I’m having troubles with rotation. What I want to do is this:
I had the same problem.
For a transform M
and point pp
in the rotated image, we wish to find the point pp_org
in the coordanates of the original image. Use the following lines:
cv::Mat_ iM;
cv::invertAffineTransform(M, iM);
cv::Point2f pp_org = iM*pp;
Where the operator * in the above line is defined as:
cv::Point2f operator*(cv::Mat_ M, const cv::Point2f& p)
{
cv::Mat_ src(3/*rows*/,1 /* cols */);
src(0,0)=p.x;
src(1,0)=p.y;
src(2,0)=1.0;
cv::Mat_ dst = M*src; //USE MATRIX ALGEBRA
return cv::Point2f(dst(0,0),dst(1,0));
}
Note: M
is the rotation matrix you used to go from the original to the rotated image