毛星云Opencv之7.4仿射变换函数warpAffine()和二维旋转变换矩阵函数getRotationMatrix2D()及其实现

#include 
#include
#include"opencv2/highgui/highgui.hpp"
#include
#include
#include
#include
using namespace std;
using namespace cv;

#define WINDOW_NAME1 "[原始图窗口]"
#define WINOW_NAME2 "[经过Warp后的图像]"
#define WINDOW_NAME3 "[经过Warp和Rotate后的图像"


int main()
{
	Point2f srcTriangle[3];
	Point2f dstTriangle[3];
	
	Mat roMat(2, 3, CV_32FC1);
	Mat warpMat(2, 3, CV_32FC1);
	Mat srcImage, dstImage_warp, dstImage_warp_rotate;


	srcImage = imread("C:/Users/离子键/source/repos/Project8/1.jpg",1);
	dstImage_warp = Mat::zeros(srcImage.rows, srcImage.cols, srcImage.type());

	srcTriangle[0] = Point2f(0, 0);
	srcTriangle[1] = Point2f(static_cast(srcImage.cols - 1), 0);
	srcTriangle[2] = Point2f(0,static_cast(srcImage.rows - 1));

	dstTriangle[0] = Point2f(static_cast(srcImage.cols * 0.0), static_cast(srcImage.rows * 0.33));
	dstTriangle[1] = Point2f(static_cast(srcImage.cols * 0.65), static_cast(srcImage.rows * 0.35));
	dstTriangle[2] = Point2f(static_cast(srcImage.cols * 0.15), static_cast(srcImage.rows * 0.6));
	
	warpMat = getAffineTransform(srcTriangle, dstTriangle);
	warpAffine(srcImage, dstImage_warp, warpMat, dstImage_warp.size());

	Point center = Point(dstImage_warp.cols / 2, dstImage_warp.rows / 2);
	double angle = -30.0;
	double scale = 0.8;
	roMat = getRotationMatrix2D(center, angle, scale);
	warpAffine(dstImage_warp, dstImage_warp_rotate, roMat, dstImage_warp.size());

	imshow(WINDOW_NAME1, srcImage);

	imshow(WINOW_NAME2, dstImage_warp);
	
	
	imshow(WINDOW_NAME3,dstImage_warp_rotate);
	
	waitKey(0);
	return 0;
}




运行结果如图:

毛星云Opencv之7.4仿射变换函数warpAffine()和二维旋转变换矩阵函数getRotationMatrix2D()及其实现_第1张图片

 原版介绍:
毛星云Opencv之7.4仿射变换函数warpAffine()和二维旋转变换矩阵函数getRotationMatrix2D()及其实现_第2张图片

 毛星云Opencv之7.4仿射变换函数warpAffine()和二维旋转变换矩阵函数getRotationMatrix2D()及其实现_第3张图片

 毛星云Opencv之7.4仿射变换函数warpAffine()和二维旋转变换矩阵函数getRotationMatrix2D()及其实现_第4张图片

 毛星云Opencv之7.4仿射变换函数warpAffine()和二维旋转变换矩阵函数getRotationMatrix2D()及其实现_第5张图片

 毛星云Opencv之7.4仿射变换函数warpAffine()和二维旋转变换矩阵函数getRotationMatrix2D()及其实现_第6张图片

 毛星云Opencv之7.4仿射变换函数warpAffine()和二维旋转变换矩阵函数getRotationMatrix2D()及其实现_第7张图片

 毛星云Opencv之7.4仿射变换函数warpAffine()和二维旋转变换矩阵函数getRotationMatrix2D()及其实现_第8张图片

 毛星云Opencv之7.4仿射变换函数warpAffine()和二维旋转变换矩阵函数getRotationMatrix2D()及其实现_第9张图片

 毛星云Opencv之7.4仿射变换函数warpAffine()和二维旋转变换矩阵函数getRotationMatrix2D()及其实现_第10张图片

 毛星云Opencv之7.4仿射变换函数warpAffine()和二维旋转变换矩阵函数getRotationMatrix2D()及其实现_第11张图片

 

你可能感兴趣的:(opencv,计算机视觉,c++)