Apply boundary to my Image in OpenCV Python.

share link

by vigneshchennai74 dot icon Updated: Apr 6, 2023

technology logo
technology logo

Solution Kit Solution Kit  

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 Python and C library 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 illustration below that it can do other things, such as stretch an image or change color.


OpenCV Functionality:

  • 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)


This solution will teach us how to add borders to our image using a particular system. The syntax is cv2.copyMakeBorder() system is used to produce a border around our image. To add borders to the images, OpenCV has a package copyMakeBorder which helps to make a border around the 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 to produce a Border around the image.

Preview of the output that you will get on running this code from your IDE

CODE

In this solution we use the Imread function of the OpenCV.

  1. Copy the code using the "Copy" button above, and paste it in a Python file in your IDE.
  2. Modify the name, location of the image.
  3. 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!


Note:

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 .

syntax: cv2.wiatkey()

Environment Tested

I tested this solution in the following versions. Be mindful of changes when working with other versions


  1. The solution is created and executed in python version 3.7.15 .
  2. 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

Dependent Library

opencvby opencv

C++ doticonstar image 69456 doticonVersion:4.7.0doticon
License: Permissive (Apache-2.0)

Open Source Computer Vision Library

Support
    Quality
      Security
        License
          Reuse

            opencvby opencv

            C++ doticon star image 69456 doticonVersion:4.7.0doticon License: Permissive (Apache-2.0)

            Open Source Computer Vision Library
            Support
              Quality
                Security
                  License
                    Reuse

                      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

                      Support

                      1. For any support on kandi solution kits, please use the chat
                      2. For further learning resources, visit the Open Weaver Community learning page.


                      See similar Kits and Libraries