OpenCV is an open-source computer vision and machine learning software library. Various image processing operations such as manipulating images and applying tons of filters 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
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Draw Shape inside Shape in Python Using Turtle
- Python - Draw Octagonal shape Using Turtle Graphics
- OpenCV - Facial Landmarks and Face Detection using dlib and OpenCV
- Find and Draw Contours using OpenCV | Python
- Draw geometric shapes on images using OpenCV
- Draw a triangle with centroid using OpenCV
- Python | Program to extract frames using OpenCV
- Track objects with Camshift using OpenCV
- Transition from OpenCV 2 to OpenCV 3.x
- Python | Pandas df.size, df.shape and df.ndim
- Program to print the diamond shape
- Python | Pandas TimedeltaIndex.shape
- Python | Pandas Series.shape
- Python | Pandas Panel.shape
- Python | Pandas Index.shape
- PyQt5 - Tube shape Radio button
- PyQt5 QCalendarWidget - Changing Cursor Shape
- PyQt5 QCalendarWidget - Getting Cursor Shape
- PyQt5 QCalendarWidget - Making Cursor Shape back to normal
- turtle.shape() function in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.