-
Notifications
You must be signed in to change notification settings - Fork 5
/
detectHuman.py
47 lines (36 loc) · 1.26 KB
/
detectHuman.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import time
# import imutils
import numpy as np
import cv2
import hogClass
def detectHumanFromFrame(image):
hog = hogClass.hogObject()
image = np.asarray(image)
# image = imutils.resize(image, width=min(400, image.shape[1]))
ratio = image.shape[0] / image.shape[1]
new_height = int(400 * ratio)
image = cv2.resize(image, (400,new_height))
# Detecting all the regions in the Image that has a pedestrians inside it
(regions, _) = hog.detector.detectMultiScale(
image, winStride=(4, 4), padding=(4, 4), scale=1.05)
# Drawing the regions in the image
for (x, y, w, h) in regions:
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
return image
if __name__ == "__main__":
cap = cv2.VideoCapture('livedata.mp4')
ret, image = cap.read()
t_end = time.time() + 10
while time.time() < t_end:
# Reading the video stream
ret, image = cap.read()
if ret:
image = detectHumanFromFrame(image)
cv2.imshow("Image", image)
cv2.waitKey(5)
if cv2.waitKey(5) & 0xFF == ord('q'):
exit()
else:
break
cap.release()
cv2.destroyAllWindows()