I'm having trouble getting an image to rotate in some code I'm working on. This is the problem I'm having:
1. I have a source image. It has a size (w, h) which is not necessarily square.
2. It is going to be rotated by angle a.
3. I've calculated the output size required to fit an image of size (w, h) rotated by angle a using a bit 'o trig. This size is (dw, dh), and I can verify on paper it is being computed correctly.
I cannot get ippiRotate to center the rotated image in the destination image. It's always off center.
My best guess for what xShift and yShift should be is the following:
xShift = (dw / 2.0) - (w / 2.0)
yShift = (dh / 2.0) - (h / 2.0)
But this doesn't work, and I'm not sure what else to do to calculate xShift and yShift.I've attempted to use ippiGetRotateShift to calculate xShift and yShift, again, to no avail.
I originally tried this, thinking that it would center my rotated image in the destination image:
ippiGetRotateShift(dw / 2.0, dh / 2.0, a, &xShift, &yShift);
But it doesn't it's very much off center. If I do this:
ippiGetRotateShift(w / 2.0, h / 2.0, a, &xShift, &yShift);
It's not as off center, but it's still off.
I'm at the end of my rope here, I need to get this working ASAP, I'd really appreciate any help I can get.
Thanks, but the samples aren't much of a help in this case - I've scoured over them, but none of them that deal with rotation appear to be doing what I'm looking for - rotating aninput bufferaround it's center, and centering that rotated image in a destination buffer that is sized to fit the rotated input. That seems to be impossible to get right. I'm surprised that such a simple sounding task is so difficult to do with either IPL or IPP.
Please don't let the trouble get the better of you. It is not that difficult with IPP, you are almost there, this works for me:
int xOffset = (dw-w)/2;
int yOffset = (dh-h)/2;
ippiGetRotateShift(w/2, h/2, a, &xShift, &yShift);
if ( xOffset > 0 )
xShift += xOffset;
if ( yOffset > 0 )
yShift += yOffset;
and call ippiRotate.