How open and save image in opencv

How open and save image in OpenCV


To open image in opencv python
Reading image file in opencv

image use : i saved the image as 1.jpg



Code :

import cv2
a = cv2.imread("1.jpg")
cv2.imshow("original image",a)
cv2.waitKey(0)
cv2.destroyAllWindows()


Explanation: 

import cv2 :Now Let's try to understand how this code works . First what we have done we call our cv2 library.
a = cv2.imread("1.jpg") : here we have store cv2.imread function to read our file in double quotes we have written the file that we are going to show and i store this image in variable called a
Note : i assume that your image in same place where your python file is saving if not you not provide image address .check the video for better understanding

cv2.imshow("original image",a) : name of the window in which our image will appear here you will notice i have ,a is written after original image it is basically telling that this image will be shown whatever the image is store in this variable 

cv2.waitKey(0) and cv2,destroyAllWindows() : try to run this code without using this line you will realise why i add there

How to Save image in OpenCv


cv2.imwrite("he.png",a)  

#cv2.imwrite will save your image of your desired name and format





 

Post a Comment

0 Comments