Using a RigidTransform score instead of findHomography

The link below is used findHomographyto get the conversion between two sets of points. I want to limit the degrees of freedom used in the conversion, so I want to replace findHomographywith estimateRigidTransform.

http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html#feature-homography

Below I use estimateRigidTransformto get the conversion between the object and the points in the scene. objPointsand scePointspresented vector <Point2f>.

Mat H = estimateRigidTransform(objPoints, scePoints, false);

Following the method used in the tutorial above, I want to convert the values ​​of angles using conversion H. The textbook is used perspectiveTransformwith a 3x3 matrix returned findHomography. With hard conversion, it returns a 2x3 matrix, so this method cannot be used.

How would I convert the values ​​of the angles represented as vector <Point2f>with this 2x3 matrix. I just want to perform the same functions as the textbook, but with less degrees of freedom for transformation. I also looked at other methods, such as warpAffineand getPerspectiveTransform, but have not yet found a solution.

EDIT:

I tried David Nilosek's suggestion. Below I add an extra row to the matrix.

Mat row = (Mat_<double>(1,3) << 0, 0, 1);
H.push_back(row);

However, this gives this error when using the Transform perspective.

OpenCV Error: Assertion failed (mtype == type0 || (CV_MAT_CN(mtype) == CV_MAT_CN(type0) && ((1 << type0) & fixedDepthMask) != 0)) in create, file /Users/cgray/Downloads/opencv-2.4.6/modules/core/src/matrix.cpp, line 1486
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/cgray/Downloads/opencv-2.4.6/modules/core/src/matrix.cpp:1486: error: (-215) mtype == type0 || (CV_MAT_CN(mtype) == CV_MAT_CN(type0) && ((1 << type0) & fixedDepthMask) != 0) in function create

ChronoTrigger warpAffine. warpAffine , 1 x 5 - objCorners sceCorners.

warpAffine(objCorners, sceCorners, H, Size(1,4));

, . objCorners sceCorners vector <Point2f>, 4 . , warpAffine Mat , .

OpenCV Error: Assertion failed ((M0.type() == CV_32F || M0.type() == CV_64F) && M0.rows == 2 && M0.cols == 3) in warpAffine, file /Users/cgray/Downloads/opencv-2.4.6/modules/imgproc/src/imgwarp.cpp, line 3280
+4
3

:

cv::Mat R = cv::estimateRigidTransform(p1,p2,false);

    if(R.cols == 0)
    {
        continue;
    }

    cv::Mat H = cv::Mat(3,3,R.type());
    H.at<double>(0,0) = R.at<double>(0,0);
    H.at<double>(0,1) = R.at<double>(0,1);
    H.at<double>(0,2) = R.at<double>(0,2);

    H.at<double>(1,0) = R.at<double>(1,0);
    H.at<double>(1,1) = R.at<double>(1,1);
    H.at<double>(1,2) = R.at<double>(1,2);

    H.at<double>(2,0) = 0.0;
    H.at<double>(2,1) = 0.0;
    H.at<double>(2,2) = 1.0;


    cv::Mat warped;
    cv::warpPerspective(img1,warped,H,img1.size());

: 0 0 1

IMAGES .

/ , perspectiveTransform 3x3 (http://docs.opencv.org/modules/core/doc/operations_on_arrays.html?highlight=perspectivetransform#perspectivetransform)

:

http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html

,

cv::Point2f result;
result.x = point.x * R.at<double>(0,0) + point.y * R.at<double>(0,1) + R.at<double>(0,2);
result.y = point.x * R.at<double>(1,0) + point.y * R.at<double>(1,1) + R.at<double>(1,2);

, .

: , . PerspectiveTransform!

edit: () :

// points
std::vector<cv::Point2f> p1;
p1.push_back(cv::Point2f(0,0));
p1.push_back(cv::Point2f(1,0));
p1.push_back(cv::Point2f(0,1));

// simple translation from p1 for testing:
std::vector<cv::Point2f> p2;
p2.push_back(cv::Point2f(1,1));
p2.push_back(cv::Point2f(2,1));
p2.push_back(cv::Point2f(1,2));

cv::Mat R = cv::estimateRigidTransform(p1,p2,false);

// extend rigid transformation to use perspectiveTransform:
cv::Mat H = cv::Mat(3,3,R.type());
H.at<double>(0,0) = R.at<double>(0,0);
H.at<double>(0,1) = R.at<double>(0,1);
H.at<double>(0,2) = R.at<double>(0,2);

H.at<double>(1,0) = R.at<double>(1,0);
H.at<double>(1,1) = R.at<double>(1,1);
H.at<double>(1,2) = R.at<double>(1,2);

H.at<double>(2,0) = 0.0;
H.at<double>(2,1) = 0.0;
H.at<double>(2,2) = 1.0;

// compute perspectiveTransform on p1
std::vector<cv::Point2f> result;
cv::perspectiveTransform(p1,result,H);

for(unsigned int i=0; i<result.size(); ++i)
    std::cout << result[i] << std::endl;

:

[1, 1]
[2, 1]
[1, 2]
+4

( cv::estimateRigidTransform) cv::warpAffine.

+2

3x3 :

 a1 a2 b1
-a2 a3 b2
  0  0  1

Therefore, when using, estimateRigidTransformyou can add [0 0 1] as the third row if you need a 3x3 matrix.

+2
source

Source: https://habr.com/ru/post/1538629/


All Articles