views:

761

answers:

5

I need code for rotating an image in C++ which functions like imrotate function of matlab. Please suggest a good link. Or if someone can provide the code for imrotate.

Or at least please explain the algorithm.

Its not a homework. I need this code for my project. And we can use any external library or code.

+1  A: 

Check this hope it helps .

Other questions on stack overflow on the same topic experts opinion on it.

YetAnotherCoder
+2  A: 

Magick can help you. Read this PDF and search for rotate.

Aviator
Imagemagick, best option for you
Craig
A: 

There is no built-in way of accomplishing this in C++, short of writing your own function for manipulating binary data, which yields other problems like "How do I decompress a jpg/png in C++?"

Your best bet is a 3rd party graphics library such as libSDL

meagar
The question is a perfectly valid way to ask for a library that's linkable from C++.
slim
... I believe I linked him to a linkable library?
meagar
+2  A: 

OpenCV2.0 has several computer vision and image processing tools. Specifically warpAffine (by defining the rotation matrix) will solve your problem with rotating an image.

The 2x3 transformation matrix mentioned in the documentation is as follows: alt text

where θ is the angle of rotation and tx and ty is the translation along the x and y axes respectively.

You can get the source code here.

Also, OpenCV2.0 has many MATLAB-esque functions like imread, etc.

Jacob
(+1)My friend uses this lib and loves it Look here http://ashish-newday.blogspot.com/2009/12/mouse-cursor-position-control-using-our.html
TheMachineCharmer
But there is no image warpImage in openCV
avd
My bad, I updated it to the correct function `warpAffine`
Jacob
How should I define rotation matrix?
avd
OpenCV asks for a 2x3 transformation matrix which I've included in my answer
Jacob
Cool!! Thanks for the answer, BTY I also got this useful link:http://www.discover.uottawa.ca/~qchen/my_presentations/A%20Basic%20Introduction%20to%20OpenCV%20for%20Image%20Processing.pdf
avd
Yes, that seems like a nice tutorial but it explains OpenCV with the old `IplImage*`. Don't forget to start using OpenCV2.0's new `Mat` class - it makes your code *much* cleaner!
Jacob
A: 

libgd has image rotation functions.

Convict