Sometimes when I use this function, it does not detect the edges of an image, that is because I would like to know how to exit the function, in case it does not find any contour, with an if loop for example.
def sort_contours(cnts,reverse = False):
i = 0
boundingBoxes = [cv2.boundingRect(c) for c in cnts]
#if cnts==0:
#quit()
(cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes),
key=lambda b: b[1][i], reverse=reverse))
return cnts
With this output in failure case:
7 (cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes),
----> 8 key=lambda b: b[1][i], reverse=reverse))
9 return cnts
10
ValueError: not enough values to unpack (expected 2, got 0)
Before I made this
#if cnts==0:
#quit()
Which does not work, any ideas?