Skip to content

Commit db10847

Browse files
committed
feat: Added helmet detection program
1 parent 98447f8 commit db10847

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Helmet Detection/main.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from http.client import _DataType
2+
import cv2, random, os, time, imutils
3+
import numpy as np
4+
from tensorflow.keras.models import load_model
5+
6+
7+
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
8+
net = cv2.dnn.readNet("yolov3-custom_7000.weights","yolov3-custom.cfg")
9+
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
10+
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
11+
model = load_model('helmet-nonhelmet_cnn.h5')
12+
print('model loaded!!!')
13+
cap = cv2.VideoCapture('testing videos/test2.mp4')
14+
COLORS = [(0,255,0,),(0,0,255)]
15+
16+
def helmet_or_nonhelmet(helmet_roi):
17+
try:
18+
helmet_roi = cv2.resize(helmet_roi,(224,224))
19+
helmet_roi = np.array(helmet_roi,dtype='float32')
20+
helmet_roi = helmet_roi.reshape(1,224,224,3)
21+
helmet_roi = helmet_roi/255.0
22+
return int(model.predict(helmet_roi)[0][0])
23+
except:
24+
pass
25+
26+
layer_names = net.getLayerNames()
27+
output_layers = [layer_names[i[0] -1] for i in net.getUnconnectedOutLayers()]
28+
29+
ret = True
30+
31+
while ret:
32+
ret, img = cap.read()
33+
img = imutlis.resize(img,height=5500)

0 commit comments

Comments
 (0)