4

I'm trying to search a specific object in input images by matching SIFT descriptors and finding the transformation matrix by RANSAC. The object can only be modified in scene by similarity transform in 2D space (scaled, rotated, translated), so I need to estimate 2x2 transform matrix instead of 3x3 homography matrix in 3D space. How can I achieve this in OpenCV?

4

2 回答 2

5

可以使用estimateRigidTransform(不知道是不是RANSAC,代码在http://code.opencv.org/projects/opencv/repository/revisions/2.4.4/entry/modules/video/src/lkpyramid.cpp RANSAC 在其评论中说),第三个参数设置为false以获得缩放+旋转+平移:

#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;
}

使用 OpenCV 2.4.4 编译和测试。输出是:

[0.7071067988872528, -0.7071067988872528, 1.000000029802322;
  0.7071067988872528, 0.7071067988872528, 1.000000029802322]
于 2013-03-17T13:44:34.593 回答
2

您可以使用 opencv 查找点集之间的仿射变换,这比您描述的情况(称为相似变换)稍微更一般,因为它也描述了形状的剪切变换。

可以使用函数来执行getAffineTransform(InputArray src, InputArray dst)。这需要两组三个点并计算它们之间的仿射变换。

于 2013-02-12T16:40:10.893 回答