beyblade41
beyblade41

Reputation: 85

cv2.findContours doesn't find contours

i need to find contours of brown regions. but befıre that, i tried to draw all contours. but i can't see any contour on

i tried this:

contours, hierarchy = cv2.findContours(thresh_dummy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) 
cv2.drawContours(thresh_dummy, contours, -1, (0, 255, 0), 3) 

Upvotes: 1

Views: 1536

Answers (1)

Bolat
Bolat

Reputation: 379

I think the reason why you are not seeing contours in the output image is because you are drawing contours with (0, 255, 0), which would not be visible on a grayscale image (thresh_dummy happens to be a grayscale image). What you could do is convert thresh_dummy to RGB before drawing the contours or you could just use a random color like (128, 255, 128) which would be visible on the specific example you have.

contours, hierarchy = cv2.findContours(thresh_dummy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) 
thresh_color = cv2.cvtColor(thresh_dummy, cv2.COLOR_GRAY2RGB)
cv2.drawContours(thresh_color, contours, -1, (0, 255, 0), 3)
cv2.imwrite("thresh_color.jpg", thresh_color)

enter image description here

Upvotes: 2

Related Questions