Flipping (mirroring) and rotating images

You can use the flip function to flip or mirror an image. This function can be used to flip an image around the x or y axes, or both, depending on the provided flip code. Here's how this function is used:

int code = +1; 
flip(image, result, code);

If code is zero, the input image will be flipped/mirrored vertically (around the x axis), if code is a positive value, the input image will be flipped/mirrored horizontally (around the y axis), and if code is a negative value, the input image will be flipped/mirrored around both the x and y axes at the same time.

On the other hand, to rotate an image, you can use the rotate function. What you need to take care of, when calling the rotate function, is providing a correct rotation flag, as seen in the following example:

RotateFlags rt = ROTATE_90_CLOCKWISE; 
rotate(image, result, rt); 

The RotateFlag enum can be one of the following self-explanatory constant values:

  • ROTATE_90_CLOCKWISE
  • ROTATE_180
  • ROTATE_90_COUNTERCLOCKWISE

Here's an image that depicts all possible results of the flip and rotate functions. Notice that the result of flip around both axes is the same as a 180-degree rotation in the following resulting images:

As mentioned previously in this chapter, Mat::t, or the transpose of a matrix, can also be used to rotate an image when used in conjunction with the flip function.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.162.37