6

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.

avd
  • 13,993
  • 32
  • 78
  • 99

5 Answers5

8

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
  • 34,255
  • 14
  • 110
  • 165
  • 1
    (+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 – Pratik Deoghare Feb 17 '10 at 05:03
  • 1
    But there is no image warpImage in openCV – avd Feb 17 '10 at 05:06
  • How should I define rotation matrix? – avd Feb 17 '10 at 05:13
  • OpenCV asks for a 2x3 transformation matrix which I've included in my answer – Jacob Feb 17 '10 at 05:27
  • 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 Feb 17 '10 at 05:57
  • 1
    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 Feb 17 '10 at 06:21
  • The code for OpenCV is now in Git: git://code.opencv.org/opencv.git – wanovak Nov 06 '12 at 22:49
3

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

vpram86
  • 5,860
  • 4
  • 28
  • 40
1

Check this hope it helps .

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

Community
  • 1
  • 1
Srinivas M.V.
  • 6,508
  • 5
  • 33
  • 49
0

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

user229044
  • 232,980
  • 40
  • 330
  • 338
0

libgd has image rotation functions.

Convict
  • 506
  • 2
  • 4