如何估计OpenCV中的2D相似变换(线性共形,非反射相似性)? [英] How to estimate 2D similarity transformation (linear conformal, nonreflective similarity) in OpenCV?

查看:1107
本文介绍了如何估计OpenCV中的2D相似变换(线性共形,非反射相似性)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过匹配SIFT描述符并通过RANSAC查找转换矩阵来搜索输入图像中的特定对象。该对象只能通过2D空间中的相似变换(缩放,旋转,平移)在场景中进行修改,因此我需要在3D空间中估计2x2变换矩阵而不是3x3单应矩阵。如何在OpenCV中实现这一目标?

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?

推荐答案

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

You can use estimateRigidTransform (I do not know whether it is RANSAC, the code at http://code.opencv.org/projects/opencv/repository/revisions/2.4.4/entry/modules/video/src/lkpyramid.cpp says RANSAC in its comment), the third parameter is set to false in order to get just 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;
}

使用OpenCV 2.4.4进行编译和测试。
输出结果为:

compiled and tested with OpenCV 2.4.4. The output is:

[0.7071067988872528, -0.7071067988872528, 1.000000029802322;
  0.7071067988872528, 0.7071067988872528, 1.000000029802322]

这篇关于如何估计OpenCV中的2D相似变换(线性共形,非反射相似性)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆