【问题标题】:(-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'contourArea'(-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function'contourArea'
【发布时间】:2019-11-11 16:41:32
【问题描述】:

我正在尝试运行the website code to create the image.

当我运行代码时,它给了我一个错误:

cv2.error: OpenCV(4.1.0) 
/Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/shapedescr.cpp:274: 
error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) 
in function 'contourArea'

我不确定其背后的原因。

【问题讨论】:

  • 你的图片是 32 位格式的吗?

标签: python opencv


【解决方案1】:

repo 显然是为 OpenCV 3.x 编写的。但是,您在 OpenCV 4.1 上运行。回购代码采用 find_contour 的第二个轮廓返回值(find_contours(...)[1])。您应该将 1 更改为 0。

【讨论】:

    【解决方案2】:

    cnts = cv2.findContours(...)[0]

    这应该可以解决您的问题,如 OpenCV (4>) findContours(...)[0] 为您提供轮廓

    【讨论】:

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