sort_contours_xld算子的几种排序方式研究

算子sort_contours_xld算子有5种排序方式,即:

 

'upper_left':

The position is determined by the upper left corner of the surrounding rectangle.

'upper_right':
The position is determined by the upper right corner of the surrounding rectangle.

'lower_left':
The position is determined by the lower left corner of the surrounding rectangle.

'lower_right':
The position is determined by the lower right corner of the surrounding rectangle.

'character':
The position is determined by the upper left corner of the surrounding rectangle. In contrast to 'upper_left', the contours are also sorted according to the remaining coordinate, if they overlap in the direction of the coordinate which is specified by the parameter RowOrCol.

 

其中'character'排序方式不太好理解,不过从英文说明可知,它跟'upper_left'排序方式很像,我想一般来说,前面的四种排序方式一般够用了。

 

'upper_left'排序方式为例,它的英文说明的翻译是:位置由环绕矩形的左上角决定。

 

于是我猜测它的意思是这样的:对于一组xld来说,画出每一个xld的最小平行矩形(gen_rectangle1),然后根据这些矩形的左上角坐标来对这些xld进行排序。

 

先看算子签名:

sort_contours_xld(Contours : SortedContours : SortMode, Order, RowOrCol : )

 

Order可以取'true'或者'false','true'是升序排列,'false'是降序排列

RowOrCol 可以取'row'或者'column'。

 

下面以如下方式排列试试:(根据最小外接矩形的左上角的行坐标来升序排列)

sort_contours_xld (SelectedXLD, SortedContours, 'upper_left', 'true', 'row')

image.png

read_image (Image, 'C:/Users/happy xia/Desktop/dynPic.png')
threshold_sub_pix (Image, Border, 90)
select_shape_xld (Border, SelectedXLD, 'contlength', 'and', 100, 99999)
sort_contours_xld (SelectedXLD, SortedContours, 'upper_left', 'true', 'row')
dev_set_draw ('margin')
dev_display (Image)
count_obj (SortedContours, Number)
gen_empty_obj (EmptyObject)
*注释:这里Number = 29
for Index := 1 to Number by 1
    select_obj (SortedContours, ObjectSelected, Index) 
    smallest_rectangle1_xld (ObjectSelected, Row1, Column1, Row2, Column2)
    gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
    concat_obj (EmptyObject, ObjectSelected, EmptyObject) 
endfor

dev_display (Image)
select_obj (SortedContours, ObjectSelected1, 11)
sort_contours_xld (SelectedXLD, SortedContours2, 'upper_left', 'false', 'row')
select_obj (SortedContours2, ObjectSelected2, Number - 11 + 1)

程序中变量ObjectSelected出现的顺序依次如下:(可以观察ObjectSelected的外接矩形的row坐标,看是否符合之前总结的规律)

image.png

对于排序后的xld元组SortedContours,我们可以发现它的升序排列第11项降序排列第(29-11+1)项是同一个对象,都是字母W。

image.png

有一个问题值得讨论一下:'upper_right', 'true', 'row''upper_left', 'true', 'row'有何区别?

我反复试了一下,结论是:没有区别。因为根据行(row)排列时,矩形的左上角和右上角的row值是一样的。

 

如果是根据row升序排列,如果row一样,那么再根据column升序排列;如果是根据row降序排列,如果row一样,那么再根据column降序排列。

 

至于其他几种排序方式,规律是一样的,无需赘言。

 

不知道看到这里的网友们懂了没有,反正我自己是搞懂了,要想彻底搞懂,很简单,用我提供的图和程序,反复变换排序的方式,跑一跑程序便知。



本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

会员中心
搜索
«    2024年4月    »
1234567
891011121314
15161718192021
22232425262728
2930
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 点击查阅微信群二维码
  • 扫描加勇哥的非标自动化群,验证答案:C#/C++/VB勇哥的非标自动化群
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:
  • 留言板:

Powered By Z-BlogPHP 1.7.2

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864