This page uses cookies. For details and possible settings refer to our Privacy Policy.
Continuing to use this page means accepting the processing of cookie files.

Accept (hide info)
POL ENG GER 中文(繁體) 中文(简体)

Code Samples

This page demonstrates the capabilities and the style of Zebra Aurora™ Vision Library with very short code snippets. Please, refer to the official examples installed with the product to see some complete inspections and sample applications.

Image Processing

One of the most typical image processing tools are smoothing filters. Here, we demonstrate gaussian and median image denoising. Note that image1 is the input, and image2 is the output.

SmoothImage_Gauss( image1, NIL, 2.0f, 2.0f, 2.5f, image2 );
SmoothImage_Median( image1, NIL, NIL, SmoothImageMedianKernel::Box, 3, NIL, image2 );

Input:

Output (Gauss):

Output (Median):

Region Analysis

A region is a set of pixel locations, or a compressed binary image. The below code demonstrates extraction of a region of red pixels and its postprocessing.

Region region1, region2, region3, region4;
ThresholdToRegion_HSx(image1, NIL, HSxColorModel::HSV, 0, 10, 190, 255, 65, 255, region1);
CloseRegion(region1, KernelShape::Ellipse, 15, 15, region2);
FillRegionHoles(region2, RegionConnectivity::EightDirections, NIL, 10000, region3);
DrawRegion(image1, region3, NIL, Pixel(0, 255, 0), 1.0);
OpenRegion(region3, KernelShape::Ellipse, 15, 15, region4);
DrawRegion(image1, region4, NIL, Pixel(255, 0, 0), 1.0);

Input:

Output:

Code Reading

DataMatrix codes are read in two steps: first candidates are detected and then the codes are recognized at the found locations.

DataMatrixCodeParams codeParams;
DataMatrixDetectionParams detectionParams;
Conditional<DataCode> code;
Array<Path> candidates;

ReadSingleDataMatrixCode(image1, NIL, NIL, codeParams, detectionParams, code, candidates);

if (code != NIL)
{
	DrawingStyle style(DrawingMode::HighQuality, 1.0f, 3.0f, false, NIL, 2.0);
	DrawPath(image1, code.Get().Outline(), NIL, Pixel(255, 0, 0), style);
	DrawString(image1, code.Get().Text(), Location(10, 10), NIL, Anchor2D::TopLeft, Pixel(255, 0, 0), style, 18.0f, 0.0f, NIL);
}

Input:

Output:

Shape Fitting

Shape Fitting allows to precisely locate shapes which rough locations are known beforehand. Here, we demonstrate segment fitting with two steps: creating a fitting map and then performing the fitting itself.

// Create shape fitting map
SegmentFittingField field(Segment2D(40.0f, 30.0f, 40.0f, 130.0f), 30.0f);
SegmentFittingMap map;
ImageFormat imageFormat(image1.Width(), image1.Height(), PlainType::UInt8, 3);

CreateSegmentFittingMap(imageFormat, field, NIL, 12, 5, InterpolationMethod::Bilinear, map);

// Fit the shape
EdgeScanParams params;
params.minMagnitude = 10.0f;
params.edgeTransition = EdgeTransition::BrightToDark;
Conditional<Segment2D> segment;
FitSegmentToEdges(image1, map, params, Selection::Best, NIL, 0.1f, NIL, segment);
if (segment != NIL)
{
	DrawingStyle style(DrawingMode::HighQuality, 1.0f, 2.0f, false, NIL, 0.0f);
	DrawSegment(image1, segment.Get(), NIL, Pixel(255, 0, 0), style, MarkerType::None, 0.0f);
}

Input:

Output:

Diagnostics:

Edge-based Template Matching

Template Matching techniques make it possible to locate objects at arbitrary locations and rotations. An example of a typical application is detection of fiducial markers on an electronic circuit:

Image image1;
LoadImage("fiducial_template.png", false, image1);

Conditional<EdgeModel> model;
CreateEdgeModel(image1, NIL, NIL, 0, NIL, 0.0f, 35.0f, 15.0f, -45.0f, +45.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, model);

Image image2;
LoadImage("fiducial_input.png", false, image2);

Conditional<Object2D> object;
if (model != NIL)
{
	LocateSingleObject_Edges(image2, NIL, model.Get(), 1, 3, 10.0f, EdgePolarityMode::MatchStrictly, 
	                                                            EdgeNoiseLevel::High, false, 0.7f, object);

	if (object != NIL)
	{
		DrawingStyle style(DrawingMode::HighQuality, 1.0f, 3.0f, false, NIL, 2.0);
		DrawRectangle(image2, object.Get().Match(), NIL, Pixel(255, 0, 0), style);
	}
}

Template:

Input:

Output:

GigE Vision Image Acquisition

Zebra Aurora™ Vision Library supports image acquisition from all GigE Vision and GenICam compatible cameras and frame grabbers. Here, we demonstrate the scheme of image acquisition from a GigE Vision device:

// Initialize acquisition
GigEHandle hDev = GigEVision_OpenDevice("169.254.1.81");
GigEVision_StartAcquisition(hDev, "Mono8");

Image image1;
while (true)
{
	// Grab image
	GigEVision_ReceiveImage(hDev, image1);

	// Process image
	ProcessImage(image1);
}

// Finalize acquisition
avl::GigEVision_StopAcquisition(hDev);
avl::GigEVision_CloseHandle(hDev);