OpenCV:图像几何变换_平移,旋转,缩放

1.平移

创建转换矩阵M=[1,0,tx;0,1,ty]

warpAffine(输入,输出,转换矩阵,输出图像大小,...)
    Mat image = imread("C:/Users/YY/Pictures/Saved Pictures/1.jpg");
	Mat out;
	Mat M = (Mat_(2, 3) << 1, 0, 40, 0, 1, 40);
	warpAffine(image, out, M, image.size());
	imshow("显示", out);

2.旋转

getRotationMatrix2D(旋转中心:Point((rows - 1) / 2, (cols - 1) / 2), 旋转角度, scale);
#include
#include
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
	Mat image = imread("C:/Users/YY/Pictures/Saved Pictures/1.jpg");
	Mat out;
	imshow("原图", image);
	int rows = image.rows;
	int cols = image.cols;
	Mat M = getRotationMatrix2D(Point((cols - 1) / 2, (rows - 1) / 2), 90, 1);
	warpAffine(image, out, M, image.size());
	imshow("显示", out);
	waitKey(0);
	destroyAllWindows();
	return 0;
}

3.缩放

resize(image, out, Size(), fx, fy, INTER_LINEAR);

你可能感兴趣的:(OpenCV图像处理)