In this post I’m sharing a couple of very simple tricks to perform an efficient Rotate or Flip (Mirror) operation on OpenCV Mat images.
Obviously you’ll start by reading an image from disk, or grab it from a video frame and so on, similar to this:
After that depending on the required transformation use any of the following codes.
Flip (Mirror) Vertically
flip(image, image, 0);
Flip (Mirror) Horizontally
flip(image, image, +1);
Rotate 90 Degrees Clockwise
transpose(image, image); flip(image, image, +1);
Rotate 90 Degrees Counter Clockwise (Same as -90 Degrees and 270 Degrees)
transpose(image, image); flip(image, image, 0);
Rotate 180 Degrees (Same as Flipping vertically and horizontally at the same time)
flip(image, image, -1);
Post your comments and questions below.