OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Mon, 26 Nov 2018 22:01:32 -0600How to find rotation angle from homography matrix?http://answers.opencv.org/question/203890/how-to-find-rotation-angle-from-homography-matrix/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.Thu, 22 Nov 2018 23:30:21 -0600http://answers.opencv.org/question/203890/how-to-find-rotation-angle-from-homography-matrix/Answer by berak for <p>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.</p>
<pre><code> 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)
</code></pre>
<p>Thank you.</p>
http://answers.opencv.org/question/203890/how-to-find-rotation-angle-from-homography-matrix/?answer=203919#post-id-203919findHomography 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
Fri, 23 Nov 2018 04:54:21 -0600http://answers.opencv.org/question/203890/how-to-find-rotation-angle-from-homography-matrix/?answer=203919#post-id-203919Comment by ronak.dedhia for <p>findHomography might return an empty Mat, if it could not find a good transformation, so you need to check for that !</p>
<p>then it's just maths: </p>
<pre><code> 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
</code></pre>
http://answers.opencv.org/question/203890/how-to-find-rotation-angle-from-homography-matrix/?comment=204117#post-id-204117Thankyou..works for me...sorry cant upvote since its showing points should be greater than 5Mon, 26 Nov 2018 22:01:32 -0600http://answers.opencv.org/question/203890/how-to-find-rotation-angle-from-homography-matrix/?comment=204117#post-id-204117