OpenCV is an open source computer vision and machine learning software library. Various image processing operations such as manipulating image and applying tons of filter can be done with the help of it. It is broadly used in Object detection, Face Detection and other Image processing tasks.
Let’s see how to draw rectangular shape on image and extract the objects using OpenCV.
Above piece of code will work with only black background image. But rectangles can be drawn to any images. We can write a program which allows us to select desired portion in an image and extract that selected portion as well. The task includes following things –
- draw shape on any image
- re-select the extract portion for in case bad selection
- extract particular object from the image
Run : Save the file as capture_events.py and for testing select a demo picture which is located in the same directory. Now, execute the following command –
python capture_events.py --image demo.jpg
Output: First select the desired portion from the image. In addition, we can remove bad selection by pressing ‘r’ as programmed for making a new proper selection.
Fig: Selected Portion
Now after selecting a proper selection like above, just press ‘c’ to extract, as programmed.
Fig: Cut Portion
- Python | Program to extract frames using OpenCV
- Find and Draw Contours using OpenCV | Python
- Draw a triangle with centroid using OpenCV
- Draw geometric shapes on images using OpenCV
- Python | Pandas Panel.shape
- Python | Pandas TimedeltaIndex.shape
- Python | Pandas Series.shape
- Python | Pandas Index.shape
- Python | Pandas df.size, df.shape and df.ndim
- numpy.extract() in Python
- Python | Extract words from given string
- Python | Pandas Series.str.extract()
- Python | Extract numbers from string
- Extract images from video in Python
- Python | Extract only characters from given string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.