openCv rotate Image

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);  
	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));  

grayImage.rotate(10); // around image centre axis
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.


great !

about blurring, I think what’s hapeninng is that every time you rotate the image, you are doing some type of interpolation (think of it like a scale). The problem with continuing to rotate internally, is that you will continue to loose data. Id suggest a second function, like

rotateIntoMe(ofCvGrayscaleImage & mom, …)

like warp into me, and then if you continually rotate the original into a new image, you shouldn’t it loose too much detail.

hope that helps! thanks for this code, I’m sure alot of folks will find it useful…

take care,