Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv.findContours() eats the image while finding the countours( see Note here ).

if you need it later, please use a copy:

contours, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
print len(contours)
cv2.drawContours(thresh,contours,-1,(0,255,0),3)

cv.findContours() eats the image while finding the countours( countours(see Note here ).

if you need it later, please use a copy:

contours, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
print len(contours)
cv2.drawContours(thresh,contours,-1,(0,255,0),3)

cv.findContours() eats the image while finding the countours(see Note here).

if you need it later, please use a copy:

contours, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
print len(contours)
cv2.drawContours(thresh,contours,-1,(0,255,0),3)

the, since you want to draw something in color, you probably want to draw into img(which has 3 channels), not into thresh(which is binary, only 1 chan)

## your drawing is invisible, since you try to plot green
# cv2.drawContours(thresh,contours,-1,(0,255,0),3)
cv2.drawContours(img,contours,-1,(0,255,0),3)

cv.findContours() eats the image while finding the countours(see Note here).

if you need it later, please use a copy:

contours, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

the, then, since you want to draw something in color, you probably want to draw into img(which img(which has 3 channels), not into thresh(which thresh(which is binary, only 1 chan)

## your drawing is invisible, since you try to plot green
# cv2.drawContours(thresh,contours,-1,(0,255,0),3)
cv2.drawContours(img,contours,-1,(0,255,0),3)