cv2.imread() method - Python OpenCV Last Updated : 14 Apr, 2025 Comments Improve Suggest changes Like Article Like Report OpenCV-Python is a Python library used to solve computer vision tasks. cv2.imread() method loads an image from the specified file. If the image cannot be read because of missing file, improper permissions or an unsupported/invalid format then it returns an empty matrix.Example: Python import cv2 image = cv2.imread("image.png") cv2.imshow("Image", image) cv2.waitKey(0) cv2.destroyAllWindows() Output:Example ImageSyntax of cv2.imread() Methodcv2.imread(filename, flag) Parameters:filename: specifies the path to the image file.flag: specifies the way how the image should be read which can be :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 such as including alpha channel. Alternatively we can pass integer value -1 for this flag.The cv2.imread() function return a NumPy array if the image is loaded successfully.Examples of OpenCV cv2.imread() Method Below is the sample image we will be using:Input Image1. Using cv2 imread() function to read a colored image:In this example we are reading the image as a color image. We will use cv.imread() function to take the image as an input and cv.imshow() function to display the image. Python import cv2 image = cv2.imread("gfg.jpeg") cv2.imshow("Image", image) cv2.waitKey(0) cv2.destroyAllWindows() Output: Colored imageHere we can see that by default our image got read and displayed in coloured image. 2. Reading image in grayscaleIn this example we are reading the image as a greyscale image. Both color and grayscale images are acceptable as input. Python import cv2 image = cv2.imread("gfg.jpeg",cv2.IMREAD_GRAYSCALE) cv2.imshow("Image", image) cv2.waitKey(0) cv2.destroyAllWindows() Output:Grayscale Image3. Reading PNG Image with TransparencyIn this example we are reading the image with the transparency channel i.e the alpha channel. It represents the transparency or opacity of an image. It controls how transparent or solid each pixel is with value of 0 indicating full transparency and 255 representing full opacity. Python import cv2 image = cv2.imread("gfg.jpeg",cv2.IMREAD_UNCHANGED) cv2.imshow("Image", image) cv2.waitKey(0) cv2.destroyAllWindows() Output:Image with Aplha Channelcv2.imread() method is a fundamental function for reading image files. It loads images into memory allowing us image manipulation and analysis. By specifying the appropriate flag you can control how the image is loaded and used for analysis. Comment More infoAdvertise with us Next Article Python OpenCV | cv2.imshow() method R Rajnis09 Follow Improve Article Tags : Python OpenCV Python-OpenCV Practice Tags : python Similar Reads Essential OpenCV Functions to Get Started into Computer Vision Computer vision is a process by which we can understand the images and videos how they are stored and how we can manipulate and retrieve data from them. Computer Vision is the base or mostly used for Artificial Intelligence. Computer-Vision is playing a major role in self-driving cars, robotics as w 7 min read cv2.imread() method - Python OpenCV OpenCV-Python is a Python library used to solve computer vision tasks. cv2.imread() method loads an image from the specified file. If the image cannot be read because of missing file, improper permissions or an unsupported/invalid format then it returns an empty matrix.Example:Pythonimport cv2 image 2 min read Python OpenCV | cv2.imshow() method OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.imshow() method is used to display an image in a window. The window automatically fits the image size. Syntax: cv2.imshow(window_name, image)Parameters: window_name: A string representing the name of the wi 3 min read Python OpenCV | cv2.cvtColor() method OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.cvtColor() method is used to convert an image from one color space to another. There are more than 150 color-space conversion methods available in OpenCV. We will use some of color space conversion codes be 4 min read Python OpenCV | cv2.imwrite() method OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.imwrite() method is used to save an image to any storage device. This will save the image according to the specified format in current working directory. Syntax: cv2.imwrite(filename, image) Parameters:file 2 min read Python OpenCV | cv2.rectangle() method OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.rectangle() method is used to draw a rectangle on any image. Syntax: cv2.rectangle(image, start_point, end_point, color, thickness) Parameters:image: It is the image on which rectangle is to be drawn. start 4 min read cv2.circle() method OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.circle() method is used to draw a circle on any image. We use this image:Example:Pythonimport cv2 path = r'C:\Users\user\Desktop\geeks14.png' src = cv2.imread(path) cv2.circle(src, center=(100, 100), radius 2 min read Python OpenCV | cv2.line() method OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.line() method is used to draw a line on any image.Syntax:cv2.line(image, start_point, end_point, color, thickness) Parameters: image: It is the image on which line is to be drawn. start_point: It is the sta 3 min read Python OpenCV | cv2.putText() method OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.putText() method is used to draw a text string on any image. Syntax: cv2.putText(image, text, org, font, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]]) Parameters:image: It is the image on w 5 min read Line detection in python with OpenCV | Houghline method The Hough Transform is a method that is used in image processing to detect any shape, if that shape can be represented in mathematical form. It can detect the shape even if it is broken or distorted a little bit.We will see how Hough transform works for line detection using the HoughLine transform m 6 min read Like