- OpenCV Python - Digit Recognition
- OpenCV Python - Feature Matching
- OpenCV Python - Feature Detection
- OpenCV Python - Meanshift/Camshift
- OpenCV Python - Face Detection
- OpenCV Python - Video from Images
- OpenCV Python - Images From Video
- OpenCV Python - Play Videos
- OpenCV Python - Capture Videos
- OpenCV Python - Fourier Transform
- OpenCV Python - Image Blending
- OpenCV Python - Image Addition
- OpenCV Python - Image Pyramids
- OpenCV Python - Template Matching
- OpenCV Python - Image Contours
- OpenCV Python - Transformations
- OpenCV Python - Color Spaces
- OpenCV Python - Histogram
- OpenCV Python - Edge Detection
- OpenCV Python - Image Filtering
- OpenCV Python - Image Threshold
- OpenCV Python - Resize and Rotate
- OpenCV Python - Add Trackbar
- OpenCV Python - Mouse Events
- OpenCV Python - Shapes and Text
- OpenCV Python - Bitwise Operations
- OpenCV Python - Image Properties
- OpenCV Python - Using Matplotlib
- OpenCV Python - Write Image
- OpenCV Python - Reading Image
- OpenCV Python - Environment
- OpenCV Python - Overview
- OpenCV Python - Home
OpenCV Python Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
OpenCV Python - Reading an image
The CV2 package (name of OpenCV-Python pbrary) provides the imread() function to read an image.
The command to read an image is as follows −
img=cv2.imread(filename, flags)
The flags parameters are the enumeration of following constants −
cv2.IMREAD_COLOR (1) − Loads a color image.
cv2.IMREAD_GRAYSCALE (0) − Loads image in grayscale mode
cv2.IMREAD_UNCHANGED (-1) − Loads image as such including alpha channel
The function will return an image object, which can be rendered using imshow() function. The command for using imshow() function is given below −
cv2.imshow(window-name, image)
The image is displayed in a named window. A new window is created with the AUTOSIZE flag set. The WaitKey() is a keyboard binding function. Its argument is the time in milpseconds.
The function waits for specified milpseconds and keeps the window on display till a key is pressed. Finally, we can destroy all the windows thus created.
The function waits for specified milpseconds and keeps the window on display till a key is pressed. Finally, we can destroy all the windows thus created.
The program to display the OpenCV logo is as follows −
import numpy as np import cv2 # Load a color image in grayscale img = cv2.imread( OpenCV_Logo.png ,1) cv2.imshow( image ,img) cv2.waitKey(0) cv2.destroyAllWindows()
The above program displays the OpenCV logo as follows −
Advertisements