Ask Your Question

SystemError: <class 'cv2.UMat'> returned NULL without setting an error

asked 2020-09-11 01:44:56 -0500

hoseinimage gravatar image

hi i after computation a Mapping Matrix using RANSAC and Below command:

src_pts = np.float32([kp1[m.queryIdx].pt for m in matches]).reshape(-1, 1, 2)
dst_pts = np.float32([kp2[m.trainIdx].pt for m in matches]).reshape(-1, 1, 2)
 homography = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0)

h, w = model.shape
pts = np.float32([[0, 0], [0, h - 1], [w - 1, h - 1], [w - 1, 0]]).reshape(-1, 1, 2)

then for Projecting Corners Keypoints into a 3d Image, I used perspectiveTransform command:

dst = cv2.perspectiveTransform(cv2.UMat(pts, homography))

but pycharm gives this error due to UMat usage:

SystemError: <class 'cv2.umat'=""> returned NULL without setting an error

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-09-11 02:28:44 -0500

berak gravatar image

there are several errors in your code, first, cv2.findHomography returns a tuple, see:

>>> help(cv2.findHomography)
    findHomography(srcPoints, dstPoints[, method[, ransacReprojThreshold[, mask[, maxIters[, confidence]]]]]) -> retval, mask

and you need ONLY the retval (the actual transform matrix)

then, this is entirely broken:

dst = cv2.perspectiveTransform(cv2.UMat(pts, homography))

you don't need a UMat at all, and there is no constructor for it taking 2 arrays. in the end, it should work like this:

# mask is unused
homography, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0)
dst = cv2.perspectiveTransform(pts, homography)
edit flag offensive delete link more


hi thanks- i changed my code to : homography = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0,) dst = cv2.perspectiveTransform(pts, homography) and pycharm gives this error: TypeError: Expected Ptr<cv::umat> for argument 'm'

hoseinimage gravatar imagehoseinimage ( 2020-09-13 05:35:59 -0500 )edit

hi thanks a lot, with using mask and your Code line solved. homography, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0)

hoseinimage gravatar imagehoseinimage ( 2020-09-13 05:49:22 -0500 )edit

you said Findhomography returned a tuple, and since tuple contents are unchangeable, so in below line:

dst = cv2.perspectiveTransform(pts, homography) python can not apply perspectiveTransform command to my TUPLE (homography)?? i.e I MUST Delete : dst = cv2.perspectiveTransform(pts, homography) ??

hoseinimage gravatar imagehoseinimage ( 2020-09-13 05:55:09 -0500 )edit

Question Tools

1 follower


Asked: 2020-09-11 01:44:56 -0500

Seen: 258 times

Last updated: Sep 11 '20