How to do it...

Perform the following steps to detect people in an image using opencv-python library functions:

  1. First, read the image and initialize the HOG detector using the following lines of code:
img = cv2.imread("images/walk.jpg")hog = cv2.HOGDescriptor()
  1. Initialize the SVM detector to be the default people detector:
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
  1. Run the detection algorithm, with a spatial stride of 4 pixels (horizontal and vertical), a scale stride of 1.1, and no grouping of the rectangles (to notice that HOG detects the same object at multiple scales in the scale pyramid). As you can see, 314 potential bounding boxes were detected (with multiple detections of the same object):
(found_bounding_boxes, ...

Get Python Image Processing Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.