Halcon执行图像中的引脚(Pin)测量任务
Halcon测量图像中引脚的宽度、间距和高度,并将这些测量结果用于进一步的分析或质量控制
以下是halcon用于执行图像中的引脚(Pin)测量任务。HALCON是一款广泛用于机器视觉领域的软件,能够进行图像分析、处理和识别。
- Pin Measurement: Example for the application of the HALCON Measure Tool
- (in this program: pure processing code without visualization)
read_image (Image, ‘ic_pin’)
get_image_size (Image, Width, Height)
Row := 47
Column := 485
Phi := 0
Length1 := 420
Length2 := 10
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
- Prepare the extraction of straight edges perpendicular to a rectangle
gen_measure_rectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, ‘nearest_neighbor’, MeasureHandle) - Extract straight edge pairs perpendicular to a rectangle
measure_pairs (Image, MeasureHandle, 1.5, 30, ‘negative’, ‘all’, RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, PinWidth, PinDistance)
avgPinWidth := sum(PinWidth) / |PinWidth|
avgPinDistance := sum(PinDistance) / |PinDistance|
numPins := |PinWidth| - Delete the measure object
close_measure (MeasureHandle)
Row := 508
Column := 200
Phi := -1.5708
Length1 := 482
Length2 := 35
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
gen_measure_rectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, ‘nearest_neighbor’, MeasureHandle)
measure_pos (Image, MeasureHandle, 1.5, 30, ‘all’, ‘all’, RowEdge, ColumnEdge, Amplitude, Distance)
PinHeight1 := RowEdge[1] - RowEdge[0]
PinHeight2 := RowEdge[3] - RowEdge[2]
close_measure (MeasureHandle)
这段代码的功能是测量图像中引脚的宽度和间距,以及引脚的高度。下面是代码的逐行解释:
read_image (Image, ‘ic_pin’):
读取名为 ‘ic_pin’ 的图像文件到变量 Image 中。
get_image_size (Image, Width, Height):
获取图像 Image 的宽度和高度,分别存储在变量 Width 和 Height 中。
Row := 47, Column := 485, Phi := , Length1 := 420, Length2 := 10:
设置用于生成矩形测量区域的参数,包括矩形中心的行坐标 Row、列坐标 Column、旋转角度 Phi(以弧度为单位),以及矩形的两个边长 Length1 和 Length2。
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2):
根据提供的参数生成一个矩形区域 Rectangle。
gen_measure_rectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, ‘nearest_neighbor’, MeasureHandle):
生成一个测量工具,用于在指定的矩形区域内提取与矩形边缘垂直的直线边缘。
measure_pairs (Image, MeasureHandle, 1.5, 30, ‘negative’, ‘all’, RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, PinWidth, PinDistance):
使用上一步生成的测量工具在图像 Image 中提取与矩形边缘垂直的直线边缘对,并计算每对边缘之间的宽度 PinWidth 和间距 PinDistance。
avgPinWidth := sum(PinWidth) / |PinWidth| 和 avgPinDistance := sum(PinDistance) / |PinDistance|:
计算引脚宽度和间距的平均值。
numPins := |PinWidth|:
计算引脚的数量。
close_measure (MeasureHandle):
关闭并释放之前生成的测量工具。
Row := 508, Column := 200, Phi := -1.5708, Length1 := 482, Length2 := 35:
设置第二个矩形测量区域的参数。
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2) 和 gen_measure_rectangle2 (…):
重复步骤4和5,为第二个矩形区域生成测量工具。
measure_pos (Image, MeasureHandle, 1.5, 30, ‘all’, ‘all’, RowEdge, ColumnEdge, Amplitude, Distance):
使用测量工具提取与第二个矩形边缘垂直的直线边缘,并计算引脚的高度 PinHeight1 和 PinHeight2。
close_measure (MeasureHandle):
关闭并释放第二个测量工具。
总的来说,这段代码的功能是测量图像中引脚的宽度、间距和高度,并将这些测量结果用于进一步的分析或质量控制。代码中没有涉及到可视化,因此所有的处理都是后台进行的,不显示图像窗口。
更多推荐
所有评论(0)