-
背景介绍
使用Halcon时经常会遇到一个问题,即选择一个属于其它轮廓子集的小轮廓,如下图中右下角所示的红色轮廓。本文记录一下该问题的解决方法。
图例:
生成的轮廓
代码:
*生成五个闭合轮廓,其中一个轮廓包含一个小轮廓
gen_rectangle1 (ROI_0, 284.418, 282.922, 319.063, 315.445)
dev_clear_window ()
gen_contour_polygon_xld (Contours, [50,50,150,150,50], [50,150,150,50,50])
gen_contour_polygon_xld (Contour3, [250,250,350,350,250], [50,150,150,50,50])
concat_obj (Contours, Contour3, Contours)
gen_contour_polygon_xld (Contour4, [50,50,150,150,50], [250,350,350,250,250])
concat_obj (Contours, Contour4, Contours)
gen_contour_polygon_xld (Contour5, [250,250,350,350,250], [250,350,350,250,250])
concat_obj (Contours, Contour5, Contours)
gen_contour_region_xld (ROI_0, Contours1, 'border')
concat_obj (Contours, Contours1, Contours)
stop ()
*循环判断
area_center_xld (Contours, Area, Row1, Column, PointOrder)
for Index := 0 to |Row1|-1 by 1
test_xld_point (Contours, Row1[Index], Column[Index], IsInsideContours)
if(sum(IsInsideContours) = 2)
a:=Index+1
break
endif
endfor
select_shape_xld (Contours, SelectedXLD, 'area', 'and', Area[a], Area[a])
*结果显示
dev_clear_window ()
dev_display (SelectedXLD)