- OpenCV Tutorial
- OpenCV - Home
- OpenCV - Overview
- OpenCV - Environment
- OpenCV - Storing Images
- OpenCV - Reading Images
- OpenCV - Writing an Image
- OpenCV - GUI
- Types of Images
- OpenCV - The IMREAD_XXX Flag
- Reading an Image as Grayscale
- OpenCV - Reading Image as BGR
- Image Conversion
- Colored Images to GrayScale
- OpenCV - Colored Image to Binary
- OpenCV - Grayscale to Binary
- Drawing Functions
- OpenCV - Drawing a Circle
- OpenCV - Drawing a Line
- OpenCV - Drawing a Rectangle
- OpenCV - Drawing an Ellipse
- OpenCV - Drawing Polylines
- OpenCV - Drawing Convex Polylines
- OpenCV - Drawing Arrowed Lines
- OpenCV - Adding Text
- Filtering
- OpenCV - Bilateral Filter
- OpenCV - Box Filter
- OpenCV - SQRBox Filter
- OpenCV - Filter2D
- OpenCV - Dilation
- OpenCV - Erosion
- OpenCV - Morphological Operations
- OpenCV - Image Pyramids
- Sobel Derivatives
- OpenCV - Sobel Operator
- OpenCV - Scharr Operator
- Transformation Operations
- OpenCV - Laplacian Transformation
- OpenCV - Distance Transformation
- Camera and Face Detection
- OpenCV - Using Camera
- OpenCV - Face Detection in a Picture
- Face Detection using Camera
- Geometric Transformations
- OpenCV - Affine Translation
- OpenCV - Rotation
- OpenCV - Scaling
- OpenCV - Color Maps
- Miscellaneous Chapters
- OpenCV - Canny Edge Detection
- OpenCV - Hough Line Transform
- OpenCV - Histogram Equalization
- OpenCV Useful Resources
- OpenCV - Quick Guide
- OpenCV - Useful Resources
- OpenCV - Discussion
OpenCV - The IMREAD_XXX Flag
OpenCV supports various types of images such as colored, binary, grayscale, etc. Using the imread() method and predefined fields of the Imgcodecs class, you can read a given image as another type.
The flags parameter of imread() method (IMREAD_XXX)
In the earlier chapters, we have seen the syntax of imread() method of the Imgcodecs class. It accepts a string argument representing the location of the image that is to be read.
imread(filename)
The imread() method has another syntax.
imread(filename, int flags)
This syntax accepts two parameters −
filename − It accepts an argument (filename), a variable of the String type representing the path of the file that is to be read.
flags − An integer value representing a predefined flag value. For each value, this reads the given image as a specific type (gray scale color etc.)
Following is the table listing various fields provided in the Imgproc class as values for this parameter.
S.No | Fields and Description |
---|---|
1 |
IMREAD_COLOR If the flag is set to this value, the loaded image will be converted to a 3-channel BGR (Blue Green Red) color image. |
2 |
IMREAD_GRAYSCALE If the flag is set to this value, the loaded image will be converted to a single-channel grayscale image. |
3 |
IMREAD_LOAD_GDAL If the flag is set to this value, you can load the image using the gdal driver. |
4 |
IMREAD_ANYCOLOR If the flag is set to this value, the image is read in any possible color format. |
5 |
IMREAD_REDUCED_COLOR_2 IMREAD_REDUCED_COLOR_4 IMREAD_REDUCED_COLOR_8 If the flag is set to this value, the image is read as three-channel BGR, and the size of the image is reduced to ½, ¼th or ⅛th of the original size of the image with respect to the field used. |
6 |
IMREAD_REDUCED_GRAYSCALE_2 IMREAD_REDUCED_GRAYSCALE_4 IMREAD_REDUCED_GRAYSCALE_8 If the flag is set to this value, the image is read as a single-channel grayscale image, and the size of the image is reduced to ½, ¼th or ⅛th of the original size of the image with respect to the field used. |
7 |
IMREAD_UNCHANGED If the flag is set to this value, the loaded image is returned as it is. |
To Continue Learning Please Login
Login with Google