forked from Sharpiless/Yolov5-deepsort-inference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
54 lines (41 loc) · 1.21 KB
/
demo.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
from AIDetector_pytorch import Detector
import imutils
import cv2
def main():
func_status = {}
func_status['headpose'] = None
name = 'demo'
det = Detector()
cap = cv2.VideoCapture('E:/视频/行人监控/test01.mp4')
fps = int(cap.get(5))
print('fps:', fps)
t = int(1000/fps)
size = None
videoWriter = None
while True:
# try:
_, im = cap.read()
if im is None:
break
result = det.feedCap(im, func_status)
result = result['frame']
result = imutils.resize(result, height=500)
if videoWriter is None:
fourcc = cv2.VideoWriter_fourcc(
'm', 'p', '4', 'v') # opencv3.0
videoWriter = cv2.VideoWriter(
'result.mp4', fourcc, fps, (result.shape[1], result.shape[0]))
videoWriter.write(result)
cv2.imshow(name, result)
cv2.waitKey(t)
if cv2.getWindowProperty(name, cv2.WND_PROP_AUTOSIZE) < 1:
# 点x退出
break
# except Exception as e:
# print(e)
# break
cap.release()
videoWriter.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()