-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathface_alert.py
70 lines (52 loc) · 1.65 KB
/
face_alert.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
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 17 10:20:23 2019
@author: apple
"""
import cv2, sys, time
import face_recognition
import viVoicecloud as vv
vv.Login()
t = vv.tts()
img = cv2.imread("self1.jpg")
tags=[]
faces=[]
self3_img = face_recognition.load_image_file("self3.jpg")
#print(face_recognition.face_encodings(self3_img))
cbn3 = face_recognition.face_encodings(self3_img)[0]
faces = faces+[cbn3]
tags = tags+["cbn3"]
print("ok1")
cap = cv2.VideoCapture(0)
width = 640
height = 480
cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
print("ok2")
while True:
try:
ret, frame = cap.read()#reading pictures from cam
img = frame
t1 = time.time()
names = face_recognition.face_encodings(img)
face_locations = face_recognition.face_locations(img)
flag = 0
for i in range(len(names)):
faceCompare = face_recognition.compare_faces(faces,names[i], tolerance = 0.5)#higher, preciser
try:
faceIndex = faceCompare.index(True)
print("Name:",tags[faceIndex])
t.say(text = "welcome championNan", voice = "John")
print("ok3")
if flag == 0:
cv2.imwrite("capture_self.jpg", img)
flag = flag+1
except Exception as e:
print("error in capturing:", e)
print("Unknown")
except Exception as e:
print("Terminate by interuption:", e)
cap.release()
vv.Logout()
sys.exit(0)