As known, we can pass to the function estimateRigidTransform()
two parameters with one of two types: Mat estimateRigidTransform(InputArray src, InputArray dst, bool fullAffine)
cv::Mat frame1, frame2;
std::vector<cv::Point2f> frame1_features, frame2_features;
I.e., for example, to implement video-stabilization (shake remove) we can use one of two approach:
cv::Mat
: video stabilization using opencvcv::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;
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?
I.e. which of types Mat
or vector<Point2f>
is better to use with function estimateRigidTransform()?
In the first case OpenCV will perform implicitly a calcOpticalFlowPyrLK()
inside the function estimateRigidTransform()
. See the implementation in lkpyramid.cpp @ line 1383.
This is the only difference between the two methods. If finding correspondences between frame1
and frame2
matters then use version #2 otherwise #1.