Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is getPerspectiveTransform broken in opencv python2 wrapper?

Tags:

python

opencv

Something appears to be afoul with "getPerspectiveTransform" in the python2 wrapper for opencv. For starters, it takes two arguments instead of the expected three.

So instead of the first wrapper's:

cv.GetPerspectiveTransform(source,destination,3x3mat)

It's now:

cv2.getPerspectiveTransform(?,?)

If I try to put in two sets of four quad vert coordinates as the arguments like so:

cv2.getPerspectiveTransform(first_set_of_corners, second_set_of_corners)

it spits out the following error:

cv2.error: C:\slave\WinInstallerMegaPack\src\opencv\modules\imgproc\src\imgwarp.
cpp:3194: error: (-215) src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV
_32F) == 4

If the checkVectors shouldn't equal four (hence the "quad" in quadrangle) then I'm not certain what it wants from me. As with everything else in the python2 wrapper this feature is completely undocumented so I don't know if it's broken or, more likely, that I'm doing it wrong. Has anyone here managed to get this to work properly?

like image 700
Snesticle Avatar asked Mar 21 '12 16:03

Snesticle


1 Answers

cv2.getPerspectiveTransform is not broken anyway.

May be, your points are of not length 4 or they may not be float32 numbers.

Try following :

import cv2
import numpy as np

img = cv2.imread('1original.jpg',0)

src = np.array([[50,50],[450,450],[70,420],[420,70]],np.float32)
dst = np.array([[0,0],[299,299],[0,299],[299,0]],np.float32)

ret = cv2.getPerspectiveTransform(src,dst)
print ret

Result is :

[[  8.36097696e-01  -4.51944700e-02  -3.95451613e+01]
 [ -4.51944700e-02   8.36097696e-01  -3.95451613e+01]
 [  6.45161290e-05   6.45161290e-05   1.00000000e+00]]
like image 114
Abid Rahman K Avatar answered Oct 27 '22 01:10

Abid Rahman K