Images (reading, showing and writing)

A short introduction on how to read , show and write images using OpenCV.

Given below is a program in python to read ,display and write images.

#read ,show  and write images in opencv
import cv2

Functions used:


This function is used to read images.It takes two parameters : the path of image and the flag.
imread(give the path of the image ,flag)
flag – indicates the way the image will be read (0,1,-1)
1 : loads a color image
0 : loads image in gray scale mode
-1 : loads image as such including alpha channel


will show u the following output:


This function displays the image that has been read on the screen.It takes two parameters : the tittle of the window and the image variable.

imshow(window title, image variable)


waitKey() function will show the image for a specific amount of time.It takes time in millisecond as a parameter

If 0 is passed as the parameter then the window will remain open till you hit any random key


This function destroys all the windows which we have created


This function is used to save the image file that we have read. It take s two parameters: the file name and the image variable. Give the file name and its format and give the image variable as parameters. Look at the given picture below . The file has been saved (highlighted in yellow).

prerequisites: What is OpenCV?

One Comment

Leave a Reply