// 逆时针旋转图像degree角度(原尺寸)
private IplImage rotateImage(IplImage img)
{
/*IplImage img_rotate = IplImage.create(img.width(), img.height(), IPL_DEPTH_8U, 2);
//旋转中心为图像中心
CvPoint2D32f center = new CvPoint2D32f();
center.x(img.width()/2.0f+0.5f);
center.y(img.height()/2.0f+0.5f);
//计算二维旋转的仿射变换矩阵
CvMat cvMat = cvCreateMat(2, 3, CV_32F);
cvZero (img_rotate);
cv2DRotationMatrix( center, degree,1.0, cvMat);*/
//变换图像,并用黑色填充其余值
//cvWarpAffine(img,img_rotate, cvMat,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,cvScalarAll(0) );
IplImage img_rotate = IplImage.create(img.height(),img.width(), IPL_DEPTH_8U, 2);
cvTranspose(img, img_rotate);
cvTranspose(img_rotate, img);
//cvTranspose(img, img_rotate);
cvFlip(img,null,-1);
return img;
}
public static IplImage rotate(IplImage image, double angle) {
IplImage copy = cvCloneImage(image);
IplImage rotatedImage = cvCreateImage(cvGetSize(copy), copy.depth(), copy.nChannels());
//Define Rotational Matrix
CvMat mapMatrix = cvCreateMat(2, 3, CV_32FC1);
//Define Mid Point
CvPoint2D32f centerPoint = new CvPoint2D32f();
centerPoint.x(copy.width() / 2);
centerPoint.y(copy.height() / 2);
//Get Rotational Matrix
cv2DRotationMatrix(centerPoint, angle, 1.0, mapMatrix);
//Rotate the Image
cvWarpAffine(copy, rotatedImage, mapMatrix, CV_INTER_CUBIC + CV_WARP_FILL_OUTLIERS, cvScalarAll(170));
cvReleaseImage(copy);
cvReleaseMat(mapMatrix);
return rotatedImage;
}