Ask Your Question

How to find rotation angle from homography matrix?

asked 2018-11-22 23:30:21 -0500

ronak.dedhia gravatar image

updated 2018-11-23 04:50:04 -0500

berak gravatar image

I have 2 images and i am finding simliar key points by SURF. I want to find rotation angle between the two images from homograpohy matrix. Can someone please tell me how to find rotation angle between two images from homography matrix.

 if len(good)>MIN_MATCH_COUNT:
    src_pts = np.float32([ kp1[m.queryIdx].pt for m in good ]).reshape(-1,1,2)
    dst_pts = np.float32([ kp2[m.trainIdx].pt for m in good ]).reshape(-1,1,2)

    M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC,5.0)

Thank you.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-11-23 04:54:21 -0500

berak gravatar image

findHomography might return an empty Mat, if it could not find a good transformation, so you need to check for that !

then it's just maths:

        if np.shape(M) == ():
            print( "No transformation possible" )
            return None, None

        ## derive rotation angle from homography
        theta = - math.atan2(M[0,1], M[0,0]) * 180 / math.pi
edit flag offensive delete link more

Comments for me...sorry cant upvote since its showing points should be greater than 5

ronak.dedhia gravatar imageronak.dedhia ( 2018-11-26 22:01:32 -0500 )edit

Question Tools

1 follower


Asked: 2018-11-22 23:30:21 -0500

Seen: 4,710 times

Last updated: Nov 23 '18