OpenCV is an open-source library, which is aimed at real-time computer vision. This library is developed by Intel and is cross-platform – it can support Python, C++, Java, etc. Computer Vision is a cutting edge field of Computer Science that aims to enable computers to understand what is being seen in an image. OpenCV is one of the most widely used libraries for Computer Vision tasks like face recognition, motion detection, object detection, etc.
In this tutorial, we are going to build a basic Pedestrian Detector for images and videos using OpenCV. Pedestrian detection is a very important area of research because it can enhance the functionality of a pedestrian protection system in Self Driving Cars.
We can extract features like head, two arms, two legs, etc, from an image of a human body and pass them to train a machine learning model. After training, the model can be used to detect and track humans in images and video streams. However, OpenCV has a built-in method to detect pedestrians. It has a pre-trained HOG(Histogram of Oriented Gradients) + Linear SVM model to detect pedestrians in images and video streams.
Histogram of Oriented Gradients
This algorithm checks directly surrounding pixels of every single pixel. The goal is to check how darker is the current pixel compared to the surrounding pixels. The algorithm draws and arrows showing the direction of the image getting darker. It repeats the process for each and every pixel in the image. At last, every pixel would be replaced by an arrow, these arrows are called Gradients. These gradients show the flow of light from light to dark. By using these gradients algorithms perform further analysis. To learn more about HOG, read Navneet Dalal and Bill Triggs research paper on HOG for Human Detection..
To install the above modules type the below command in the terminal.
pip install moudle_name
Lets make the program to detect pedestrians in an Image:
Example 2: Lets make the program to detect pedestrians in a video:
- Text Detection and Extraction using OpenCV and OCR
- Python - Edge Detection using Pillow
- Multiple Color Detection in Real-Time using Python-OpenCV
- Gun Detection using Python-OpenCV
- Text Localization, Detection and Recognition using Pytesseract
- Image resizing using Seam carving using OpenCV in Python
- Converting Color video to grayscale using OpenCV in Python
- Negative transformation of an image using Python and OpenCV
- Check if the camera is opened or not using OpenCV-Python
- How to take screenshots using python?
- Saving a Video using OpenCV
- Track objects with Camshift using OpenCV
- Python - Process images of a video using OpenCV
- Python | Multiple Face Recognition using dlib
- Python | Face recognition using GUI
- Create Local Binary Pattern of an image using OpenCV-Python
- Log transformation of an image using Python and OpenCV
- Display date and time in videos using OpenCV - Python
- Implement Canny Edge Detector in Python using OpenCV
- Feature matching using ORB algorithm in Python-OpenCV
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.