Unexpected behavior of cv2.getPerspectiveTransform

asked 2018-07-20 00:10:48 -0500

I have a set of points that I wanted to transform given the following two homographies. The second one is just the vertical translation of all the eight points by 300 pixels. However the output is very different for both, in particular the second transformation makes the transformed points to be "upside down" (rotated 180 degrees along y and x axis).

TRANSFORM_COORD_PAIR = {
'640x480d1': (
    ((297,   60), (100,200), (429, 60),  (640,200)), #Lefttop, leftbot, righttop, right bot
    ((220,   -200), (220,200), (440, -200),(440,200))
),
'640x480d2': (
    ((297,   360), (100,500), (429, 360),  (640,500)), #Lefttop, leftbot, righttop, rightbot
    ((220,   100), (220,500), (440, 100),(440,500))
)}
points=TRANSFORM_COORD_PAIR['640x480d2']    
persp_inv = cv2.getPerspectiveTransform(np.float32(points[1]), np.float32(points[0]))

A sample of points I use:

[ 38.99988556 183.99998474] [ 151.00003052 184. ] [ 299. 184. ] [ 382. 183.99998474] [ 554. 184. ] [ 21.99988937 179.99998474] [ 147.00004578 180. ] [ 298. 180.00003052] [ 384. 180.00001526] [ 15.99992466 175.99998474] [ 136.99993896 175.99998474] [ 297. 175.99996948] [ 387.99996948 176.00001526] [ 14.00001335 172. ] [ 124. 172.00001526] [ 296.00003052 172.00001526]

edit retag flag offensive close merge delete

Comments

your points are in the wrong order. either keep it clock or counter-clockwise, but be consistent.

berak gravatar imageberak ( 2018-07-20 00:52:56 -0500 )edit