Home Problems drawing a specific contour using cv2.drawContours() Python 3
Reply: 0

Problems drawing a specific contour using cv2.drawContours() Python 3

user1205 Published in May 26, 2018, 9:38 pm

I am having a problem with cv2.drawContours() using python

Problem: I can't show single contour. I would like to get just the track

Here is the Code:

original_image = np.array(ImageGrab.grab(bbox))

crop_img = original_image[200:307, :, :]

# Convert BGR to HSV
hsv = cv2.cvtColor(crop_img, cv2.COLOR_BGR2HSV)

# define range of track (grey) color in HSV
lower_grey = np.array([0, 0, 0])
upper_grey = np.array([255, 40, 150])

# Threshold the HSV image to get only gery colors
grey_mask = cv2.inRange(hsv, lower_grey, upper_grey)
grey_mask2 = grey_mask.copy()

_, contours, heir = cv2.findContours(grey_mask2, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

cv2.drawContours(grey_mask2, contours, 0, (0, 255, 0), 3)

cv2.imshow('Orig Image', crop_img)
cv2.imshow('Grey Mask', grey_mask2)

if cv2.waitKey(25) & 0xFF == ord('q'):

Original Image When drawContours() is Set to, 0

but it seems to get a few contours if I set the number of contours to show = -1 (all of them)

When drawContours() is Set to, -1

I've tried my best to fix this one, any advice would be highly appreciated

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302635 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO