- To run python interpreter type python in the terminal and press enter
- Running a python file
Working with images in OPENCV:
Functions: cv2.imshow() , cv2.imread()
USE : to display an image in a window.
HOW TO : cv2.imshow(‘window_name’,img)
First argument is a window name (string data type) while the second argument is the image. You can create as many windows as you wish, but with different window names.The window automatically fits to the image size.
This is similar to “printf” in c-lang.We need to specify the time for which it should be displayed so we need waitKey() function for this purpose.
cv2.waitKey() is a keyboard binding function having time(milliseconds) as its argument. The function waits for specified milliseconds. The program continues if any key is pressed within that time. If 0 is passed,it waits indefinitely for a keystroke.
After waitkey() function is done if we want to close the image window we can use
cv2.destroyWindow(‘window_name’) or cv2.destroyAllWindows() which closes all opened windows
CODE : import cv2 img = cv2.imread('image') cv2.namedWindow('window', cv2.WINDOW_NORMAL) cv2.imshow('window',img) cv2.waitKey(0)
USE : For importing images
HOW TO : cv2.imread(‘img_name.jpg’)
Here the “img_name.jpg” should be there in the current working directory or else you should type the entire location of image.We can use a variable to store it..If you want to import a grayscale image then type.
img = cv2.imread(‘img_name.jpg’,0)
Here if you write 1 instead of 0 then you will get a colour image which will neglect any transparency in image loaded.By default it will load image without any changes to image.