I want to find the contours of an image to then draw its convex hull. What I am doing is loading the image, threshold it, find its contours and then draw the convex hull.
gray = cv2.imread(test_paths[i], 0)
ret, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY_INV)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnt = contours[0]
The number of contours detected is equal to 1. The problem comes when I try to plot the contours, if I do
cv2.drawContours(cnt_dst, cnt, -1, (255, 0, 0), 3)
plt.imshow(cnt_dst)
If I change the code to the following:
cv2.drawContours(cnt_dst, contours, 0, (255, 0, 0), 3)
plt.imshow(cnt_dst)
The contours are different:
Note that I am getting the same (nice) result with this:
cv2.drawContours(cnt_dst, contours, -1, (255, 0, 0), 3)
Any ideas of why this is happening?