rotate.cpp
资源名称:xuanzhuan.rar [点击查看]
上传用户:nsdled
上传日期:2022-08-01
资源大小:1419k
文件大小:1k
源码类别:
图片显示
开发平台:
Visual C++
- #include "cv.h" #include "highgui.h" #include "math.h"
- #include "stdio.h" int main( int argc, char** argv ) { IplImage* src; /* the first command line parameter must be image file name */ if( argc==2 && (src = cvLoadImage(argv[1], -1))!=0) { IplImage* dst = cvCloneImage( src ); int delta = 1; int angle = 330; // 0: 仅仅旋转 double factor; cvNamedWindow( "原图像", 1 ); cvShowImage( "原图像", src ); float m[6]; // Matrix m looks like: // // [ m0 m1 m2 ] ===> [ A11 A12 b1 ] // [ m3 m4 m5 ] [ A21 A22 b2 ] // CvMat M = cvMat( 2, 3, CV_32F, m ); int w = src->width; int h = src->height;
- //旋转 factor = 1;
- m[0] = (float)(factor*cos(-angle*2*CV_PI/180.));
- m[1] = (float)(factor*sin(-angle*2*CV_PI/180.));
- m[3] = -m[1];
- m[4] = m[0];
- // 将旋转中心移至图像中间
- m[2] = w*0.5f;
- m[5] = h*0.5f; // dst(x,y) = A * src(x,y) + b
- cvGetQuadrangleSubPix( src, dst, &M); //cvNamedWindow( "旋转后的图像", 1 ); //cvShowImage( "旋转后的图像", dst );
- //if(!cvSaveImage("旋转后的图像",dst))
- //printf("Could not save:%sn","旋转后的图像");
- cvSaveImage(argv[2],dst);
- // cvWaitKey(0);
- cvReleaseImage(&dst); // angle=(int)angle%360;
- } return 0; }