-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdstill.py
30 lines (23 loc) · 888 Bytes
/
pdstill.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import cv2
from imutils.object_detection import non_max_suppression
from imutils import paths
import imutils
import numpy as np
#pedestrian detection still image
image = cv2.imread("download.jpeg")
#creating the hog descriptor
hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
#preprocessing the image
image = imutils.resize(image, width=min(400, image.shape[1]))
#detection
(rects, weights) = hog.detectMultiScale(image, winStride=(4, 4),padding=(8, 8), scale=1.05)
#applying non-max-suppression
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.65)
#creating the non max suppression rectangles
for (xA, yA, xB, yB) in pick:
cv2.rectangle(image, (xA, yA), (xB, yB), (0, 255, 0), 2)
#displaying image
cv2.imshow("Detected pedestrians !", image)
cv2.waitKey(0)