I needed a way to rotate images so made this…
void ofCvGrayscaleImage::rotate(float angle){
rotate(angle, width/2, height/2);
}
void ofCvGrayscaleImage::rotate(float angle, float centreX, float centreY){
CvPoint2D32f centre;
CvMat *translate = cvCreateMat(2, 3, CV_32FC1);
cvSetZero(translate);
centre.x = centreX;
centre.y = centreY;
cv2DRotationMatrix(centre, angle, 1.0, translate);
cvWarpAffine(cvImage, cvImageTemp, translate, CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS, cvScalarAll(0));
cvReleaseMat(&translate);
swapTemp();
}
usage:
grayImage.rotate(10); // around image centre axis
or
grayImage.rotate(10, 300, 200); // set x & y axis for rotation
Do you have any idea why the image seems to get more and more blurred the more it is rotated?
Just to clarify, this isn’t to rotate an image when displaying, but rotating an image within itself. You will get blank areas inside the image once you rotate, and if you rotate all the way around the image will become a circle region with a black space around it.
Thanks