(-215:断言失败) 函数 'contourArea' 中的 n点 >= 0 && (深度 == CV_32F || 深度 == CV_32S)



我正在尝试运行网站代码以创建图像。

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

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'

我不确定其背后的原因。

repo清楚地为opencv 3.x编写。但是,您正在OpenCV 4.1上运行。Repo Code获取Contours(find_contours(...)[1](的find_contour的第二个返回值。您应该更改1到0。

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

这应该解决您的问题,如OpenCV(4>(FindContours(...([0]给您轮廓

最新更新