This error occurs when the 'image' argument in the cv2.drawContours() function is not a valid image or is of the wrong type.

To fix this error, make sure that the 'image' argument is a valid image and is of the correct type (numpy array or cv::UMat). You can try converting the image to the correct type using the cv2.UMat() function before passing it to the drawContours() function.

Example:

img2 = cv2.imread('image.jpg')
um_img2 = cv2.UMat(img2)
cv2.drawContours(um_img2, cnt, -1, (0, 255, 0), 2)

This should convert the image to the correct type and allow the drawContours() function to run without errors.

cv2.drawContours() TypeError: Expected Ptr<cv::UMat> for argument 'image' - Python OpenCV Error Fix

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

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