[英]Which of types Mat or vector<Point2f> is better to use with function estimateRigidTransform()?
As known, we can pass to the function estimateRigidTransform()
two parameters with one of two types: Mat estimateRigidTransform(InputArray src, InputArray dst, bool fullAffine)
众所周知,我们可以将具有两种类型之一的两个参数传递给函数
Mat estimateRigidTransform(InputArray src, InputArray dst, bool fullAffine)
estimateRigidTransform()
: Mat estimateRigidTransform(InputArray src, InputArray dst, bool fullAffine)
cv::Mat frame1, frame2;
std::vector<cv::Point2f> frame1_features, frame2_features;
Ie, for example, to implement video-stabilization (shake remove) we can use one of two approach: 即,例如,要实现视频稳定(抖动消除),我们可以使用以下两种方法之一:
cv::Mat
: video stabilization using opencv cv::Mat
: 使用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);
std::vector<cv::Point2f> features;
std::vector<cv::Point2f> 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);
Which of these approach is better to use, and why? 哪种方法更适合使用,为什么?
Ie which of types Mat
or vector<Point2f>
is better to use with function estimateRigidTransform()? 即哪种
Mat
或vector<Point2f>
类型更适合与函数vector<Point2f>
()使用?
In the first case OpenCV will perform implicitly a calcOpticalFlowPyrLK()
inside the function estimateRigidTransform()
. 在第一种情况下,OpenCV将在函数
estimateRigidTransform()
隐式执行calcOpticalFlowPyrLK()
estimateRigidTransform()
。 See the implementation in lkpyramid.cpp @ line 1383 . 请参见lkpyramid.cpp @ 1383行中的实现。
This is the only difference between the two methods. 这是两种方法之间的唯一区别。 If finding correspondences between
frame1
and frame2
matters then use version #2 otherwise #1. 如果发现
frame1
和frame2
之间的对应关系很重要,则使用版本#2,否则使用版本1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.