How to do it...

  1. Import the Computer Vision package - cv2:
import cv2 
  1. Read the image using the built-in imread function:
image = cv2.imread('image_2.jpg')
  1. Display the original image using the built-in imshow function:
cv2.imshow("Original", image) 
  1. Wait until any key is pressed:
cv2.waitKey(0) 
  1. Perform the required operation on the test image:
# cv2.flip is used to flip images 
# Horizontal flipping of images using value '1' 
flipping = cv2.flip(image, 1) 
  1. Display the horizontally flipped image:
# Display horizontally flipped image 
cv2.imshow("Horizontal Flipping", flipping) 
  1. Wait until any key is pressed:
cv2.waitKey(0) 
  1. Perform vertical flipping of input image:
# Vertical flipping of images using value '0' 
flipping = cv2.flip(image, 0) 
  1. Display the vertically flipped image:
cv2.imshow("Vertical Flipping", flipping) 
  1. Wait until any key is pressed:
cv2.waitKey(0) 
  1. Display the processed image:
# Horizontal & Vertical flipping of images using value '-1' 
flipping = cv2.flip(image, -1) 
# Display horizontally & vertically flipped image 
cv2.imshow("Horizontal & Vertical Flipping", flipping) 
# Wait until any key is pressed 
cv2.waitKey(0)
  1. Stop the execution and display the result:
# Close all windows 
cv2.destroyAllWindows() 
  1. The command used to execute the Flipping.py Python program is shown here:
  1. The original and horizontally flipped images obtained after executing Flipping.py are shown here:

Following is the horizontally flipped picture:

  1. Vertically, and horizontally and vertically, flipped images obtained after executing Flipping.py are shown here:

Following horizontally and vertically flipped picture: