QQ登录

只需一步,快速开始

halcon 几何工具函数介绍

[ 复制链接 ]
1.angle_ll( : : RowA1, ColumnA1, RowA2, ColumnA2, RowB1, ColumnB1, RowB2, ColumnB2 : Angle)
计算RowA1, ColumnA1, RowA2, ColumnA2和RowB1, ColumnB1, RowB2, ColumnB2
组成的两线段夹角,结果保存于Angle,单位弧度
例如用鼠标绘制两直线,计算两直线夹角
draw_line (200000, Row1, Column1, Row2, Column2)
draw_line (200000, Row11, Column11, Row21, Column21)
angle_ll (Row1, Column1, Row2, Column2, Row11, Column11, Row21, Column21, Angle)


2.angle_lx( : : Row1, Column1, Row2, Column2 : Angle)
计算Row1, Column1, Row2, Column2组成的直线与水平轴线夹角
结果保存于Angle,角度弧度,范围-180《=Angle<=180
例如
draw_line (200000, Row11, Column11, Row21, Column21)
angle_lx (Row11, Column11, Row21, Column21, Angle1)


3.distance_cc(Contour1, Contour2 : : Mode : DistanceMin, DistanceMax)
distance_cc计算两个轮廓(Contour1和Contour2)的基点之间的最小和最大距离。
参数DistanceMin和DistanceMax包含产生的距离。
参数Mode 设置计算距离的类型:
'point_to_point'只确定轮廓基准点之间的最小和最大距离。这导致更快的算法,但可能导致不准确的最小距离。
相比之下,“point_to_segment”确定了轮廓线段之间的实际最小距离。
在这两种情况下,搜索算法都具有二次复指数(n*n)。
如果只需要最小距离,则可以选择使用操作符distance_cc_min,
因为它提供了“n*log(n)”的算法。
两种模式的例程:
gen_contour_polygon_rounded_xld(Cont1, [0,100,100,0,0], [0,0,100,100,0],[50,50,50,50,50], 0.5)
gen_contour_polygon_rounded_xld(Cont2, [41,91,91,41,41], [41,41,91,91,41], [25,25,25,25,25], 0.5)
distance_cc(Cont1, Cont2, 'point_to_point', distance_min, distance_max)
distance_cc(Cont1, Cont2, 'point_to_segment', distance_min, distance_max)

4.distance_cc_min(Contour1, Contour2 : : Mode : DistanceMin)
distance_cc_min计算两个轮廓线Contour1和Contour2之间的最小距离。
最小距离以DistanceMin返回。
参数Mode 设置计算距离的类型。
“point_to_point”确定最近的轮廓线点之间的距离,
“fast_point_to_segment”计算这些点附近的线段之间的距离,
“point_to_segment”确定轮廓线段之间的实际最小距离。
虽然'point_to_point'和'fast_point_to_segment'是复杂度为n*log(n)的高效算法,
但'point_to_segment'具有二次复杂度,因此执行时间较长,特别是对于包含许多线段的轮廓。
例程:
gen_contour_polygon_rounded_xld(Cont1, [0,100,100,0,0], [0,0,100,100,0],[50,50,50,50,50], 0.5)
gen_contour_polygon_rounded_xld(Cont2, [41,91,91,41,41], [41,41,91,91,41], [25,25,25,25,25], 0.5)
distance_cc_min (Cont1, Cont2, 'fast_point_to_segment', DistanceMin)
distance_cc_min (Cont1, Cont2, 'point_to_point', DistanceMin1)
distance_cc_min (Cont1, Cont2, 'point_to_segment', DistanceMin2)

5.distance_cc_min_points(Contour1, Contour2 : : Mode : DistanceMin, Row1, Column1, Row2, Column2)
distance_cc_min_points计算Contour1和Contour2之间的最小距离。
最小距离以DistanceMin返回。
与distance_cc_min相比,该操作符还返回轮廓上提供最小距离的点。
Contour1上的点在Row1和Column1中返回;
Contour2上的点在Row2和Column2中返回。


参数Mode 设置计算距离的类型。
“fast_point_to_segment”计算与最近轮廓点相邻的线段之间的距离,
“point_to_segment”确定轮廓线段之间的实际最小距离。



虽然“fast_point_to_segment”是一个复杂度为n*log(n)的高效算法,
但“point_to_segment”具有二次复杂度,因此执行时间较长,尤其是对于包含许多线段的轮廓。
例程:
gen_contour_polygon_rounded_xld(Cont1, [0,100,100,0,0], [0,0,100,100,0],[50,50,50,50,50], 0.5)
gen_contour_polygon_rounded_xld(Cont2, [41,91,91,41,41], [41,41,91,91,41], [25,25,25,25,25], 0.5)
distance_cc_min_points (Cont1, Cont2, 'fast_point_to_segment', DistanceMin, Row1, Column1, Row2, Column1)
distance_cc_min_points (Cont1, Cont2, 'point_to_segment', DistanceMin, Row1, Column1, Row2, Column2)

6.distance_contours_xld(ContourFrom, ContourTo : ContourOut : Mode : )
操作符distance_contours_xld计算ContourFrom中每个点到ContourTo的最小距离。结果轮廓保存于ContourOut 。
结果轮廓线包含属性“distance”。
可以通过使用操作符get_contour_attrib_xld查询属性'distance'来访问距离。

参数Mode决定计算ContourFrom中每个点的距离:
'point_to_point'计算到ContourTo基点的最小距离。
相反,'point_to_segment'计算到ContourTo中轮廓段的最小距离(见下图)。
2019-05-28_220317.jpg
虚线表示从左边的轮廓点开始计算的距离。
距离d1对应于'point_to_point'模式,
而距离d2对应于'point_to_segment'模式。


请注意,在许多应用程序中,
模式'point_to_segment'会建议自己就近获得准确的结果,
而'point_to_point'则要快得多。
如果m是ContourFrom中的点的个数,
n是ContourTo中的点的个数,
那么distance_contours_xld的复杂度为O(mlog(n)),对应“point_to_point”。
O(mn)对应“point_to_segment”。


如果重复使用模板轮廓ContourTo,
可以使用create_distance_transform_xld
和apply_distance_transform_xld操作符
作为distance_contours_xld的替代。
有关详细信息,请参阅 create_distance_transform_xld.的文档
例程:
gen_contour_polygon_rounded_xld(Cont1, [0,100,100,0,0], [0,0,100,100,0],[50,50,50,50,50], 0.5)
gen_contour_polygon_rounded_xld(Cont2, [41,91,91,41,41], [41,41,91,91,41], [25,25,25,25,25], 0.5)
distance_contours_xld (Cont1, Cont2, ContourOut, 'point_to_point')
distance_contours_xld (Cont1, Cont2, ContourOut1, 'point_to_segment')
get_contour_attrib_xld (ContourOut, 'distance', Attrib)



7.distance_lc(Contour : : Row1, Column1, Row2, Column2 : DistanceMin, DistanceMax)
distance_lc计算一条直线与一条轮廓线段之间的正交距离。
直线由两点(Row1、Column1、Row2、Column2)确定,
轮廓由contour)指定。
参数DistanceMin和DistanceMax返回计算结果。
例程:
gen_contour_polygon_rounded_xld(Cont1, [0,100,100,0,0], [0,0,100,100,0],[50,50,50,50,50], 0.5)
gen_contour_polygon_rounded_xld(Cont2, [41,91,91,41,41], [41,41,91,91,41], [25,25,25,25,25], 0.5)
draw_line (200000, Row1, Column1, Row2, Column2)
distance_lc (Cont1, Row1, Column1, Row2, Column2, DistanceMin, DistanceMax)

8.distance_lr(Region : : Row1, Column1, Row2, Column2 : DistanceMin, DistanceMax)
distance_lr计算直线与一个区域之间的正交距离。
直线由两个点确定(Row1、Column1、Row2、Column2),
区域由Region 指定。
参数DistanceMin和DistanceMax返回计算结果。



例程:
gen_contour_polygon_rounded_xld(Cont1, [0,100,100,0,0], [0,0,100,100,0],[50,50,50,50,50], 0.5)
gen_contour_polygon_rounded_xld(Cont2, [41,91,91,41,41], [41,41,91,91,41], [25,25,25,25,25], 0.5)
gen_circle (Circle, 200, 200, 100.5)
Row1:=23
Column1:=53
Row2:=14
Column2:=24
distance_lr (Circle, Row1, Column1, Row2, Column2, DistanceMin, DistanceMax)

9.distance_pc(Contour : : Row, Column : DistanceMin, DistanceMax)
distance_pc计算一个或多个点到单个轮廓的距离。
输入点为Row, Column和轮廓为Contour 。
参数DistanceMin和DistanceMax返回计算结果。
注意,结果对应的是点与轮廓线段之间的距离,
而不是点与轮廓基准点之间的距离(参见distance_contours_xld)
例程:
gen_contour_polygon_rounded_xld(Cont1, [0,100,100,0,0], [0,0,100,100,0],[50,50,50,50,50], 0.5)
gen_contour_polygon_rounded_xld(Cont2, [41,91,91,41,41], [41,41,91,91,41], [25,25,25,25,25], 0.5)
gen_circle (Circle, 200, 200, 100.5)
Row1:=23
Column1:=53
Row2:=14
Column2:=24
distance_pc (Cont2, Row2, Column2, DistanceMin, DistanceMax)

10.distance_pl( : : Row, Column, Row1, Column1, Row2, Column2 : Distance)
计算点(Row, Column),和线段( Row1, Column1, Row2, Column2)的距离,
结果保存于Distance
例程
RowC:=200
ColC:=200
gen_circle (Circle, RowC, ColC, 100)
Row1:=23
Column1:=53
Row2:=14
Column2:=24
distance_pl (RowC, ColC, Row1, Column1, Row2, Column2, Distance)


11.distance_pp( : : Row1, Column1, Row2, Column2 : Distance)
计算点1(Row1, Column1和点2( Row2, Column2)的距离。
x = (Row1-Row2)*(Row1-Row2)+ (Column1-Column2)*Column1-Column2)
Distance = x开平方。
例程
Row1:=23
Column1:=53
Row2:=14
Column2:=24
distance_pp (Row1, Column1, Row2, Column2, Distance)

12.distance_pr(Region : : Row, Column : DistanceMin, DistanceMax)
distance_pr计算一个点到一个区域的距离。
输入点为 Row, Column)和一个区域为Region 。
如果一个点在区域内,它的最小距离为零。
参数DistanceMin和DistanceMax返回计算结果。
例程
RowC:=200
ColC:=200
gen_circle (Circle, RowC, ColC, 100)
Row1:=23
Column1:=53
Row2:=14
Column2:=24
distance_pr (Circle, RowC, ColC, DistanceMin, DistanceMax)
distance_pr (Circle, Row1, Column1, DistanceMin, DistanceMax)


13.distance_ps( : : Row, Column, Row1, Column1, Row2, Column2 : DistanceMin, DistanceMax)
distance_ps计算点(Row, Column)与线段之间的最小和最大距离,
线段由起始点(Row1, Column1)和终点( Row2, Column2表示。
DistanceMax是线段端点到点的最大距离。
如果该点位于两个端点之间,则DistanceMin与distance_pl相同。
否则,使用到其中一个端点的最小距离。
例程:
RowC:=200
ColC:=200
gen_circle (Circle, RowC, ColC, 100)
Row1:=23
Column1:=53
Row2:=14
Column2:=24
distance_ps (RowC, ColC, Row1, Column1, Row2, Column2, DistanceMin, DistanceMax)

14.distance_rr_min(Regions1, Regions2 : : : MinDistance, Row1, Column1, Row2, Column2)
distance_rr_min计算区域对的最小距离。
如果在Regions1和Regions2中传递多个区域,则Regions1, Regions2内区域一一对应进行轮廓像素之间距离计算,
然后在输出参数MinDistance中保存对应距离。
使用欧几里得距离。
参数(Row1, column n1)和(Row2, Column2)
分别表示距离最小的Regions1和Regions2在轮廓线上的位置。


通过对所有轮廓像素的比较进行计算(见get_region_contour)。
这特别意味着忽略区域中的洞。
此外,它不检查一个区域是否完全位于另一个区域内。
在这情况下,返回最小距离> 0。
它也不检查两个区域是否包含非空的交集。
在后一种情况下,根据区域的轮廓是否包含公共点,
可以返回最小距离0或> 0。
下面例程按F5执行,可以看到绿色投影点:
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
Row1 := 300
Column1 := 200
Row2 := 140
Column2 := 400
Rows := 300
Columns := 170
dev_set_color ('cadet blue')
gen_contour_polygon_xld (Contour, [Row1,Row2], [Column1,Column2])
Offset := 0
for Rows := 40 to 280 by 40
  dev_set_color ('red')
  gen_cross_contour_xld (Point,Rows+Offset, Columns, 6, 0)
  projection_pl (Rows+Offset, Columns, Row1, Column1, Row2, Column2, RowProj, ColProj)
  dev_set_color ('blue')
  gen_cross_contour_xld (RowP, RowProj, ColProj, 6, 0)
  dev_clear_window ()
  dev_set_color ('green')
  dev_display (Point)
  dev_set_color ('red')
  dev_display (RowP)
  dev_set_color ('blue')
  dev_display (Contour)
  dev_disp_text ('Project', 'window',RowProj+10, ColProj+10, 'black', [], [])
  Offset := Offset+30
  stop()
endfor



  

halcon从自学到接项目视频教程,另外再赠送全网最全资源  

  

欢迎围观我录制的一套halcon自学视频教程(进入)



















回复

使用道具 举报

快速回复 返回列表 客服中心 搜索