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 中文(繁體) 中文(简体)

示例代碼

此頁用簡短的範例顯示出 Zebra Aurora™ Vision Library 的功能與風格。請參考與 Zebra Aurora™ Vision Library 一起安裝的範例為了理解完成檢測應用程序。

圖像處理

平滑化過濾器是圖像處理最典型的工具之一。在此,我們顯示高斯與中值 圖像去噪。注意,image1 是輸入,image2 是輸出。

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

輸入:

輸出 (高斯):

輸出 (中值):

區域分析

區域是一套像素位置或壓縮二維圖像。如下代碼顯示紅像素區域的提出與他的處理。

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);

輸入:

輸出:

條碼識別

二維代碼(DataMatrix)用兩個步驟辨識:首先偵測條碼位置,再在搜尋到的位置識別。

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);
}

輸入:

輸出:

形狀擬合

形狀擬合從大約的範圍找起,位於形狀精確的位置。此範例顯示線段擬合的兩個步驟:創造擬合圖與執行擬合。

// 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);
}

輸入:

輸出:

診斷輸出:

基於灰度模板匹配

模板匹配技術在圖像尋找匹配圖像,獲取它的位置與旋轉 。典型的例子是在電子路線尋找記號:

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);
	}
}

模板:

輸入:

輸出:

GigE Vision 圖像獲取

Zebra Aurora™ Vision Library 支持所有與 GigE Vision 及 GenICam 相合的相機與影像擷取卡。在此,我們顯示用 GigE Vision 設備獲取圖像範例:

// 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);