for encoding in encodings:
matches = face_recognition.compare_faces(known_face_encoding,
encoding)
name = "Unknown"
if True in matches:
matchedIdxs = [i for (i, b) in enumerate(matches) if b]
counts = {}
for i in matchedIdxs:
best_match_index = np.argmin(matches)
name = known_face_names[best_match_index]
counts[name] = counts.get(name, 0) + 1
name = max(counts, key=counts.get)
names.append(name)
Put the text (name) and rectangle to the picture or video
for ((x, y, w, h), name) in zip(faces, names):
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.putText(frame, name, (x, y), cv2.FONT_HERSHEY_SIMPLEX,
0.75, (0, 255, 0), 2)`
Connect the program to the speaker
engine = pyttsx3.init()
if matches [0] == True:
engine.say("Wellcome home etcodetech")
else:
engine.say("Who are you ? i don't know you")
engine.say("Please go back later")
engine.runAndWait()
Capture the picture and send to the bot telegram
bot = telepot.Bot('insert your token')
if matches [0] == True:
engine.say("Wellcome home etcodetech")
cv2.imwrite("family.jpg", frame)
bot.sendPhoto('insert your chat id', photo=open('family.jpg', 'rb'))
else:
engine.say("Who are you ? i don't know you")
engine.say("Please go back later")
cv2.imwrite("guest.jpg", frame)
bot.sendPhoto('insert your chat id', photo=open('guest.jpg', 'rb'))
engine.runAndWait()
Demo
Clik the picture to see the Video
About
Smart CCTV that uses a telegram bot and speaker to recognize a person's face and issue an alert if the face is not recognized.