Skip to main content

Send Unit

This guide shows how to build a Unit with three Capture objects — each loaded from a real image file — and send it to a Display in a single call.

Download project


Overview

The script loads three cookie inspection images from disk, wraps each one in a Capture with a text label, groups them into a Unit, and sends the unit to the display. The user can then navigate between captures directly in the display UI.

Load images

var image1 = Ve.loadImage("C:/cookies_image_1.jpg");
var image2 = Ve.loadImage("C:/cookies_image_2.jpg");
var image3 = Ve.loadImage("C:/cookies_image_3.jpg");

Images are loaded from disk using Ve.loadImage(). The pixel format and dimensions are inferred automatically from the file.

Capture 1 — 12 cookies

var veList1: Ve.VisionElement[] = [];
var label1 = new Ve.String("Capture 1 — 12 cookies");
label1.color = "#ffffff";
label1.fontSize = 60;
label1.setAnchor(new Ve.Point2d(30, 30));
veList1.push(label1 as Ve.VisionElement);

var capture1 = new Capture(image1, "capture-1");
capture1.addVisionElement(veList1);

Capture 2 — 7 cookies

var veList2: Ve.VisionElement[] = [];
var label2 = new Ve.String("Capture 2 — 7 cookies");
label2.color = "#ffffff";
label2.fontSize = 60;
label2.setAnchor(new Ve.Point2d(30, 30));
veList2.push(label2 as Ve.VisionElement);

var capture2 = new Capture(image2, "capture-2");
capture2.addVisionElement(veList2);

Capture 3 — 4 cookies

var veList3: Ve.VisionElement[] = [];
var label3 = new Ve.String("Capture 3 — 4 cookies");
label3.color = "#ffffff";
label3.fontSize = 60;
label3.setAnchor(new Ve.Point2d(30, 30));
veList3.push(label3 as Ve.VisionElement);

var capture3 = new Capture(image3, "capture-3");
capture3.addVisionElement(veList3);

Build and send the unit

var unit = new Unit();
unit.addCapture(capture1);
unit.addCapture(capture2);
unit.addCapture(capture3);

Visu.page0.display1.sendUnit(unit);
Visu.update();

A Unit groups related captures together. Once sent, the display shows the first capture and the user can browse the others using the capture navigation in the UI.

info

For a full explanation of what a Unit is and how it appears in the image display, see Units.

tip

Visu.update() must be called after sendUnit() to flush the update to the visualization layer.

Full script

//
// Load images
//

var image1 = Ve.loadImage("C:/cookies_image_1.jpg");
var image2 = Ve.loadImage("C:/cookies_image_2.jpg");
var image3 = Ve.loadImage("C:/cookies_image_3.jpg");

var FONT_SIZE = 60;

//
// Capture 1 — 12 cookies
//

var veList1: Ve.VisionElement[] = [];
var label1 = new Ve.String("Capture 1 — 12 cookies");
label1.color = "#ffffff";
label1.fontSize = FONT_SIZE;
label1.setAnchor(new Ve.Point2d(30, 30));
veList1.push(label1 as Ve.VisionElement);

var capture1 = new Capture(image1, "capture-1");
capture1.addVisionElement(veList1);

//
// Capture 2 — 7 cookies
//

var veList2: Ve.VisionElement[] = [];
var label2 = new Ve.String("Capture 2 — 7 cookies");
label2.color = "#ffffff";
label2.fontSize = FONT_SIZE;
label2.setAnchor(new Ve.Point2d(30, 30));
veList2.push(label2 as Ve.VisionElement);

var capture2 = new Capture(image2, "capture-2");
capture2.addVisionElement(veList2);

//
// Capture 3 — 4 cookies
//

var veList3: Ve.VisionElement[] = [];
var label3 = new Ve.String("Capture 3 — 4 cookies");
label3.color = "#ffffff";
label3.fontSize = FONT_SIZE;
label3.setAnchor(new Ve.Point2d(30, 30));
veList3.push(label3 as Ve.VisionElement);

var capture3 = new Capture(image3, "capture-3");
capture3.addVisionElement(veList3);

//
// Unit
//

var unit = new Unit();
unit.addCapture(capture1);
unit.addCapture(capture2);
unit.addCapture(capture3);

//
// Send
//

Visu.page0.display1.sendUnit(unit);
Visu.update();