【发布时间】:2018-02-14 06:22:54
【问题描述】:
我在使用 python 时遇到 cv2.drawContours() 问题
问题:我无法显示单个轮廓。我只想得到曲目
代码如下:
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'):
cv2.destroyAllWindows()
break
Original Image When drawContours() is Set to, 0
但如果我将轮廓数设置为显示 = -1(全部),它似乎会得到一些轮廓
When drawContours() is Set to, -1
我已经尽力解决这个问题,任何建议都将不胜感激
【问题讨论】: