-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoDetector.py
47 lines (39 loc) · 1.12 KB
/
VideoDetector.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 torch
import numpy as np
import cv2
import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
model=torch.hub.load("ultralytics/yolov5",'custom',path="best3.pt",force_reload=True)
cap =cv2.VideoCapture("yourvideo.mp4")
while cap.isOpened():
ret, frame = cap.read()
# Make detections
results = model(frame)
cv2.imshow('YOLO', np.squeeze(results.render()))
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
###################################### REAL TIME Detector ######################################################
# import torch
# import numpy as np
# import cv2
# import os
# from matplotlib import pyplot as plt
# import tkinter
#
# os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
# model=torch.hub.load("ultralytics/yolov5",'custom',path="best170).pt",force_reload=True)
# cap = cv2.VideoCapture(0)
# while cap.isOpened():
# ret, frame = cap.read()
#
# # Make detections
# results = model(frame)
#
# cv2.imshow('YOLO', np.squeeze(results.render()))
#
# if cv2.waitKey(10) & 0xFF == ord('q'):
# break
# cap.release()
# cv2.destroyAllWindows()