• 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')

     1 read_image (Image, 'C:/Users/happy xia/Desktop/dynPic.png')
     2 threshold_sub_pix (Image, Border, 90)
     3 select_shape_xld (Border, SelectedXLD, 'contlength', 'and', 100, 99999)
     4 sort_contours_xld (SelectedXLD, SortedContours, 'upper_left', 'true', 'row')
     5 dev_set_draw ('margin')
     6 dev_display (Image)
     7 count_obj (SortedContours, Number)
     8 gen_empty_obj (EmptyObject)
     9 *注释:这里Number = 29
    10 for Index := 1 to Number by 1
    11     select_obj (SortedContours, ObjectSelected, Index) 
    12     smallest_rectangle1_xld (ObjectSelected, Row1, Column1, Row2, Column2)
    13     gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
    14     concat_obj (EmptyObject, ObjectSelected, EmptyObject) 
    15 endfor
    16 
    17 dev_display (Image)
    18 select_obj (SortedContours, ObjectSelected1, 11)
    19 sort_contours_xld (SelectedXLD, SortedContours2, 'upper_left', 'false', 'row')
    20 select_obj (SortedContours2, ObjectSelected2, Number - 11 + 1)

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

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

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

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

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

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

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

  • 相关阅读:
    jQuery 选择城市,显示对应的即时时区时间
    HTML5 LocalStorage 本地存储,刷新值还在
    jQuery 鼠标拖拽移动窗口
    css/css3常用收集/笔记
    Linux下删除命令 硬盘空间查看... 常用命令
    linux 下 zip unzip压缩与解压
    js字节转换、字节转换GB等
    jquery 判断网络图片,或网络文件是否存在
    js中substr,substring,indexOf,lastIndexOf,split 的用法
    apktool、dex2jar、jd-gui的区别及详解
  • 原文地址:https://www.cnblogs.com/xh6300/p/6536467.html
Copyright © 2020-2023  润新知