【问题标题】:How to fix error: (-215:Assertion failed) npoints > 0 in function 'drawContours'如何修复错误:(-215:Assertion failed) npoints > 0 in function 'drawContours'
【发布时间】:2019-04-15 19:52:08
【问题描述】:

绘制轮廓错误 我正在尝试为图像中的对象绘制轮廓

(_, contours) = cv2.findContours(binary, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)

# draw contours over original image
length = len(contours)
for c in range(length):
    cv2.drawContours(img,contours,c,(255,0,0),3)

cv2.namedWindow("output", cv2.WINDOW_NORMAL)
cv2.imshow("output", img)
cv2.waitKey(0)

我希望绘制所有轮廓,但我得到的实际结果是 错误:

(-215:Assertion failed) npoints > 0 in function 'drawContours'

【问题讨论】:

  • 有没有机会分享完整的代码以获得一个工作示例?发布软件版本,以及您的输入图像和输出图像(如果可能,错误版本)和原始回溯。蟒蛇?

标签: opencv opencv-contour


【解决方案1】:

轮廓应该是 numpy 数组。 将您的代码更改为:

for c in contours:
    cv2.drawContours(img,[c], 0, (255,0,0),3)

【讨论】:

    【解决方案2】:

    你有轮廓,层次倒退。请参阅findContours()上的 OpenCv 文档

    contours, hierarchy = cv2.findContours(binary,2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    

    【讨论】:

      猜你喜欢
      • 2022-10-17
      • 2021-04-05
      • 2019-11-11
      • 2021-04-09
      • 1970-01-01
      • 2019-11-12
      • 2020-09-03
      • 1970-01-01
      • 2019-10-18
      相关资源
      最近更新 更多