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
- Draw Shape inside Shape in Python Using Turtle
- Python - Draw Octagonal shape Using Turtle Graphics
- Find and Draw Contours using OpenCV | Python
- Python | Program to extract frames using OpenCV
- OpenCV - Facial Landmarks and Face Detection using dlib and OpenCV
- Draw geometric shapes on images using OpenCV
- Draw a triangle with centroid 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
- Python | Pandas TimedeltaIndex.shape
- Python | Pandas Series.shape
- Python | Pandas Panel.shape
- Python | Pandas Index.shape
- turtle.shape() function in Python
- Python - tensorflow.IndexedSlices.shape Attribute
- Python | Create video using multiple images using OpenCV
- Image resizing using Seam carving using OpenCV in Python
- Extract numbers from a text file and add them using Python
- Draw Cube and Cuboid in Python using Turtle
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.