#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int g_angle = 45;
int g_MaxAngle = 360;
Mat img;
void Tracker(int pos, void *)
{
double angle = g_angle;
double a = 3.1415926 * angle / 180;
double array[] =//旋转矩阵格式
{
cos(a), -sin(a), 0,
sin(a), cos(a), 1,
0, 0, 1
};
double dis = sqrt(img.cols*img.cols + img.rows*img.rows) / 2;
double orgin = atan2(img.rows / 2, img.cols / 2);
double dx = dis - cos(a + orgin)*dis;
double dy = dis - sin(a + orgin)*dis;
Mat trans = Mat::eye(3, 3, CV_64FC1);//平移矩阵
trans.at<double>(0, 2) = dx;
trans.at<double>(1, 2) = dy;
Mat Rotation = Mat(3, 3, CV_64FC1, array);//旋转矩阵
//因为是先旋转后平移 P=HQ H=TR这样的格式
Rotation = trans*Rotation;
Size ImgSize = Size(sqrt(img.cols*img.cols + img.rows*img.rows), sqrt(img.cols*img.cols + img.rows*img.rows));
Mat Result;
warpPerspective(img, Result, Rotation, ImgSize, INTER_LINEAR);
string tile = "angle";
imshow(tile,Result);
waitKey(0);
return;
}
int main()
{
string filename = "C:/Users/Administrator/Desktop/标准测试图片/Fig0638(a)(lenna_RGB).tif";
img = imread(filename, IMREAD_COLOR);
string tile = "angle";
namedWindow(tile);
if (img.empty())
{
return -1;
}
createTrackbar("Angle", tile, &g_angle, g_MaxAngle, Tracker);
Tracker(0, NULL);
return 0;
}
旋转矩阵,旋转影像
最新推荐文章于 2024-01-13 22:22:17 发布