What you'll be learning in this post.
1. How to read images from your computer with opencv.
2. How to display images from your computer with opencv.
3. How to write images to your computer with opencv.
Lets get started,
i'm using the old file that we have used in previous post namely opencv_test.py, you can find the post here.
and you will need any image file, i have named it as test.jpg.
So lest start from the first.
1. How to read images from your computer with opencv.
diplay window until any key is press from keyboard, we can specify any keyboard key like 'q' to quit the program. we will see it in future posts.
Tags: opencv, opencv python, opencv programming, python, imread, imwrite, imshow.
1. How to read images from your computer with opencv.
2. How to display images from your computer with opencv.
3. How to write images to your computer with opencv.
Lets get started,
i'm using the old file that we have used in previous post namely opencv_test.py, you can find the post here.
and you will need any image file, i have named it as test.jpg.
1. How to read images from your computer with opencv.
- here we are using opencv's function imread to read our image from any directory. and we are assigning it to the img variable.
This is how we read our image.
2. How to display image that we have read in our program.
so to do that we will be using opencv's imshow function, which accepts two parameters.
- Opencv diplay name (this is to differentiate more than one windows of opencv )
- Image variable
Here we have two new functions waitKey() and destroyAllWindows().
The reason why we are using these function is that the waitKey function will hold the
The destroyAllWindows() will destroy all the opencv windows that is opened now.
Now you can run and test your program. if you dont know how to do that make sure you read my previous posts.
2. How to save image from our program to your computer.
in this section we will learn new function that will convert our color image to black and white.
cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
This is the final block of code that we will be running bu let me explain you first.
here i have used two new functions cvtColor(), imwrite()
- cvtColor takes input image variable as first parameter and opencv specified property to convert color to B&W image.
- imwrite take file name to be saved as first parameter, ans image variable as second.
- i have used another window so we can see the image color and black and white at same time but the difference is that i have specified different window names to each window.
Run this program ans see what is the output.
Hope you liked the post, let me know in comments.
Tags: opencv, opencv python, opencv programming, python, imread, imwrite, imshow.
No comments:
Post a Comment