Hello Guys,
In this tutorial, I will discuss how to display an image using OpenCV.
OpenCV comes with the function named imshow which is used to display images.
imshow function takes two arguments
1. Window name
2. Image object
We can show show any number of windows . But the name of each window must be different.
# Import cv2 moduleimport cv2 as cv#reading an using imread function without passing any parameter#by default it loads image in color format (BGR format)colored_image= cv.imread("nature.jpg") # loads image in gray formatgray_image= cv.imread("nature.jpg",cv.IMREAD_GRAYSCALE)#Code to display single imagecv.imshow("Colored Image",colored_image)#Passing zero means it will open till you press any key #to close the window. It takes time in milliseconds . So if 500 will be #passed then it will be opened for 500 ms and then it will be closed #automatically.cv.waitKey(0) # This is used to close all opened windowscv.destroyAllWindows() #code to display multiple windows. If you want to show multiple images #then you have to pass different window name for each windowcv.imshow("Colored Image",colored_image)cv.imshow("GrayScale Image",gray_image)cv.waitKey(0)cv.destroyAllWindows() # This is used to close all opened windows
Also don’t forget to check my previous OpenCV tutorials.
http://techievaibhav.in/category/programming/opencv/
Comments
Post a Comment