When using OpenCV findContours
method, how come the contours are not found in order?
inputImage = cv2.imread("randomImage.jpg",0)
im2, contours, hierarchy = cv2.findContours(inputImage.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
j=1
for cnt in reversed(contours):
letter = inputImage[y:y+h, x:x+w]
cv2.imwrite(str(j)+"sub/"+str(k)+'.png', letter)
k+=1
The input image consists of a few letters, for example "abcde". However, when the contours are saved to file they are saved in a random order like "c", "e", "d", "a", "b". Is there any reason for this?
output: t, l, h, b, e, r, g, o, e