OpenCV is the huge open-source library for computer vision, machine learning, and image processing and now it plays a major role in real-time operation which is very important in today’s systems. By using it, one can process images and videos to identify objects, faces, or even the handwriting of a human. This article focuses on detecting objects.
Note: For more information, refer to Introduction to OpenCV.
Object Detection is a computer technology related to computer vision, image processing, and deep learning that deals with detecting instances of objects in images and videos. We will do object detection in this article using something known as haar cascades.
Haar Cascade classifiers are an effective way for object detection. This method was proposed by Paul Viola and Michael Jones in their paper Rapid Object Detection using a Boosted Cascade of Simple Features. Haar Cascade is a machine learning-based approach where a lot of positive and negative images are used to train the classifier.
- Positive images – These images contain the images which we want our classifier to identify.
- Negative Images – Images of everything else, which do not contain the object we want to detect.
Steps to download the requirements below:
- Run The following command in the terminal to install opencv.
pip install opencv-python
- Run the following command to in the terminal install the matplotlib.
pip install matplotlib
- To download the haar cascade file and image used in the below code as a zip file click here.
Note: Put the XML file and the PNG image in the same folder as your Python script.
Opening an image
We will use the
detectMultiScale() function of OpenCV to recognize big signs as well as small ones:
Here is the full script for lazy devs:
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.
- Object Oriented Programming in Python | Set 1 (Class, Object and Members)
- Object Oriented Programming in Python | Set 2 (Data Hiding and Object Printing)
- Python Program to detect the edges of an image using OpenCV | Sobel edge detection method
- Python | Detect corner of an image using OpenCV
- Python | Detect Polygons in an Image using OpenCV
- Detect an Unknown Language using Python
- Detect and Recognize Car License Plate from a video in real time
- Python - Detect loop in Dictionaries
- Interquartile Range to Detect Outliers in Data
- Detect Cat Faces in Real-Time using Python-OpenCV
- Detect the RGB color from a webcam using Python - OpenCV
- OOP in Python | Set 3 (Inheritance, examples of object, issubclass and super)
- pickle — Python object serialization
- Data type Object (dtype) in NumPy Python
- PyQt5 QSpinBox – Setting object name
- marshal — Internal Python object serialization
- Python __iter__() and __next__() | Converting an object into an iterator
- Python Object Comparison : "is" vs "=="
- Python | object() method
- Python | Convert dictionary object into 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 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.
Improved By : priyankamore