A simple pedestrian detector using the SVM model
In this recipe, you will learn how to detect pedestrians using a pre-trained SVM model with HOG features. Pedestrian detection is an important component of many Advanced Driver Assistance Solutions (ADAS). Pedestrian detection is also used in video surveillance systems, and many other computer vision applications.
Getting ready
Before you proceed with this recipe, you need to install the OpenCV 3.x Python API package and the matplotlib
package.
How to do it...
- Import the modules:
import cv2 import matplotlib.pyplot as plt
- Load the test image:
image = cv2.imread('../data/people.jpg')
- Create the HOG feature computer and detector:
hog = cv2.HOGDescriptor() hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
- Detect the people in the image:
locations, weights = hog.detectMultiScale(image)
- Draw the detected people bounding boxes:
dbg_image = image.copy() for loc in locations: cv2.rectangle(dbg_image, (loc[0], loc[1]), (loc...