Opencv warp

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 the documentation:

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

Three parameters are in order. I have the same problem with cv2.warpAffine .

+6
source share
2 answers

The problem is resolved. img.shape returns a tuple with 3 elements, warpPerspective expects a tuple with 2.

+14
source

try it

 finished = cv2.warpPerspective(img, transform, img.shape[1::-1]) 
+2
source

Source: https://habr.com/ru/post/944177/


All Articles