码迷,mamicode.com
首页 > 编程语言 > 详细

Halcon选择一堆region中面积第N大的region的算法实现

时间:2017-02-20 00:03:47      阅读:724      评论:0      收藏:0      [点我收藏+]

标签:[1]   abi   tuple   class   object   text   strong   http   它的   

以下图为例:

技术分享

比如我想把面积第2小的那个“小正方形”选择出来,算法代码如下:

1 read_image (Yuan, C:/Users/happy xia/Desktop/yuan.png)
2 binary_threshold (Yuan, Region, max_separability, dark, UsedThreshold)
3 connection (Region, ConnectedRegions)
4 area_center (ConnectedRegions, Area, Row, Column)
5 tuple_sort_index (Area, Indices)
6 Num := |Indices|
7 select_obj (ConnectedRegions, ObjectSelected, Indices[1] + 1)

 

该实现算法的关键是对算子tuple_sort_index意思的理解。

 

代码中:

Area := [420, 12922, 38019, 58, 2033]

Indices := [3, 0, 4, 1, 2]

 

tuple_sort_index (Area, Indices)的意思是:先将Area中各元素按升序排序,然后将排序后的每一个Area分别在原Area元组中的索引放在元组Indices 中。

 

[3, 0, 4, 1, 2]的意思是:

58是Area 中的3号元素(元组索引从0开始)

420是Area 中的0号元素;

2033是Area 中的4号元素;

12922是Area 中的1号元素;

38019是Area 中的2号元素。

 

再看看上面tuple_sort_index算子的意思,可知Indices[1]面积第2小的元素在原Area元组中的索引,即索引是0。由于对于算子select_obj 来说,它的索引是从1开始的。所以Indices[1] + 1 是最终的索引。

 

结果图:

技术分享

 

如果要找到面积第二大的,只需将最后一句改为:

select_obj (ConnectedRegions, ObjectSelected, Indices[Num -2] + 1)

技术分享

 

Halcon选择一堆region中面积第N大的region的算法实现

标签:[1]   abi   tuple   class   object   text   strong   http   它的   

原文地址:http://www.cnblogs.com/xh6300/p/6417801.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!