halcon筛选/挑出——最长/最短的边/轮廓

gen_polygons_xld (Intersection, Polygons, 'ramer', 2)
split_contours_xld (Polygons, ContoursSplit, 'polygon', 1, 5)
* Select the segments that have approximately the expected orientation
select_shape_xld (ContoursSplit, SelectedXLD, ['orientation_points','orientation_points'], 'or', rad([OrientationRef,OrientationRef - 180]) - rad(OrientationTolerance), rad([OrientationRef,OrientationRef - 180]) + rad(OrientationTolerance))
union_adjacent_contours_xld (SelectedXLD, UnionContours, 10, 1, 'attr_keep')
* Select the three longest segments
length_xld (UnionContours, Length)
*给边排序,第0号就是最长的
SelectedId := sort_index(-Length)[0:2] + 1
select_obj (UnionContours, ObjectSelected1, SelectedId[0])
select_obj (UnionContours, ObjectSelected2, SelectedId[1])
select_obj (UnionContours, ObjectSelected3, SelectedId[2])

上面代码中,第0号就是最长的边

或者直接用下面的代码也可以,下面的方法更简单

SelectedId := sort_index(-Length) + 1
select_obj (UnionContours, ObjectSelected1, SelectedId[0])

 

算法升级,筛选最短的和最长的

*最长最短长度及其索引初始化
Max_Length :=0
Max_Index :=0
Min_Length :=9999999
Min_Index:=0
*遍历每个轮廓长度
for i:=1 to Number2 by 1
    select_obj (Polygons, SelectedPolygon, i)
    get_polygon_xld (SelectedPolygon, Rowlg, Collg, Length, Phi)
    *保留最长轮廓及绑住索引
    if(Max_Length<Length)
        Max_Length := Length
        Max_Index := i
    endif
    *保留最短轮廓及其索引
    if(Min_Length>Length)
        Min_Length :=Length
        Min_Index := i
    endif
endfor
*从众多轮廓中选择出最长,最短轮廓
select_obj (Polygons,MaxLengthContour , Max_Index)
select_obj (Polygons,MinLengthContour , Min_Index)
dev_set_color('yellow')
dev_display(MaxLengthContour)
dev_set_color('red')
dev_display(MinLengthContour)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

大胡子大叔

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

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

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

打赏作者

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

抵扣说明:

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

余额充值