Apply boundary to my Image in OpenCv Python
by vigneshchennai74 Updated: Feb 3, 2023
Image processing is an interesting field in today’s Artificial Intelligence and Machine Learning period. We can see the applications of image processing in our day-to-day life, like whenever we apply filters over any image( selfie) or when we want to apply some effect like blurring the image, etc.
In python, we have a specific library that helps to work with Images called OpenCV. OpenCV is an open-source library in Python and C that's used for image processing and computer vision tasks. This library provides nearly contains all the tools you need for image processing. Using OpenCV would give you the mathematical tools required to capture images and track a particular object as it moves around. You can see from the below illustration that although it can do other things such as stretch an image or change color.
- Image/ videotape I/ O, processing, display
- Object/ point discovery( object, nonfree)
- figure- grounded monocular or stereo computer vision( stitching, videotape stab)
- Computational photography( print, videotape)
- Machine literacy & clustering( ml, Flann)
In this solution, we're going to learn how to add borders to our Image using a particular system. To add borders to the images OpenCV has a package copyMakeBorder which helps to make a border around the image The syntax is cv2.copyMakeBorder() system is used to produce a border around our image.
- imwrite(): cv2.imwrite() method is used to save images in a file system
- imshow(): cv2.imshow() method is used to display an image in our output
Then's an illustration of how you can produce a Border around the Image.
Preview of the output that you will get on running this code from your IDE
In this solution we use the Imread function of the OpenCV.
- Copy the code using the "Copy" button above, and paste it in a Python file in your IDE.
- Modify the name, location of the image.
- Run the code to apply boundary to our image.
I hope you found this useful. I have added the link to dependent libraries, version information in the following sections.
i found this code snippet by searching for "Apply boundary to my image in OpenCv python" in kandi. You can try any such use case!
Use im.show() method at the end of the code to display the image in window
syntax: cv2.imshow(window_name, image)
use the waitkey function to display the image for given milliseconds, if 0 is passed in the argument it waits till any key is pressed. Inside the arguments, u can enter the time that image needs to display .
I tested this solution in the following versions. Be mindful of changes when working with other versions
- The solution is created and executed in python version 3.7.15 .
- The solution is tested on OpenCV 4.6.0
Using this solution, we are able to display an image using the OpenCv library in Python with simple steps. This process also facilities an easy to use, hassle free method to create a hands-on working version of code which would help us display an image in Python
If you do not have OpenCV that is required to run this code, you can install it by clicking on the above link and copying the pip Install command from the OpenCV page in kandi.
You can search for any dependent library on kandi like OpenCV
- For any support on kandi solution kits, please use the chat
- For further learning resources, visit the Open Weaver Community learning page.