放射变换都可以表示为乘以一个矩阵再加上一个向量的形式:
可以做三种动作:
1.旋转 (线性变换)
2.平移(向量加)
3.缩放(线性变换)
放射变换函数:getAffineTransform()对应关系是三个点,得到对应关系后,最终归于warpAffine
二维旋转变换矩阵:getRotationMatrix2D()对应关系是中心点,旋转角度和缩放倍数,得到对应关系后,最终归于warpAffine
其他小知识:point2D32f表示两通道,每个通道由32位单通道浮点数组成。
int main()
{
Point2f srcTri[3];
Point2f dstTri[3];
Mat warpMat;
Mat src,dst1,dst2;
src=imread("cui.jpg");
dst1.create(src.size(),src.type());
dst2.create(src.size(),src.type());
srcTri[0]=Point2f(0,0);
srcTri[1]=Point2f(0,saturate_cast<float>(src.rows-1));
srcTri[2]=Point2f(saturate_cast<float>(src.cols-1),0);
dstTri[0]=Point2f(0,saturate_cast<float>(src.rows*0.2));
dstTri[1]=Point2f(saturate_cast<float>(src.cols*0.6),saturate_cast<float>(src.rows*0.5));
dstTri[2]=Point2f(saturate_cast<float>(src.cols*0.8),saturate_cast<float>(src.rows*0.9));
warpMat=getAffineTransform(srcTri,dstTri);
warpAffine(src,dst1,warpMat,dst1.size());
imshow("a",dst1);
Point center=Point(src.cols/2,src.rows/2);
double angle=30.0;
double scale=0.5;
Mat roMat=getRotationMatrix2D(center,angle,scale);
warpAffine(src,dst2,roMat,dst2.size());
imshow("b",dst2);
waitKey(0);
}