#include <opencv/cv.h> #include <opencv/highgui.h> IplImage *rotateImage(const IplImage *src, int angleDegrees) { IplImage *imageRotated = cvCloneImage(src); if (angleDegrees != 0){ CvMat* rot_mat = cvCreateMat(2, 3, CV_32FC1); CvPoint2D32f center = cvPoint2D32f(cvGetSize(imageRotated).width / 2, cvGetSize(imageRotated).height / 2); cv2DRotationMatrix(center, angleDegrees, 1, rot_mat); cvWarpAffine(src, imageRotated, rot_mat); } return imageRotated; } int main() { IplImage* img; IplImage* rotated_img; int angle = 0; img = cvLoadImage("6013202130.jpg"); rotated_img = rotateImage(img, 223); cvNamedWindow("选做-图片旋转", CV_WINDOW_AUTOSIZE); cvNamedWindow("原图", CV_WINDOW_AUTOSIZE); cvShowImage("原图", img); cvShowImage("选做-图片旋转", rotated_img); cvWaitKey(0);//等待按键 cvDestroyWindow("原图"); cvDestroyWindow("选做-图片旋转"); cvReleaseImage(&img); cvReleaseImage(&rotated_img); return 0; }