This error occurs in OpenCV when there is an assertion failure. In this case, the error message is indicating that the assertion failed because the number of points in the contour is less than zero and the depth is not either 'CV_32F' or 'CV_32S'.

To fix this error, you can check the contour before passing it to the cv2.contourArea function. You should make sure that the contour has a positive number of points and the depth is either 'CV_32F' or 'CV_32S'.

Here is an example of how you can check the contour:

if len(cnt) >= 0:
    if cnt.dtype == np.int32:
        cnt = cnt.astype(np.float32)

Once you have confirmed that the contour is valid, you can then pass it to the cv2.contourArea function.


原文地址: https://www.cveoy.top/t/topic/neK3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录