【发布时间】:2017-05-25 03:03:34
【问题描述】:
我想找到图像的轮廓,然后绘制它的凸包。我正在做的是加载图像,对其设置阈值,找到它的轮廓,然后绘制凸包。
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]
检测到的轮廓数等于 1。 当我尝试绘制轮廓时,问题就来了,如果我这样做了
cv2.drawContours(cnt_dst, cnt, -1, (255, 0, 0), 3)
plt.imshow(cnt_dst)
如果我将代码更改为以下内容:
cv2.drawContours(cnt_dst, contours, 0, (255, 0, 0), 3)
plt.imshow(cnt_dst)
轮廓不同:
请注意,我得到了相同(不错)的结果:
cv2.drawContours(cnt_dst, contours, -1, (255, 0, 0), 3)
你知道为什么会这样吗?
【问题讨论】:
标签: python opencv computer-vision opencv-contour