(cnts, method="left-to-right")
| 5 | import cv2 |
| 6 | |
| 7 | def sort_contours(cnts, method="left-to-right"): |
| 8 | # initialize the reverse flag and sort index |
| 9 | reverse = False |
| 10 | i = 0 |
| 11 | |
| 12 | # handle if we need to sort in reverse |
| 13 | if method == "right-to-left" or method == "bottom-to-top": |
| 14 | reverse = True |
| 15 | |
| 16 | # handle if we are sorting against the y-coordinate rather than |
| 17 | # the x-coordinate of the bounding box |
| 18 | if method == "top-to-bottom" or method == "bottom-to-top": |
| 19 | i = 1 |
| 20 | |
| 21 | # construct the list of bounding boxes and sort them from top to |
| 22 | # bottom |
| 23 | boundingBoxes = [cv2.boundingRect(c) for c in cnts] |
| 24 | (cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes), |
| 25 | key=lambda b: b[1][i], reverse=reverse)) |
| 26 | |
| 27 | # return the list of sorted contours and bounding boxes |
| 28 | return cnts, boundingBoxes |
| 29 | |
| 30 | |
| 31 | def label_contour(image, c, i, color=(0, 255, 0), thickness=2): |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…