根据指定的3对点,确定仿射变换,并据此,对vSrc里的点进行仿射。
void AffineTransformPoints(const vector<Point2f> &vFixedSrc,const vector<Point2f> &vFixedDst,const vector<Point2f> &vSrc,vector<Point2f> &vDst)
{
Mat map_matrix = getAffineTransform(vFixedSrc,vFixedDst);
map_matrix.convertTo(map_matrix,CV_32F);
for (int i=0;i<vSrc.size();i++)
{
Point2f pt;
Mat dp(2,1,CV_32F);
Mat sp(3,1,CV_32F);
sp.at<float>(0,0) = vSrc[i].x;
sp.at<float>(1,0) = vSrc[i].y;
sp.at<float>(2,0) = 1;
dp = map_matrix*sp;
pt.x = dp.at<float>(0,0);
pt.y = dp.at<float>(1,0);
vDst.push_back(pt);
}
}