#include <stdio.h>
 #include "opencv2/core/core.hpp"
 #include "opencv2/features2d/features2d.hpp"
 #include "opencv2/highgui/highgui.hpp"
 #include "opencv2/nonfree/nonfree.hpp"
 #ifndef _DEBUG
 #pragma  comment(lib,"IlmImf.lib")   
 #pragma  comment(lib,"libjasper.lib")    
 #pragma  comment(lib,"libjpeg.lib")   
 #pragma  comment(lib,"libpng.lib")       
 #pragma  comment(lib,"libtiff.lib")  
 #pragma  comment(lib,"zlib.lib")   
 #pragma  comment(lib,"opencv_calib3d2411.lib")
 #pragma  comment(lib,"opencv_contrib2411.lib")
 #pragma  comment(lib,"opencv_core2411.lib")
 #pragma  comment(lib,"opencv_features2d2411.lib")
 #pragma  comment(lib,"opencv_flann2411.lib")
 #pragma  comment(lib,"opencv_gpu2411.lib")
 #pragma  comment(lib,"opencv_highgui2411.lib")
 #pragma  comment(lib,"opencv_imgproc2411.lib")
 #pragma  comment(lib,"opencv_legacy2411.lib")
 #pragma  comment(lib,"opencv_ml2411.lib")
 #pragma  comment(lib,"opencv_nonfree2411.lib")
 #pragma  comment(lib,"opencv_objdetect2411.lib")
 #pragma  comment(lib,"opencv_ocl2411.lib")
 #pragma  comment(lib,"opencv_photo2411.lib")
 #pragma  comment(lib,"opencv_stitching2411.lib")
 #pragma  comment(lib,"opencv_superres2411.lib")
 #pragma  comment(lib,"opencv_ts2411.lib")
 #pragma  comment(lib,"opencv_video2411.lib")
 #pragma  comment(lib,"opencv_videostab2411.lib")
 #else
 #pragma  comment(lib,"zlibd.lib")
 #pragma  comment(lib,"IlmImfd.lib")
 #pragma  comment(lib,"libjasperd.lib")
 #pragma  comment(lib,"libjpegd.lib")
 #pragma  comment(lib,"libpngd.lib")
 #pragma  comment(lib,"libtiffd.lib")
 #pragma  comment(lib,"opencv_calib3d2411d.lib")
 #pragma  comment(lib,"opencv_contrib2411d.lib")
 #pragma  comment(lib,"opencv_core2411d.lib")
 #pragma  comment(lib,"opencv_features2d2411d.lib")
 #pragma  comment(lib,"opencv_flann2411d.lib")
 #pragma  comment(lib,"opencv_gpu2411d.lib")
 #pragma  comment(lib,"opencv_highgui2411d.lib")
 #pragma  comment(lib,"opencv_imgproc2411d.lib")
 #pragma  comment(lib,"opencv_legacy2411d.lib")
 #pragma  comment(lib,"opencv_ml2411d.lib")
 #pragma  comment(lib,"opencv_nonfree2411d.lib")
 #pragma  comment(lib,"opencv_objdetect2411d.lib")
 #pragma  comment(lib,"opencv_ocl2411d.lib")
 #pragma  comment(lib,"opencv_photo2411d.lib")
 #pragma  comment(lib,"opencv_stitching2411d.lib")
 #pragma  comment(lib,"opencv_superres2411d.lib")
 #pragma  comment(lib,"opencv_ts2411d.lib")
 #pragma  comment(lib,"opencv_video2411d.lib")
 #pragma  comment(lib,"opencv_videostab2411d.lib")
 #endif using namespace cv;
#include <opencv/highgui.h>  
 #include <opencv/cv.h>  int main(int argc, char** argv)  
 {  
  CvPoint2D32f srcTri[3], dstTri[3]; //二维坐标下的点,类型为浮点  
  CvMat* rot_mat = cvCreateMat( 2, 3, CV_32FC1 );  //多通道矩阵  
  CvMat* warp_mat = cvCreateMat( 2, 3, CV_32FC1 );  
  IplImage *src, *dst;  
  
  if( argc == 2 && ( ( src = cvLoadImage( argv[1], 1 ) ) != 0 ) )  
  {  
      dst = cvCloneImage( src );  //制作图像的完整拷贝  
      dst ->origin = src ->origin;    
      /* 
   int origin; /* 0 - 顶—左结构, 
   1 - 底—左结构 (Windows bitmaps 风格)  
   */  
   cvZero( dst );  //清空数组  
   
   //计算矩阵仿射变换  
   srcTri[0].x = 0;  
   srcTri[0].y = 0;  
   srcTri[1].x = src -> width - 1;  //缩小一个像素  
   srcTri[1].y = 0;  
   srcTri[2].x = 0;  
   srcTri[2].y = src -> height - 1;  
   
   //改变目标图像大小  
   dstTri[0].x = src -> width * 0.0;  
   dstTri[0].y = src -> height * 0.33;  
   dstTri[1].x = src -> width * 0.85;  
   dstTri[1].y = src -> height * 0.25;  
   dstTri[2].x = src -> width * 0.15;  
   dstTri[2].y = src -> height * 0.7;  
   cvGetAffineTransform( srcTri, dstTri, warp_mat );  //由三对点计算仿射变换   
   cvWarpAffine( src, dst, warp_mat );  //对图像做仿射变换  
   //输出  
   cvNamedWindow( "Affine_Transform1", 1 );  
   cvShowImage( "Affine_Transform1", dst );  //最终是输出dst   
   cvWaitKey();   //cvCopy( dst, src );  //将dst拷贝给src  
   
   //计算旋转仿射变换  
   CvPoint2D32f center = cvPoint2D32f( src -> width / 2, src -> height / 2 );  
   double angle =30.0;// -50.0; //旋转角度,负值表示顺时针  
   double scale = 0.9;//0.6;  //各项同性的尺度因子   
   cv2DRotationMatrix( center, angle, scale, rot_mat );  
   cvWarpAffine( src, dst, rot_mat );  //将src仿射变换存入dst  
   
   //输出  
   cvNamedWindow( "Affine_Transform2", 1 );  
   cvShowImage( "Affine_Transform2", dst );  //最终是输出dst   
   cvWaitKey();  
  }  
  cvReleaseImage( &dst );  
  cvReleaseMat( &rot_mat );  
  cvReleaseMat( &warp_mat );  
  return 0;  
 }