-
Notifications
You must be signed in to change notification settings - Fork 11
/
Human_Detection.py
24 lines (20 loc) · 965 Bytes
/
Human_Detection.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
import cv2
import numpy as np
from imutils.object_detection import non_max_suppression
## Histogram of Oriented Gradients Detector
HOGCV = cv2.HOGDescriptor()
HOGCV.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
def Detector(frame):
## USing Sliding window concept
rects, weights = HOGCV.detectMultiScale(frame, winStride=(4, 4), padding=(8, 8), scale=1.03)
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)
c = 1
for x, y, w, h in pick:
cv2.rectangle(frame, (x, y), (w, h), (139, 34, 104), 2)
cv2.rectangle(frame, (x, y - 20), (w,y), (139, 34, 104), -1)
cv2.putText(frame, f'P{c}', (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 2)
c += 1
cv2.putText(frame, f'Total Persons : {c - 1}', (20, 450), cv2.FONT_HERSHEY_DUPLEX, 0.8, (255, 255,255), 2)
cv2.imshow('output', frame)
return frame