#include"cv.h"#include"highgui.h"
#include"iostream"
using namespace cv;using namespace std;
int main()
{
Mat image=imread("mini.jpg");
if(image.empty())
{
cout<<"read file failure"<<endl;
return -1;
}
Point2f center=Point2f(image.cols/2,image.rows/2);//旋转中心
double angle=30;//旋转角度
double scale=1;//缩放尺度
double degree=angle*CV_PI/180;
double a=sin(degree),b=cos(degree);
Mat image_rotate;
image_rotate.cols= (image.cols*fabs(b)+image.rows*fabs(a));
image_rotate.rows=(image.cols*fabs(a)+image.rows*fabs(b));
// Point2f center=Point2f(image_rotate.cols/2,image_rotate.rows/2);//也不能把图像移到中间
// float map[6];
Mat rotateMat(2,3,CV_32FC1,map);
rotateMat=getRotationMatrix2D(center,angle,scale);
// map[2]+=(image_rotate.cols-image.cols)/2;
//map[5]+=(image_rotate.rows-image.rows)/2;
Mat rotateImage;
warpAffine(image,rotateImage,rotateMat,image_rotate.size());
imwrite("rotate_image.jpg",rotateImage);
namedWindow("window",1);
imshow("window",rotateImage);
waitKey(0);
return 0;
}
//#include"iostream"
//#include"cv.h"
//#include"highgui.h"
//using namespace cv;//using namespace std;
//int main()//{
//Point2f scrTri[3];
//Point2f dsttri[3];
//Mat warp_mat(2,3,CV_32FC1);
//Mat rot_mat(2,3,CV_32FC1);
//Mat scr,warp_dst,warp_rotate_dst;
//scr=imread("lena.jpg");
//warp_dst=Mat::zeros(scr.type(),scr.cols,scr.rows);//重置为0
//}
开心每一天1111