15

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.

Adam Trhon
  • 2,915
  • 1
  • 20
  • 51

2 Answers2

27

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

Adam Trhon
  • 2,915
  • 1
  • 20
  • 51
5

Try this

finished = cv2.warpPerspective(img, transform, img.shape[1::-1])
sphinks
  • 3,048
  • 8
  • 39
  • 55
  • What is `[1::-1]`mean? – tomfriwel Sep 27 '17 at 01:39
  • 1
    @tomfriwel In Python list indexing is [begin:end:step], so [1::-1] means from the second element (indexes start at 0) to end, reversed. See https://stackoverflow.com/questions/509211/understanding-pythons-slice-notation – Adam Trhon Jul 16 '18 at 12:02