Importing an Image & Viewing it

import cv2

image = cv2.imread("./Path/To/Image.extension")

cv2.imshow("Image", image)

cv2.waitKey(0)

cv2.destroyAllWindows()

Warning 1: On reading images this way via openCV, it isn’t in RGB colorspace—it’s in BGR. Sometime this won’t be an issue with you, you’ll only have trouble if you want to add something colored to your image.

There are two solutions:

Switch the R — 1st one(red) with the B — 3rd one(blue), so that Red is (0,0,255) instead of (255,0,0). Change the colorspace to RGB:

rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

and go on with your code with rgb_image instead of image .

Warning 2: To close the window that’s displaying the image, press any button. If you use the close button it may cause freezes (happens to me when I’m on a Jupyter notebook).

For simplicity, throughout this tutorial I’ll be using this method to view images: