#include "cv.h"
#include "highgui.h"
#include "math.h"
// clockwise 为true则顺时针旋转,否则为逆时针旋转
IplImage* rotateImage(IplImage* src, int angle, bool clockwise)
{
angle = abs(angle) % 180;
if (angle > 90)
{
angle = 90 - (angle % 90);
}
IplImage* dst = NULL;
int width =
(double)(src->height * sin(angle * CV_PI / 180.0)) +
(double)(src->width * cos(angle * CV_PI / 180.0 )) + 1;
int height =
(double)(src->height * cos(angle * CV_PI / 180.0)) +
(double)(src->width * sin(angle * CV_PI / 180.0 )) + 1;
int tempLength = sqrt((double)src->width * src->width + src->height * src->height) + 10;
int tempX = (tempLength + 1) / 2 - src->width / 2;
int tempY = (te