forked from jaak322/smart-house
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalarm-security-sys+face_detection.py
More file actions
71 lines (47 loc) · 1.51 KB
/
alarm-security-sys+face_detection.py
File metadata and controls
71 lines (47 loc) · 1.51 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
import face_recognition
import imutils
import pickle
import time
from imutils.video import VideoStream
from imutils.video import FPS
import cv2
from pydub import AudioSegment
from pydub.playback import play
from firebase import firebase
import serial
import time
import re
FBConn = firebase.FirebaseApplication('https://smart-house-ae2d9-default-rtdb.europe-west1.firebasedatabase.app/', None)
song = AudioSegment.from_mp3("soundclip.mp3")
currentname = "unknown"
currentname2 = "unknown"
autolamp=0
encodingsP = "encodings.pickle"
print("Loading face detection & extraction of characteristics")
data = pickle.loads(open(encodingsP, "rb").read())
vs = VideoStream(src=0,framerate=10).start()
time.sleep(2.0)
fps = FPS().start()
while True:
frame = vs.read()
frame = imutils.resize(frame, width=500)
boxes = face_recognition.face_locations(frame)
encodings = face_recognition.face_encodings(frame, boxes)
names = []
for encoding in encodings:
matches = face_recognition.compare_faces(data["encodings"],
encoding)
if True in matches:
matchedIdxs = [i for (i, b) in enumerate(matches) if b]
counts = {}
for i in matchedIdxs:
name = data["names"][i]
counts[name] = counts.get(name, 0) + 1
name = max(counts, key=counts.get)
while currentname != name:
currentname = name
while name == "Alex":
print("Security Alarm Deactivated")
lamp = FBConn.put("/Security","lazerX",autolamp)
name = "unknown2"
break