-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRealtime_Detection.py
More file actions
73 lines (52 loc) · 2.09 KB
/
Realtime_Detection.py
File metadata and controls
73 lines (52 loc) · 2.09 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import cv2
from mtcnn.mtcnn import MTCNN
detector = MTCNN()
import numpy as np
from keras.preprocessing.image import img_to_array
from resizeimage import resizeimage
from keras.models import load_model
model = load_model(r"C:\Users\ASUS\face_mask.h5")
from keras.preprocessing.image import load_img
font = cv2.FONT_HERSHEY_TRIPLEX
font2 = cv2.FONT_HERSHEY_COMPLEX_SMALL
font3 = cv2.FONT_HERSHEY_SCRIPT_COMPLEX
font4 = cv2.FONT_HERSHEY_SIMPLEX
# image_file = load_img('test_img.jpg')
# print(chr(169))
# rights=chr(169)+'2020'
cap = cv2.VideoCapture(0)
while True:
# Capture frame-by-frame
__, frame = cap.read()
cv2.putText(frame, 'PIASH\'s CAM', (480, 450), font2, 0.9, (255, 255, 255), 2, cv2.LINE_AA)
# Use MTCNN to detect faces
result = detector.detect_faces(frame)
if result != []:
for person in result:
bounding_box = person['box']
keypoints = person['keypoints']
# cv2.putText(frame,"The Face",(200,100), font, 1,(255,255,255),2,cv2.LINE_AA)
cv2.imwrite('opencv.png', frame)
image_file = load_img('opencv.png')
cover = resizeimage.resize_cover(image_file, [160, 160], validate=False)
x = []
x = img_to_array(cover)
x = np.expand_dims(x, axis=0)
pred = model.predict(x)
print(pred[0][0])
if pred[0][0] == 0.0:
cv2.putText(frame, "ACCESS GRANTED, MASK ON", (160, 160), font4, 0.8, (0, 255, 0), 2, cv2.LINE_AA)
elif pred[0][0] == 1.0:
cv2.putText(frame, "ACCESS DENIED, No FACE-MASK", (160, 160), font4, 0.8, (0, 0, 255), 2, cv2.LINE_AA)
cv2.rectangle(frame,
(bounding_box[0], bounding_box[1]),
(bounding_box[0] + bounding_box[2], bounding_box[1] + bounding_box[3]),
(0, 155, 255),
2)
# display resulting frame
cv2.imshow('frame', frame)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
# When everything's done, release capture
cap.release()
cv2.destroyAllWindows()