Created
June 23, 2017 03:40
-
-
Save clarle/e31955984fbb7c1a6392c2c0e9d0effb to your computer and use it in GitHub Desktop.
Revisions
-
clarle created this gist
Jun 23, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ %matplotlib inline import numpy as np import cv2 import imutils from matplotlib import pyplot as plt from imutils.object_detection import non_max_suppression hog = cv2.HOGDescriptor() hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector()) # Change to your own image with pedestrians image = cv2.imread('../data/diridon/P1070543.jpg') image = imutils.resize(image, width=min(1080, image.shape[1])) original = image.copy() # Detect people in the image (rects, weights) = hog.detectMultiScale(image, winStride=(4, 4), padding=(8, 8), scale=1.05) # Draw the original bounding boxes for (x, y, w, h) in rects: cv2.rectangle(original, (x, y), (x + w, y + h), (0, 0, 255), 2) # Apply non-maxima suppression to the bounding boxes using a # fairly large overlap threshold to try to maintain overlapping # boxes that are still people rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects]) pick = non_max_suppression(rects, probs=None, overlapThresh=0.6) # Draw the final bounding boxes for (xA, yA, xB, yB) in pick: cv2.rectangle(image, (xA, yA), (xB, yB), (0, 255, 0), 2) print("Number of pedestrians: {}".format(len(pick))) # Show the output images plt.imshow(image) plt.show()