There are 5 sorts of sort_contours_xld operators, namely:
' 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 is also sorted according to the remaining coordinate, if they overlap in the di Rection of the coordinate which is specified by the parameter roworcol.
The ' character ' sort method is not very good to understand, but from the English explanation, it is similar to the ' upper_left ' sort, I think generally speaking, the previous four sort methods generally enough.
As an example of the ' upper_left ' sort, the translation of its English explanation is that the position is determined by the upper left corner of the bounding rectangle.
So I guess it means this: for a group of XLD, draw the smallest parallel rectangle (gen_rectangle1) for each xld, and then sort the xld according to the coordinates of the upper-left corner of the rectangles.
First look at operator signatures:
Sort_contours_xld (Contours:SortedContours:SortMode, Order, Roworcol:)
Order can take ' true ' or ' false ',' true ' is ascending order, ' false ' is descending order.
Roworcol can take ' row ' or ' column '.
This is arranged in the following way:(in ascending order based on the row coordinates of the upper-left corner of the smallest bounding rectangle)
Sort_contours_xld (Selectedxld, sortedcontours, ' Upper_left ', ' true ', ' Row ')
1Read_image (Image,'c:/users/happy xia/desktop/dynpic.png')2Threshold_sub_pix (Image, Border, -)3Select_shape_xld (Border, SELECTEDXLD,'Contlength',' and', -,99999)4Sort_contours_xld (SELECTEDXLD, Sortedcontours,' upper_left ', ' true ', ' Row ')5Dev_set_draw ('margin')6 Dev_display (Image)7 count_obj (sortedcontours, number)8 gen_empty_obj (emptyobject)9* Note: here number = inTen forIndex: =1To number by1 One select_obj (sortedcontours, objectselected, Index) A smallest_rectangle1_xld (objectselected, Row1, Column1, Row2, Column2) - Gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2) - concat_obj (Emptyobject, objectselected, Emptyobject) the endfor - - Dev_display (Image) -Select_obj (Sortedcontours, ObjectSelected1, One) +Sort_contours_xld (SELECTEDXLD, SortedContours2,' upper_left ', ' false ', ' Row ') -Select_obj (SortedContours2, ObjectSelected2,Number-11 + 1)
The order in which the variable objectselected appears in the program is as follows: (You can observe the row coordinates of the objectselected's external rectangle to see if it conforms to the previously summarized law)
For the sorted xld tuple sortedcontours, we can find it in ascending order of the 11th and descending order (29-11+1) entries are the same object, both of which are the letter W.
One question is worth discussing:' upper_right ', ' true ', ' Row ' and ' Upper_left ', ' true ', what's the difference between ' row '?
I tried again and again, and the conclusion was: no difference. Because rows are arranged by row, the upper-left corner of the rectangle is the same as the row value in the upper-right corner.
If the row is sorted in ascending order, it is arranged in ascending order according to column, if Row is the same, and then in descending order of column, if it is in descending order.
As for the other kinds of sorting, the law is the same, needless to be discussed.
Research on several sort methods of sort_contours_xld operator