Halcon寻找被包含在其它轮廓中的小轮廓

  • 背景介绍

使用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)

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

进击的路飞桑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值