
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
Reading an image using Python OpenCv module
In OpenCv module,we can use the function cv2.imread() to read an image. When inputting the image path, the image should be in the working directory or a full path of image should be given.
cv2.IMREAD_COLOR − This function loads a color image and any transparency of image will be neglected. It is the default flag.
cv2.IMREAD_GRAYSCALE − This function loads image in grayscale mode
cv2.IMREAD_UNCHANGED − This function loads image as such including alpha channel
Source Image

Example
import numpy as np import cv2 my_img = cv2.imread('C:/Users/TP/Desktop/poor/poverty_india.jpg', 0) cv2.imshow('image', my_img) k = cv2.waitKey(0) & 0xFF # wait for ESC key to exit if k == 27: cv2.destroyAllWindows() elif k == ord('s'): cv2.imwrite('C:/Users/TP/Desktop/poor/poverty_india_gray.jpg',my_img) cv2.destroyAllWindows()
import cv2 import numpy as np import matplotlib.pyplot as plt my_img = cv2.imread('C:/Users/TP/Desktop/poor/poverty_india.jpg',cv2.IMREAD_GRAYSCALE) cv2.imshow('image', my_img) cv2.waitKey(0) cv2.destoryAllWindows()
Output

- Related Articles
- Histograms Equalization using Python OpenCv Module
- Cartooning an Image using OpenCV in Python?
- Reading a colored image as grey scale using Java OpenCV library.
- Upsampling an image using OpenCV
- Downsampling an image using OpenCV
- Find Circles in an Image using OpenCV in Python
- How to resize an image in OpenCV using Python?
- Reading and displaying images using OpenCV
- How to convert an RGB image to HSV image using OpenCV Python?
- Reading and writing Excel files using the openpyxl module in Python
- How to blur faces in an image using OpenCV Python?
- How to detect eyes in an image using OpenCV Python?
- Draw geometric shapes on images using Python OpenCv module
- Draw an ellipse on an image using OpenCV
- Python Program to detect the edges of an image using OpenCV

Advertisements