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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.