This section presents how to work on images by means of OpenCV-Python. Furthermore, we discuss how to load, display, and save images.
Loading, displaying, and saving images
How to do it...
- Import the Computer Vision package - cv2:
import cv2
- Read the image using the built-in imread function:
image = cv2.imread('image_1.jpg')
- Display the original image using the built-in imshow function:
cv2.imshow("Original", image)
- Wait until any key is pressed:
cv2.waitKey(0)
- Save the image using the built-in imwrite function:
cv2.imwrite("Saved Image.jpg", image)
- The command used to execute the Python program Load_Display_Save.py is shown here:
- The result obtained after executing Load_Display_Save...