-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.py
More file actions
41 lines (31 loc) · 785 Bytes
/
camera.py
File metadata and controls
41 lines (31 loc) · 785 Bytes
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
from time import time
import cv2
from numpy import intersect1d
import torch
model = torch.hub.load('ultralytics/yolov5', 'yolov5m')
danger = open('danger.txt').read().strip().split('\n')
cap = cv2.VideoCapture(0)
cap.set(3, 640)
cap.set(4, 480)
def detect(img):
result = model(img)
result.print()
object = result.pandas().xyxy[0].name.unique()
print(object)
common = intersect1d(object, danger)
if(len(common)):
# Raise Alarm
print("ALARM")
while True:
t0 = time()
frame = None
success, frame = cap.read()
if success:
detect(frame)
else:
print('Error in Camera') # For debugging purposes
continue
while(time()-t0 < 10):
continue
print('time taken: ')
print(time()-t0)