//2020.6.21P72_OpenCV_图像平移_缩放_旋转
//2020.6.21P72_OpenCV_图像平移_缩放_旋转
//#include
//#include
//txwtech
#include
#include
#include
using namespace cv;
int main(int argc, char *argv[])
{
//Mat I = imread(argv[1],CV_LOAD_IMAGE_GRAYSCALE);
//Mat I = imread(argv[1], CV_LOAD_IMAGE_COLOR);
Mat I = imread("yezi.png");
//图片放在cpp的相同目录。 比如cvp71.cpp, yezi.png放在同一个文件夹
if (!I.data) //no data ,return to -1;
return -1;
//缩放仿射矩阵,等比例缩放2倍
Mat s = (Mat_(2,3)<<0.5, 0, 0,
0, 0.5, 0);
//x平移80,y不移动仿射矩阵
Mat s5 = (Mat_(2,3)<<1, 0, 180,
0, 1, 0);
//x平移80,y移动100仿射矩阵
/*Mat s2 = (Mat_(2, 3) << 1, 0, 80,
0, 1, 100);*/
//缩放+平移仿射矩阵
Mat s2 = (Mat_(2, 3) << 0.5, 0, 80,
0, 0.5, 80);
Mat s3 = getRotationMatrix2D(Point2f(280,280),-90,0.5);//顺时针旋转90度,缩小2倍
Mat dst1a, dst1b;
Mat dst1,dst3;
//插值算法
warpAffine(I,dst1,s,Size(I.cols/2,I.rows/2));//图像缩放
warpAffine(I, dst3,s3,Size(I.cols,I.rows));//顺时针旋转90度,缩小2倍
warpAffine(I, dst1b, s2, Size(I.cols, I.rows));//缩放+平移
warpAffine(I, dst1a, s5, Size(I.cols, I.rows));//平移
Mat dst2;
resize(I,dst2,Size(I.cols/2,I.rows/2),0.5,0.5);//openCV缩放函数
imshow("原图像I",I);
imshow("平移",dst1a);
imshow("缩放+平移", dst1b);
//imshow("warAffine仿射方式",dst1);
//imshow("resize方式",dst2);
imshow("缩放+旋转90度",dst3);
Mat img2,Rimg3;
img2 = I.clone();
//imshow("复制图像",img2);
waitKey(0);
return 0;
}