【发布时间】:2018-02-23 13:16:22
【问题描述】:
我已预处理以下图像:
现在我想使用findContours 方法从图像中查找单元格,然后使用drawContours 为图像中的每个单元格绘制轮廓。我这样做了,但没有显示任何内容。
contours = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img, contours, -1, (0, 255, 0), 3)
我收到以下错误。
contours 不是 numpy 数组,也不是标量
其他答案对我没有帮助。
我也使用以下解决方案。
contours = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0]
ctr = numpy.array(contours).reshape((-1,1,2)).astype(numpy.int32)
cv2.drawContours(img, ctr, -1, (0, 255, 0), 3)
但是这个解决方案没有在给定的图像上绘制任何东西。
【问题讨论】:
标签: python numpy opencv image-processing computer-vision