旋转矩阵,旋转影像

#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;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值