Loading, displaying, and saving images
This section presents how to work on images by means of OpenCV-Python. Furthermore, we discuss how to load, display, and save 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:
![](https://static.packt-cdn.com/products/9781788629874/graphics/6e9147e9-fff6-43e9-b356-d182d4e67dc8.png)
- The result obtained after executing
Load_Display_Save.py
is shown here:
![](https://static.packt-cdn.com/products/9781788629874/graphics/dc161ddb-d9ce-4340-a31e-18988b8f9a96.png)