-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcamera.py
33 lines (25 loc) · 1 KB
/
camera.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
import cv2
from detection import AccidentDetectionModel
import numpy as np
import os
model = AccidentDetectionModel("model.json", 'model_weights.h5')
font = cv2.FONT_HERSHEY_SIMPLEX
def startapplication():
video = cv2.VideoCapture('cars.mp4') # for camera use video = cv2.VideoCapture(0)
while True:
ret, frame = video.read()
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
roi = cv2.resize(gray_frame, (250, 250))
pred, prob = model.predict_accident(roi[np.newaxis, :, :])
if(pred == "Accident"):
prob = (round(prob[0][0]*100, 2))
# to beep when alert:
# if(prob > 90):
# os.system("say beep")
cv2.rectangle(frame, (0, 0), (280, 40), (0, 0, 0), -1)
cv2.putText(frame, pred+" "+str(prob), (20, 30), font, 1, (255, 255, 0), 2)
if cv2.waitKey(33) & 0xFF == ord('q'):
return
cv2.imshow('Video', frame)
if __name__ == '__main__':
startapplication()