measure_pos 提取垂直于矩形(或环形弧)的直线边缘。
该算法通过计算垂直于矩形或环形弧的长轴的“切片”中的灰度值的均值以获得一维边缘轮廓(参考:measure_pos [HALCON Operator Reference / Version 12.0.2] (mvtec.com)),包括直线型边缘和弧形边缘,此处仅对直线型进行介绍。
可在halcon hdevelop中输入measure_pos算子,然后点击F1直接进入算子的官方文档。官方文档最下方有算子的相关例程,建议可看例程学习。
measure_pos(Image : : MeasureHandle, Sigma, Threshold, Transition, Select : RowEdge, ColumnEdge, Amplitude, Distance)
Image (input_object) 单通道图像
【输入】输入图像
MeasureHandle (input_control) measure → (handle)
【输入】Measure object handle.可用默认值
Sigma (input_control) number → (real)
【输入】Sigma of gaussian smoothing.可用默认值
应该是一个高斯滤波,一般采用默认值“1”,若有懂的大佬还请指导一下
Threshold (input_control) number → (real)
【输入】Minimum edge amplitude.
这个值比较重要,关系到能不能找到边缘。(measure助手得到待测的相应最小边缘幅度):“助手”-“打开新的measure”-绘制线段-选择“边缘”,其中的最小边缘幅度
Transition (input_control) string → (string)
【输入】Light/dark or dark/light edge.可用默认值
Select (input_control) string → (string)
按需要输出几个点,可用默认值。很多效果图效果很好输出一个值就能实现
RowEdge (output_control) point.y-array → (real)
【输出】Row coordinate of the center of the edge.
ColumnEdge (output_control) point.x-array → (real)
【输出】Column coordinate of the center of the edge.
Amplitude (output_control) real-array → (real)
【输出】Edge amplitude of the edge (with sign).
Distance (output_control) real-array → (real)
【输出】Distance between consecutive edges.
一般而言需要的值是RowEdge 和ColumnEdge,即待测边缘的一个点坐标。
输入有5个,其中Sigma 、Transition 和Select 采用默认值一般影响不大(但也都是调试要点,实际现场还是需要具体情况具体分析),Threshold可自行获取(通过“measure助手”),MeasureHandle 则是通过gen_measure_rectangle2算子生成而来。
gen_measure_rectangle2
gen_measure_rectangle2( : : Row, Column, Phi, Length1, Length2, Width, Height, Interpolation : MeasureHandle)
Row (input_control) rectangle2.center.y → (real / integer)
【输入,测量矩形中点】
Column (input_control) rectangle2.center.x → (real / integer)
【输入,测量矩形中点】
Phi (input_control) rectangle2.angle.rad → (real / integer)
【输入,测量矩形角度】要垂直边缘
Length1 (input_control) rectangle2.hwidth → (real / integer)
【输入,测量矩形宽】长轴,(垂直边缘即矩形长轴垂直边缘)
Length2 (input_control) rectangle2.hheight → (real / integer)
【输入,测量矩形高】短轴
Width (input_control) extent.x → (integer)
【输入,待测图宽】
Height (input_control) extent.y → (integer)
【输入,待测图高】
Interpolation (input_control) string → (string)
【输入,选择插值方式】(‘bicubic’, ‘bilinear’, ‘nearest_neighbor’)
MeasureHandle (output_control) measure → (handle)
【输出】Measure object handle.
Row和Column 是测量的初始点,需要自行获取进行输入,Phi 表示长轴的角度,要垂直待测边缘。(可draw_point手动在待测边缘画上两点,然后angle_lx得到待测边缘的一个粗略角度a,然后a + rad(90)作为测量边缘的角度Phi。)
边缘是一根线,所以需要很多点组成,所以叫扫描测量
for i:= 0 to 15 by 1
row := Row - cos(a + rad(90)) * measureRectWidth * i
col := Column + sin(a + rad(90)) * measureRectWidth * i
gen_measure_rectangle2 (row, col, a + rad(90), measureRectHeight, measureRectWidth, Width, Height, 'nearest_neighbor', MeasureHandle)
measure_pos (Image, MeasureHandle, 1, 12, 'all', 'all', RowEdge, ColumnEdge, Amplitude, Distance)
endfor
Row和Column为初始坐标,row与col为扫描矩形的逐次更新坐标,measureRectWidth 和measureRectHeight是矩形宽高,自行定义合适的数。