Ask Your Question
0

How to find rotation angle from homography matrix?

asked Nov 23 '18

ronak.dedhia gravatar image

updated Nov 23 '18

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.

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Nov 23 '18

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
Preview: (hide)

Comments

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

ronak.dedhia gravatar imageronak.dedhia (Nov 27 '18)edit

Question Tools

1 follower

Stats

Asked: Nov 23 '18

Seen: 7,472 times

Last updated: Nov 23 '18