# sort_region算子对多个区域进行排序研究

sort_region是个很有用的算子，在对多个Region进行排序时，经常用到。

sort_region (Regions, SortedRegions, 'first_point', 'true', 'row')

sort_region (Regions, SortedRegions, 'first_point', 'true', 'row')

 1 dev_get_window (WindowHandle)
2 dev_set_color ('red')
3 set_display_font (WindowHandle, 13, 'Courier', 'true', 'false')
4
6 threshold (Image, Region, 0, 120)
7 fill_up (Region, Region)
8 opening_circle (Region, Region, 3.5)
9 connection (Region, Regions)
10
11 sort_region (Regions, SortedRegions, 'first_point', 'true', 'row')
12
13 dev_display (Image)
14
15 count_obj (SortedRegions, Number)
16 for Index := 1 to Number by 1
17     select_obj (SortedRegions, CurrentRect, Index)
18     dev_display (CurrentRect)
19     area_center (CurrentRect, Area, Row, Column)
20     disp_message (WindowHandle, ' ' + Index, 'image', Row - 8, Column - 20, 'black', 'true')
21 endfor

sort_region (Regions, SortedRegions, 'character', 'true', 'row')

① 同一行中有1个或多个区域，这些区域合起来叫做“同一行”

“同一行”的若干个区域可以重叠，因为可以通过“列”区分开。

 1 dev_get_window (WindowHandle)
2 dev_set_color ('blue')
3 set_display_font (WindowHandle, 18, 'Courier', 'true', 'false')
4
6
7 * 反复改变下面的部分矩形的中心点坐标、长宽，观察
8 gen_rectangle2 (Region1, 80, 120, 0, 40, 30)
9 gen_rectangle2 (Region2, 83, 350, 0, 40, 30)
10 gen_rectangle2 (Region3, 77, 580, 0, 40, 30)
11
12 gen_rectangle2 (Region4, 245, 300, 0, 40, 121)
13
14 gen_rectangle2 (Region5, 400, 235, 0, 40, 30)
15 gen_rectangle2 (Region6, 396, 450, 0, 40, 30)
16
17 concat_obj (Region1, Region2, RectHubs)
18 concat_obj (RectHubs, Region3, RectHubs)
19 concat_obj (RectHubs, Region4, RectHubs)
20 concat_obj (RectHubs, Region5, RectHubs)
21 concat_obj (RectHubs, Region6, RectHubs)
22
23 * 将RectHubs按'character'规则排序
24 sort_region (RectHubs, SortedRegions, 'character', 'true', 'row')
25
26 dev_display (Image)
27
28 count_obj (SortedRegions, Number)
29 for Index := 1 to Number by 1
30     select_obj (SortedRegions, CurrentRect, Index)
31     dev_display (CurrentRect)
32     area_center (CurrentRect, Area, Row, Column)
33     disp_message (WindowHandle, ' ' + Index, 'image', Row - 12, Column - 26, 'black', 'true')
34 endfor

“第一行”：矩形1、2、3

“第二行”：矩形4

“第三行”：矩形5、6

“第一行”：矩形1、2、3

“第二行”：矩形4、5、6

 1 dev_get_window (WindowHandle)
2 dev_set_color ('red')
3 set_display_font (WindowHandle, 13, 'Courier', 'true', 'false')
4
6 threshold (Image, Region, 0, 120)
7 fill_up (Region, Region)
8 opening_circle (Region, Region, 3.5)
9 connection (Region, Regions)
10
11 sort_region (Regions, SortedRegions, 'character', 'true', 'row')
12
13 dev_display (Image)
14
15 count_obj (SortedRegions, Number)
16 for Index := 1 to Number by 1
17     select_obj (SortedRegions, CurrentRect, Index)
18     dev_display (CurrentRect)
19     area_center (CurrentRect, Area, Row, Column)
20     disp_message (WindowHandle, ' ' + Index, 'image', Row - 8, Column - 20, 'black', 'true')
21 endfor

posted on 2022-08-10 17:33  xh6300  阅读(4792)  评论(0编辑  收藏  举报