文章详细介绍了Halcon库中用于计算两点之间距离、点到直线、点到区域、线到区域、线到线以及轮廓区域间距离的算子,通过实例展示了如何在图像处理中使用这些算子进行距离测量。
文章目录
算子
distance_pp 两点之间的距离算子
distance_pp( : : Row1, Column1, Row2, Column2 : Distance)
Row1 点1的行坐标
Column1 点1的列坐标
Row2 点2的行坐标
Column2 点2的列坐标
Distance 输出的两点之间的距离
distance_pl 计算点到直线的距离
distance_pl( : : Row, Column, Row1, Column1, Row2, Column2 : Distance)
Row (input_control):点的行坐标。
Column (input_control):点的列坐标。
Row1 (input_control):直线上第一个点的行坐标。
Column1 (input_control):直线上第一个点的列坐标。
Row2 (input_control):直线上第二个点的行坐标。
Column2 (input_control):直线上第二个点的列坐标。
Distance (output_control):点到直线的距禇。
distance_pr 点到区域的距离
distance_pr(Region : : Row, Column : DistanceMin, DistanceMax)
Region (input_object):输入的区域对象。
Row (input_control):点的行坐标。
Column (input_control):点的列坐标。
DistanceMin (output_control):点到区域的最短距离。
DistanceMax (output_control):点到区域的最长距离。
distence_Ir 线到区域的距离
distance_lr(Region : : Row1, Column1, Row2, Column2 : DistanceMin, DistanceMax)
Region (input_object):输入的区域对象。
Row1 (input_control):直线上第一个点的行坐标。
Column1 (input_control):直线上第一个点的列坐标。
Row2 (input_control):直线上第二个点的行坐标。
Column2 (input_control):直线上第二个点的列坐标。
DistanceMin (output_control):直线到区域的最短距离。
DistanceMax (output_control):直线到区域的最长距离。
distance_rr_min 轮廓区域的距离
distance_rr_min(Regions1, Regions2 : : : MinDistance, Row1, Column1, Row2, Column2)
Regions1 (input_object):待检查的区域轮廓。
Regions2 (input_object):待检查的区域轮廓。
MinDistance (output_control):轮廓之间的最短距离。
Assertion: 0 <= MinDistance (断言:最短距离大于等于0)
Row1 (output_control):Regions1 中轮廓上的行索引。
Column1 (output_control):Regions1 中轮廓上的列索引。
Row2 (output_control):Regions2 中轮廓上的行索引。
Column2 (output_control):Regions2 中轮廓上的列索引。
Halcon 计算两点之间的距离案例
* Calculate the distance between two points
*
dev_close_window ()
read_image (Image, 'mreut')
dev_open_window (0, 0, 512, 512, 'white', WindowID)
dev_display (Image)
dev_set_color ('black')
* 阈值处理,获取区域
threshold (Image, Region, 180, 255)
* dev_clear_window ()
dev_display (Region)
* 连通域联合
connection (Region, ConnectedRegions)
* 选择区域
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10000, 100000000)
* 获取区域的的轮廓
get_region_contour (SelectedRegions, Rows, Columns)
RowPoint := 80
ColPoint := 250
NumberTuple := |Rows|
dev_set_color ('red')
dev_set_draw ('margin')
* Display a circle that represented one point
* 产生一个圆点
gen_circle (Circle, RowPoint, ColPoint, 10)
dev_display (Circle)
dev_set_color ('green')
* Calculate the distance between points of the contour
* of the selected region and the displayed point
for I := 1 to NumberTuple by 10
* 绘制十字
gen_cross_contour_xld (Cross, Rows[I], Columns[I], 6, 0.785398)
* 产生直线
gen_contour_polygon_xld (Contour, [Rows[I],RowPoint], [Columns[I],ColPoint])
dev_set_color ('green')
dev_display (Cross)
dev_set_color ('white')
dev_display (Contour)
* 测量距离
distance_pp (RowPoint, ColPoint, Rows[I], Columns[I], Distance)
wait_seconds (0.02)
endfor
Halcon 计算点到直线的距离
* Calculate the distance between any points and one line
*
dev_close_window ()
read_image (Image, 'mreut')
dev_open_window (0, 0, 512, 512, 'white', WindowID)
dev_display (Image)
dev_set_color ('black')
threshold (Image, Region, 180, 255)
dev_clear_window ()
dev_display (Region)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10000, 100000000)
get_region_contour (SelectedRegions, Rows, Columns)
RowLine1 := 5
ColLine1 := 300
RowLine2 := 300
ColLine2 := 400
NumberTuple := |Rows|
dev_set_color ('red')
disp_line (WindowID, RowLine1, ColLine1, RowLine2, ColLine2)
dev_set_color ('green')
* Calculate the distance between points of the contour
* of the selected region and the displayed line
for i := 1 to NumberTuple by 20
disp_line (WindowID, Rows[i], Columns[i] - 2, Rows[i], Columns[i] + 2)
disp_line (WindowID, Rows[i] - 2, Columns[i], Rows[i] + 2, Columns[i])
distance_pl (Rows[i], Columns[i], RowLine1, ColLine1, RowLine2, ColLine2, Distance)
endfor
Halcon 计算点到区域的距离
* Calculate the distance between one point and one region
*
dev_close_window ()
read_image (Image, 'mreut')
dev_open_window (0, 0, 512, 512, 'white', WindowID)
dev_set_color ('black')
threshold (Image, Region, 180, 255)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10000, 100000000)
RowB1 := 255
ColumnB1 := 255
dev_clear_window ()
dev_display (SelectedRegions)
dev_set_color ('red')
* Calculate the distance between any points and a region
for i := 1 to 360 by 1
RowB2 := 255 + sin(rad(i)) * 200
ColumnB2 := 255 + cos(rad(i)) * 200
disp_line (WindowID, RowB1, ColumnB1, RowB2, ColumnB2)
distance_pr (SelectedRegions, RowB2, ColumnB2, DistanceMin, DistanceMax)
endfor
Halcon 线到区域的距离
* Calculate the distance between one line and one region
*
dev_close_window ()
read_image (Image, 'fabrik')
dev_open_window (0, 0, 512, 512, 'white', WindowID)
threshold (Image, Region, 180, 255)
connection (Region, ConnectedRegions)
* Select a region from image
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 5000, 100000000)
dev_clear_window ()
dev_set_color ('black')
dev_display (SelectedRegions)
Row1 := 100
Row2 := 400
for Col := 50 to 400 by 4
distance_lr (SelectedRegions, Row1, Col + 100, Row2, Col, DistanceMin, DistanceMax)
*在线上
if (DistanceMin <= 0)
dev_set_color ('green')
else
*不在线上
dev_set_color ('red')
endif
disp_line (WindowID, Row1, Col + 100, Row2, Col)
endfor
Halcon 线到线的距离
* Calculate the distances between line segments
*
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'white', WindowID)
dev_set_color ('black')
RowLine1 := 400
ColLine1 := 200
RowLine2 := 240
ColLine2 := 400
Rows := 300
Columns := 50
disp_line (WindowID, RowLine1, ColLine1, RowLine2, ColLine2)
dev_set_color ('red')
n := 0
* Calculate the distance between the line segments
* and the displayed single line
for Rows := 40 to 200 by 4
distance_ss (Rows, Columns, Rows + n, Columns + n, RowLine1, ColLine1, RowLine2, ColLine2, DistanceMin, DistanceMax)
if (DistanceMin == 0)
dev_set_color ('green')
else
dev_set_color ('red')
endif
disp_line (WindowID, Rows, Columns, Rows + n, Columns + n)
n := n + 8
endfor
转载
原文 Halcon 几何测量_halcon测距-CSDN博客
END