Search code examples
ocropencvpython

OpenCV Error. Expected Ptr<cv::UMat> for argument '%s', What kind of error is this?


Below I have provided the snippet of the code

kernel=np.ones((1, 1), np.float32)
img=cv2.dilate(pages[0], kernel, iterations=1)
img=cv2.erode(pages[0], kernel, iterations=1)
text=str(pt.image_to_string(img))

I am getting some errors in the second line of the above code. Thanks in advance!


Solution

  • The error you are getting is because pages[0] is not the right form. cv2.Umat() is functionally equivalent to np.float32(), so your code should read:

    img = cv2.dilate(np.float32(pages[0]), kernel, iterations=1)
    img = cv2.erode(np.float32(pages[0]), kernel, iterations=1)