How to display image in Python using CV2

You can display an image in Python using CV2 by following the given code. I highly recommend you get the “Computer Vision: Models, Learning, and Inference Book” to learn Computer Vision.

How to display image in Python using CV2
How to display image in Python using CV2

Step 1

If OpenCV library is not installed, then first install it using this code.

pip install opencv-python

Step 2

The image should be in the same folder in which the code file is running. Otherwise, add the location before the image name.

# Import the OpenCV library
import cv2

# Read the Image
image = cv2.imread('man.jpg')

# Display the Image
cv2.imshow('man_image',image)
 
# Destroy the Window
cv2.waitKey(0)
cv2.destroyAllWindows()

Output:

Output

Leave a Comment

Your email address will not be published.