forked from RizwanMunawar/yolov7-object-tracking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremoto_person.py
67 lines (50 loc) · 1.95 KB
/
remoto_person.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import cv2
import imutils
import numpy as np
HOGCV = cv2.HOGDescriptor()
HOGCV.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
def detect(frame):
bounding_box_cordinates, weights = HOGCV.detectMultiScale(frame, winStride = (4, 4), padding = (8, 8), scale = 1.03)
person = 1
for x,y,w,h in bounding_box_cordinates:
cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 2)
cv2.putText(frame, f'person {person}', (x,y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,0,255), 1)
person += 1
cv2.putText(frame, 'High confidence', (10, 15), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
cv2.putText(frame, f'Total Persons : {person-1}', (40,70), cv2.FONT_HERSHEY_DUPLEX, 0.8, (255,0,0), 2)
cv2.imshow('output', frame)
return frame
video = cv2.VideoCapture(path)
check, frame = video.read()
if check == False:
print('Video Not Found. Please Enter a Valid Path (Full path of Video Should be Provided).')
return
print('Detecting people...')
while video.isOpened():
#check is True if reading was successful
check, frame = video.read()
if check:
frame = imutils.resize(frame , width=min(800,frame.shape[1]))
frame = detect(frame)
if writer is not None:
writer.write(frame)
key = cv2.waitKey(1)
if key== ord('q'):
break
else:
break
video.release()
cv2.destroyAllWindows()
def detectByCamera():
video = cv2.VideoCapture('rtsp://adminremoto:[email protected]/:554/cam/realmonitor?channel=2&subtype=0')
#video = cv2.VideoCapture(0)
print('Detecting people...')
while True:
check, frame = video.read()
frame = detect(frame)
key = cv2.waitKey(1)
if key == ord('q'):
break
video.release()
cv2.destroyAllWindows()
detectByCamera()