How to evaluate the transformation of 2D similarity (linear conformal, non-reflective similarity) in OpenCV?

I am trying to search for a specific object in input images by matching SIFT descriptors and finding the RANSAC transform matrix. An object can only be changed in the scene using the similarity transform in 2D space (scaled, rotated, translated), so I need to evaluate the 2x2 transform matrix instead of the 3x3 homographic matrix in 3D space. How can I achieve this in OpenCV?

+4
source share
2 answers

You can use estimateRigidTransform (I don't know if this is RANSAC, the code http://code.opencv.org/projects/opencv/repository/revisions/2.4.4/entry/modules/video/src/lkpyramid.cpp says RANSAC in your comment), the third parameter is set to false to get just the scale + rotation + translation:

 #include <vector> #include <iostream> #include "opencv2/video/tracking.hpp" int main( int argc, char** argv ) { std::vector<cv::Point2f> p1s,p2s; p1s.push_back(cv::Point2f( 1, 0)); p1s.push_back(cv::Point2f( 0, 1)); p1s.push_back(cv::Point2f(-1, 0)); p1s.push_back(cv::Point2f( 0,-1)); p2s.push_back(cv::Point2f(1+sqrt(2)/2, 1+sqrt(2)/2)); p2s.push_back(cv::Point2f(1-sqrt(2)/2, 1+sqrt(2)/2)); p2s.push_back(cv::Point2f(1-sqrt(2)/2, 1-sqrt(2)/2)); p2s.push_back(cv::Point2f(1+sqrt(2)/2, 1-sqrt(2)/2)); cv::Mat t = cv::estimateRigidTransform(p1s,p2s,false); std::cout << t << "\n"; return 0; } 

compiled and tested with OpenCV 2.4.4. Output:

 [0.7071067988872528, -0.7071067988872528, 1.000000029802322; 0.7071067988872528, 0.7071067988872528, 1.000000029802322] 
+5
source

You can use the affine transformation between sets of points using opencv, which is a bit more general than the case you describe (known as similarity transformation), since it describes shear transformations of shapes as well.

It can be done using the getAffineTransform(InputArray src, InputArray dst) function getAffineTransform(InputArray src, InputArray dst) . It takes 2 sets of three points and computes the affine transformation between them.

+2
source

All Articles