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

示例代码

此页用简短的范例显示出 Adaptive Vision Library 的功能与风格。请参考与 Adaptive Vision Library 一起安装的范例为了理解完成检测应用程序。

图像处理

平滑化过滤器是图像处理最典型的工具之一。在此,我们显示高斯与中值 图像去噪。注意,image1 是输入,image2 是输出。

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

输入:

输出 (高斯):

输出 (中值):

区域分析

区域是一套像素位置或压缩二维图像。如下代码显示红像素区域的提出与他的处理。

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

输入:

输出:

条码识别

二维代码(DataMatrix)用两个步骤辨识:首先侦测条码位置,再在搜寻到的位置识别。

DataMatrixCodeParams codeParams;
DataMatrixDetectionParams detectionParams;
Conditional code;
Array 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 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 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 object;
if (model != NIL)
{
	LocateSingleObject_Edges(image2, NIL, model.Get(), 1, 3, 10.0f, true, 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 图像获取

Adaptive Vision Library 支持所有与 GigE Vision 及 GenICam 相合的相机与影像撷取卡。在此,我们显示用 GigE Vision 设备获取图像范例:

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

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

	// Process image
	...
}

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