-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_video.py
59 lines (40 loc) · 1.58 KB
/
main_video.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
48
49
50
51
52
53
54
55
56
57
58
59
import cv2
from simple_facerec import SimpleFacerec
from email_notification import EmailNotification
# Encode faces from a folder
sfr = SimpleFacerec()
sfr.load_encoding_images("train_dataset_images/")
# Load Camera
cap = cv2.VideoCapture(0)
def send_email_notification(email_img):
email_sender = ''
email_password = ''
email_receiver = ''
email_subject = "Security alert"
email_body = """ Unautherized person has entered in your house
"""
email_img = email_img
e = EmailNotification(email_sender,email_password,email_receiver,email_subject,email_body,email_img)
e.emailfunc()
unauth = "Unknown"
while True:
ret, frame = cap.read()
# Detect Faces
face_locations, face_names = sfr.detect_known_faces(frame)
for face_loc, name in zip(face_locations, face_names):
y1, x2, y2, x1 = face_loc[0], face_loc[1], face_loc[2], face_loc[3]
cv2.putText(frame, name,(x1, y1 - 10), cv2.FONT_HERSHEY_DUPLEX, 1, (0, 0, 0), 2)
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 200), 2)
#Security alert for unauthorized person
if unauth == name:
cv2.imwrite('capture_image/unrecognized_pic.jpg', frame)
# for i in range (3):
# cv2.imwrite('unrecognize'+str(i)+'.png', frame)
email_img = "capture_image/unrecognized_pic.jpg"
send_email_notification(email_img)
cv2.imshow("Frame", frame)
key = cv2.waitKey(1)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()