工控编程吧
标题:
halcon critical_points_sub_pix函数介绍
[打印本页]
作者:
qq263946146
时间:
2019-5-30 11:55
标题:
halcon critical_points_sub_pix函数介绍
critical_points_sub_pix(Image : : Filter, Sigma, Threshold : RowMin, ColumnMin, RowMax, ColumnMax, RowSaddle, ColumnSaddle)
critical al_points_sub_pix提取临界点,
即、局部极大值、局部极小值和鞍点,
这些点具有亚像素精度。
为了做到这一点,每个点
x,y在
输入图像被近似为一个二次多项式,
然后多项式检查极值和鞍点。偏导数是建立多项式所必需的,
它可以用各种高斯导数计算,也可以用基于滤波器的刻面模型计算,取决于
Filter。
在第一种情况下,Sigma决定高斯核的大小,
而在第二种情况下,在处理输入图像之前,由Sigma决定大小的高斯对其进行平滑处理。
因此,“小面”导致更快的提取,代价是略微不准确的结果。
如果黑森矩阵的两个特征值的绝对值都大于Threshold ,则一个点被认为是临界点。
特征值对应于灰度值曲面的曲率。
如果两个特征值都是负的,这个点就是局部最大值,
如果两个特征值都是正的,这个点就是局部最小值,
如果它们有不同的符号,这个点就是鞍点。
注意,如果使用域缩小的图像作为输入,
过滤器操作符可能会返回意想不到的结果。请参考章节 Filters。
参数
Image 输入图像
Filter
偏导数的计算方法。有
'facet', 'gauss'
Sigma
高斯函数的
Sigma。如果Filter是“facet”,Sigma可能是0.0,以避免平滑输入图像。
Threshold
海森矩阵特征值的最小绝对值。
RowMin,ColumnMin,
检测到的最小值的行列坐标。
RowMax,ColumnMax
检测到的极大值的行列坐标。
RowSaddle,ColumnSaddle
检测到的鞍点的行列坐标。
例程:
Scale := .7
* 设置相机参数与相对位姿
gen_cam_par_area_scan_division (0.0128583, -533.075, 7.40044e-006, 7.4e-006, 310.243, 243.807, 640, 480, CamParamLeft)
gen_cam_par_area_scan_division (0.0130659, -512.699, 7.41508e-006, 7.4e-006, 333.347, 237.374, 640, 480, CamParamRight)
create_pose (0.154132, -0.00585068, 0.0429294, 359.932, 336.422, 359.901, 'Rp+T', 'gba', 'point', RelPose)
read_image (ImageLeft, 'stereo/targets/targets_l')
read_image (ImageRight, 'stereo/targets/targets_r')
get_image_size (ImageLeft, Width, Height)
dev_update_off ()
dev_close_window ()
dev_open_window (0, 0, Width * Scale, Height * Scale, 'black', WindowHandleLeft)
dev_set_color ('yellow')
dev_set_line_width (2)
dev_display (ImageLeft)
disp_message (WindowHandleLeft, 'Left camera', 'window', 12, 12, 'black', 'true')
*
dev_open_window (0, Width * Scale + 12, Width * Scale, Height * Scale, 'black', WindowHandleRight)
dev_set_color ('yellow')
dev_set_line_width (2)
dev_display (ImageRight)
disp_message (WindowHandleRight, 'Right camera', 'window', 12, 12, 'black', 'true')
* 检测右图上目标
critical_points_sub_pix (ImageLeft, 'facet', 2.0, 5, RowMin, ColMin, RowMax, ColMax, RowPointLeft, ColumnPointLeft)
gen_cross_contour_xld (CrossLeft, RowPointLeft, ColumnPointLeft, 20, rad(45))
dev_set_window (WindowHandleLeft)
dev_display (CrossLeft)
*检测右图上目标
critical_points_sub_pix (ImageRight, 'facet', 2.0, 5, RowMin, ColMin, RowMax, ColMax, RowPointRight, ColumnPointRight)
gen_cross_contour_xld (CrossRight, RowPointRight, ColumnPointRight, 20, rad(45))
dev_set_window (WindowHandleRight)
dev_display (CrossRight)
disp_continue_message (WindowHandleLeft, 'black', 'true')
stop ()
* 计算目标3维坐标转换为mm单位。
intersect_lines_of_sight (CamParamLeft, CamParamRight, RelPose, RowPointLeft, ColumnPointLeft, RowPointRight, ColumnPointRight, X, Y, Z, Dist)
X := X * 1000
Y := Y * 1000
Z := Z * 1000
* 计算工件高:首先定义一新的非正交坐标系,其Z=0,NX=P2P0 and NY=P2P3
NX := [X[3] - X[2],Y[3] - Y[2],Z[3] - Z[2]]
NY := [X[0] - X[2],Y[0] - Y[2],Z[0] - Z[2]]
* 通过计算NX和NX的叉乘来确定这个平面上的法向量NZ
NZ := [NX[1] * NY[2] - NX[2] * NY[1],NX[2] * NY[0] - NY[2] * NX[0],NX[0] * NY[1] - NY[0] * NX[1]]
NZ := NZ / sqrt(sum(NZ * NZ))
*通过计算向量P2P1在向量NZ上的投影得到工件的高度。这是通过计算点积P2P1.NZ来实现的
P2P1 := [X[1] - X[2],Y[1] - Y[2],Z[1] - Z[2]]
WorkpieceHeight := sum(NZ * P2P1)
*显示结果
gen_arrow_contour_xld (ArrowNXRight, RowPointRight[2], ColumnPointRight[2], RowPointRight[0], ColumnPointRight[0], 20, 20)
gen_arrow_contour_xld (ArrowNYRight, RowPointRight[2], ColumnPointRight[2], RowPointRight[3], ColumnPointRight[3], 20, 20)
gen_arrow_contour_xld (ArrowRight1, 225.5, 322.5, 225.5, 365.5, 15, 15)
gen_arrow_contour_xld (ArrowRight2, 225.5, 365.5, 225.5, 322.5, 15, 15)
dev_set_window (WindowHandleLeft)
dev_display (ImageLeft)
dev_display (CrossLeft)
disp_message (WindowHandleLeft, 'Left camera', 'window', 12, 12, 'black', 'true')
for I := 0 to 3 by 1
String := 'x = ' + X[I]$'5.1f' + ' mm'
String[1] := 'y = ' + Y[I]$'5.1f' + ' mm'
String[2] := 'z = ' + Z[I]$'5.1f' + ' mm'
disp_message (WindowHandleLeft, String, 'image', RowPointLeft[I] + 20, ColumnPointLeft[I] - 100, 'black', 'true')
disp_message (WindowHandleLeft, 'P' + I, 'image', RowPointLeft[I] - 30, ColumnPointLeft[I] - 30, 'yellow', 'false')
disp_message (WindowHandleRight, 'P' + I, 'image', RowPointRight[I] - 30, ColumnPointRight[I] - 30, 'yellow', 'false')
endfor
dev_set_window (WindowHandleRight)
dev_set_color ('blue')
dev_display (ArrowNXRight)
dev_display (ArrowNYRight)
dev_set_color ('yellow')
dev_display (CrossRight)
dev_display (ArrowRight1)
dev_display (ArrowRight2)
disp_message (WindowHandleRight, 'Height = ' + WorkpieceHeight$'2.1f' + ' mm', 'image', 213, 389, 'yellow', 'false')
[halcon]1[/halcon]
欢迎光临 工控编程吧 (https://www.gkbc8.com/)
Powered by Discuz! X3.4