(-215:断言失败) npoints >= 0 && (depth == CV_32F || depth == CV_32S) 在函数 'contourArea' 中

5

我试图运行创建图片的网站代码。

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

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'

我不确定其中的原因。


1
你的图像是32位格式吗? - Thomas Weller
2个回答

10

这个代码库显然是为OpenCV 3.x编写的,但你正在使用OpenCV 4.1。代码库中使用了find_contours(...)[1]来获取轮廓,你应该将1改为0。


3

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

这样做可以解决你的问题,因为在OpenCV(4 >)中,findContours(...)[0]会给你轮廓。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接