1 | initial version |
since you already know the angle, you could easily use getRotationMatrix2D:
double angle = 31.0;
double scale = 1.0;
Point2f center(img.cols/2, img.rows/2);
Mat M = getRotationMatrix2D(center, angle, scale);
if you want to derive it from (at least 3) pairs of Points via getAffineTransform, use vector<Point2f>
, which can be casted to a cv::Mat:
vector<Point2f> a,b;
a.push_back(keypoints_a[i].pt); // extract the point from the keypoints;
b.push_back(keypoints_b[j].pt);
...
Mat M = getAffineTransform(Mat(a), Mat(b));
finally, rotate it:
Mat rotated;
warpAffine(img, rotated, M, Size());
good luck !
2 | No.2 Revision |
since you already know the angle, you could easily use getRotationMatrix2D:
double angle = 31.0;
double scale = 1.0;
Point2f center(img.cols/2, img.rows/2);
Mat M = getRotationMatrix2D(center, angle, scale);
if you want to derive it from (at least 3) pairs of Points via getAffineTransform, use vector<Point2f>
, which can be casted to a cv::Mat:
vector<Point2f> a,b;
a.push_back(keypoints_a[i].pt); // extract the point from the keypoints;
b.push_back(keypoints_b[j].pt); // you will need **exactly** 3 points in a and 3 points in b
...
Mat M = getAffineTransform(Mat(a), Mat(b));
finally, rotate it:
Mat rotated;
warpAffine(img, rotated, M, Size());
good luck !
3 | No.3 Revision |
since you already know the angle, you could easily use getRotationMatrix2D:
double angle = 31.0;
double scale = 1.0;
Point2f center(img.cols/2, img.rows/2);
Mat M = getRotationMatrix2D(center, angle, scale);
if you want to derive it from (at least (exactly 3) pairs of Points via getAffineTransform, use vector<Point2f>
, which can be casted to a cv::Mat:
vector<Point2f> a,b;
a.push_back(keypoints_a[i].pt); // extract the point from the keypoints;
b.push_back(keypoints_b[j].pt); // you will need **exactly** 3 points in a and 3 points in b
...
Mat M = getAffineTransform(Mat(a), Mat(b));
finally, rotate it:
Mat rotated;
warpAffine(img, rotated, M, Size());
good luck !