prefacio
Este artículo describe principalmente la aplicación de la transformación afín en opencv.
1. Transformación afín
//第二题 仿射变换 旋转缩放(定义旋转度数和缩放大小)
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
cv::Mat dstMat;
cv::Mat srcMat = imread("C://Users//john//Desktop//1.jpg",1);
if (srcMat.empty()) return -1;
//旋转-40°,缩放尺度为1
float angle = -10.0, scale = 0.8;
//旋转中心为图像中心
cv::Point2f center(srcMat.cols*0.5,srcMat.rows*0.5);
//获得变换矩阵
const cv::Mat affine_matrix = cv::getRotationMatrix2D(center, angle, scale);
cv::warpAffine(srcMat, dstMat, affine_matrix, srcMat.size());
cv::imshow("src", srcMat);
cv::imshow("dst", dstMat);
cv::waitKey(0);
}
Resumir
1. El código se puede ejecutar directamente, si no lo entiende, deje un mensaje.