OpenCV-Python is a library of Python bindings designed to solve computer vision problems.
cv2.imread() method loads an image from the specified file. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid 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 should be in the working directory or a full path of image should be given.
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 used for all the below examples:
Example #1: Using default flag
Loading an image in grayscale mode
- Python OpenCV | cv2.imshow() method
- Python OpenCV | cv2.circle() method
- Python OpenCV | cv2.arrowedLine() method
- Python OpenCV | cv2.copyMakeBorder() method
- Python OpenCV | cv2.line() method
- Python OpenCV | cv2.cvtColor() method
- Python OpenCV | cv2.imwrite() method
- Python OpenCV | cv2.putText() method
- Python OpenCV | cv2.ellipse() method
- Python OpenCV | cv2.rectangle() method
- Line detection in python with OpenCV | Houghline method
- Python Program to detect the edges of an image using OpenCV | Sobel edge detection method
- Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
- Python | Corner Detection with Shi-Tomasi Corner Detection Method using OpenCV
- Python | Corner detection with Harris Corner Detection method using OpenCV
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.