OpenCV-Python — is a Python bindings library for solving computer vision problems.
cv2.imread () loads an image from the specified file. If the image cannot be read (due to a missing file, incorrect permissions, unsupported or incorrect format) then this method returns an empty matrix.
Syntax: cv2. imread (path, flag)
path: A string representing the path of the image to be read.
flag: It specifies the way in which image should be read. It’s default value is cv2.IMREAD_COLOR
Return Value: This method returns an image that is loaded from the specified file.
Note . The image must be in the working directory or the full path to the image must be specified.
All three types of flags are described below:
cv2.IMREAD_COLOR: It specifies to load a color image. Any transparency of image will be neglected. It is the default flag. Alternatively, we can pass integer value 1 for this flag.
cv2.IMREAD_GRAYSCALE: It specifies to load an image in grayscale mode. Alternatively, we can pass integer value 0 for this flag.
cv2.IMREAD_UNCHANGED: It specifies to load an image as such including alpha channel. Alternatively, we can pass integer value -1 for this flag.
Image is used for all examples below:
Example # 1: Using the default flag
Example # 2:
Loading an image in grayscale