January 2018
Intermediate to advanced
268 pages
6h 20m
English
OpenCV provides multiple ways of loading an image. Let's say we want to load a color image in grayscale mode, we can do that using the following piece of code:
import cv2gray_img = cv2.imread('images/input.jpg', cv2.IMREAD_GRAYSCALE)cv2.imshow('Grayscale', gray_img)cv2.waitKey()
Here, we are using the ImreadFlag, as cv2.IMREAD_GRAYSCALE, and loading the image in grayscale mode, although you may find more read modes in the official documentation.
You can see the image displayed in the new window. Here is the input image:

Following is the corresponding grayscale image:
We can save this image as a file as well:
Read now
Unlock full access