OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 12 Sep 2019 11:23:06 -0500Determine the rotation, translation and scaling in homography matrix from estimateAffinePartial2D; Can I force no scaling? (Euclidan/Rigid)http://answers.opencv.org/question/218226/determine-the-rotation-translation-and-scaling-in-homography-matrix-from-estimateaffinepartial2d-can-i-force-no-scaling-euclidanrigid/I'm trying to align scans to a blank template -- images are from the same scanner at same scale, just rotated and translated. I find ORB feature matching as described [here](https://www.learnopencv.com/image-alignment-feature-based-using-opencv-c-python/).
I've had good luck using findHomography and then sending that homography matrix to warpPerspective. However, findHomography allows more degrees of freedom than necessary; We just do rotation and translation, no scaling.
estimateAffinePartial2D gives me a 3x2 matrix --
**How can I determine the rotation, translations (x&y) , and the scaling contained in that matrix?** That way, if scaling is not close to 1, I know the homography is bad.
**Is there a way I can FORCE the estimateAffinePartial2D to find only solutions where scaling 1???**
Wed, 11 Sep 2019 16:49:51 -0500http://answers.opencv.org/question/218226/determine-the-rotation-translation-and-scaling-in-homography-matrix-from-estimateaffinepartial2d-can-i-force-no-scaling-euclidanrigid/Comment by swebb_denver for <p>I'm trying to align scans to a blank template -- images are from the same scanner at same scale, just rotated and translated. I find ORB feature matching as described <a href="https://www.learnopencv.com/image-alignment-feature-based-using-opencv-c-python/">here</a>. </p>
<p>I've had good luck using findHomography and then sending that homography matrix to warpPerspective. However, findHomography allows more degrees of freedom than necessary; We just do rotation and translation, no scaling.</p>
<p>estimateAffinePartial2D gives me a 3x2 matrix --
<strong>How can I determine the rotation, translations (x&y) , and the scaling contained in that matrix?</strong> That way, if scaling is not close to 1, I know the homography is bad. </p>
<p><strong>Is there a way I can FORCE the estimateAffinePartial2D to find only solutions where scaling 1???</strong> </p>
http://answers.opencv.org/question/218226/determine-the-rotation-translation-and-scaling-in-homography-matrix-from-estimateaffinepartial2d-can-i-force-no-scaling-euclidanrigid/?comment=218285#post-id-218285I'm not sure what the differences are between estimateAffinePartial2D and estimateRigidTransform, but I use the former (with the third parameter set to false) - you might want to compare the results between the two.
As for scaling, if you use esimateRigidTransform with the third parameter set to false, you will get a translation, rotation and uniform scale (no projective or shear)...so the upper 2x2 part of the matrix will have the form:
<br>
cos * S -sin * S<br>
sin * S cos * S<br>
and since cos^2 + sin^2 = 1, you can determine what S is and then divide it out of the result. It's a bit more work, but I think it would achieve what you want.Thu, 12 Sep 2019 11:23:06 -0500http://answers.opencv.org/question/218226/determine-the-rotation-translation-and-scaling-in-homography-matrix-from-estimateaffinepartial2d-can-i-force-no-scaling-euclidanrigid/?comment=218285#post-id-218285