Skip vector <Point2f> for getAffineTransform
I am trying to calculate the affine transformation between two consecutive frames from a video. So I found the functions and got consistent points in two frames.
FastFeatureDetector detector;
vector<Keypoints> frame1_features;
vector<Keypoints> frame2_features;
detector.detect(frame1 , frame1_features , Mat());
detector.detect(frame2 , frame2_features , Mat());
vector<Point2f> features1; //matched points in 1st image
vector<Point2f> features2; //matched points in 2nd image
for(int i = 0;i<frame2_features.size() && i<frame1_features.size();++i )
{
double diff;
diff = pow((frame1.at<uchar>(frame1_features[i].pt) - frame2.at<uchar>(frame2_features[i].pt)) , 2);
if(diff<SSD) //SSD is sum of squared differences between two image regions
{
feature1.push_back(frame1_features[i].pt);
feature2.push_back(frame2_features[i].pt);
}
}
Mat affine = getAffineTransform(features1 , features2);
The last line displays the following error:
OpenCV Error: Assertion failed (src.checkVector(2, CV_32F) == 3 && dst.checkVector(2, CV_32F) == 3) in getAffineTransform
Can someone tell me how to calculate an affine transformation with a set of matching points between two frames?
+4
2 answers
, 3 .
, ( ).findHomography() - (http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#findhomography).
, , .
, - , .
, (, , ), .
, findHomography(features1 , features2, CV_RANSAC) getAffineTransform(features1 , features2).
, .
+3
, - .
int checkVector(int elemChannels,int depth) //
N, 1- (N x ptdim) ptdim- (1 x N) (N x 1); .
; http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#getaffinetransform: .
, , .
+2