【问题标题】:Which of types Mat or vector<Point2f> is better to use with function estimateRigidTransform()?Mat 或 vector<Point2f> 哪种类型更适合与函数 estimateRigidTransform() 一起使用?
【发布时间】:2015-02-09 14:35:48
【问题描述】:

众所周知,我们可以将两个参数传递给函数estimateRigidTransform(),它们具有以下两种类型之一:Mat estimateRigidTransform(InputArray src, InputArray dst, bool fullAffine)

  1. cv::Mat frame1, frame2;
  2. std::vector&lt;cv::Point2f&gt; frame1_features, frame2_features;

例如,要实现视频稳定(抖动移除),我们可以使用以下两种方法之一:

  1. cv::Mat:video stabilization using opencv
cv::Mat frame1 = imread("frame1.png");
cv::Mat frame2 = imread("frame2.png");
Mat M = estimateRigidTransform(frame1, frame2, 0);
warpAffine(frame2, output, M, Size(640,480), INTER_NEAREST|WARP_INVERSE_MAP);
  1. std::vector&lt;cv::Point2f&gt; features;
vector <uchar> status;
vector <float> err;

std::vector <cv::Point2f> frame1_features, frame2_features;
cv::Mat frame1 = imread("frame1.png");
cv::Mat frame2 = imread("frame2.png");
goodFeaturesToTrack(frame1 , frame1_features, 200, 0.01, 30);
goodFeaturesToTrack(frame2 , frame2_features, 200, 0.01, 30);
calcOpticalFlowPyrLK(frame1 , frame2, frame1_features, frame2_features, status, err);

std::vector <cv::Point2f> frame1_features_ok, frame2_features_ok;
for(size_t i=0; i < status.size(); i++) {
 if(status[i]) {
  frame1_features_ok.push_back(frame1_features[i]);
  frame2_features_ok.push_back(frame2_features[i]);
 }
}

Mat M = estimateRigidTransform(frame1_features_ok, frame2_features_ok, 0);
warpAffine(frame2, output, M, Size(640,480), INTER_NEAREST|WARP_INVERSE_MAP);

这些方法中哪一种更好用,为什么?

Matvector&lt;Point2f&gt; 哪种类型更适合与函数 estimateRigidTransform() 一起使用?

【问题讨论】:

  • 第一个版本没有让您对如何计算刚性变换的方式进行任何控制。所以它使用起来可能很舒服,但在这种情况下,我无法说出估计转换的质量。我更喜欢将第二个版本与我自己的点对应(不一定来自光流)一起使用。
  • @Micka“不一定来自光流”,但是,例如,来自什么?
  • 筛选或其他关键点、块匹配、密集匹配或任何其他“对应”

标签: opencv image-processing opencv3.0 image-stabilization


【解决方案1】:

在第一种情况下,OpenCV 将在函数 estimateRigidTransform() 内隐式执行 calcOpticalFlowPyrLK()。请参阅lkpyramid.cpp @ line 1383 中的实现。

这是两种方法的唯一区别。如果找到frame1frame2 之间的对应关系很重要,则使用版本#2,否则使用#1。

【讨论】:

    猜你喜欢
    • 2014-06-28
    • 1970-01-01
    • 2019-11-04
    • 2013-02-04
    • 2010-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多