Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv warpPerspective parameter count

In my script I have the following code:

src = numpy.array(cornersSheet, numpy.float32)
dst = numpy.array(cornersDesired, numpy.float32)
transform = cv2.getPerspectiveTransform(src,dst)
finished = cv2.warpPerspective(img, transform, img.shape)

Python says:

Traceback (most recent call last):
File "./script.py", line 138, in <module>
    finished = cv2.warpPerspective(img, transform, img.shape)
TypeError: function takes exactly 2 arguments (3 given)

but according to documentation:

    Python: cv2.warpPerspective(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]]) → dst

three parameters are OK. I have the same issue with cv2.warpAffine.

like image 578
Adam Trhon Avatar asked May 03 '13 06:05

Adam Trhon


2 Answers

Problem solved. img.shape returns tuple with 3 elements, warpPerspective expects tuple with 2.

like image 175
Adam Trhon Avatar answered Nov 18 '22 03:11

Adam Trhon


Try this

finished = cv2.warpPerspective(img, transform, img.shape[1::-1])
like image 5
Refael Vivanti Avatar answered Nov 18 '22 05:11

Refael Vivanti