-
Notifications
You must be signed in to change notification settings - Fork 5
/
digivision2.py
98 lines (83 loc) · 3.32 KB
/
digivision2.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import cv2 as cv
import warnings
warnings.filterwarnings("ignore")
import p_part
import f_part
from caption_tune import modcap, face_found_cap, face_not_found_cap
from gensound import generate_sound
import tkinter as tk
from faceadd import addn,speech
def saveface():
# generate_sound("Tell me the name")
x1 = speech("What is this human called?")
print(x1 + ' face saved')
cv.imwrite(r"images//" +
str(x1) + ".jpg", save)
data = {x1: f_part.img_to_encoding(
"images//" + str(x1) + ".jpg").tolist()}
f_part.digi_db.insert_one(data)
def ignoreface():
generate_sound("Not saved")
cap = cv.VideoCapture(0)
while True:
ret, frame = cap.read()
facedetect = cv.CascadeClassifier(r'haarcascade_frontalface_default.xml')
if ret:
# font = cv.FONT_HERSHEY_SIMPLEX
cv.imshow("Video", frame)
if cv.waitKey(1) == ord('p'):
cv.imwrite('./test.jpg', frame)
final_caption = p_part.generate_caption(
'./test.jpg') # create caption
final_caption = modcap(final_caption) # remove tags
print(final_caption)
generate_sound(final_caption) # convert to audio
if cv.waitKey(1) == ord('f'):
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
faces = facedetect.detectMultiScale(gray, 1.3, 5)
cv.imwrite('./test.jpg', frame)
known_detected = 0
unknown_detected = 0
known_face_list = []
known_face_dist = []
try:
for x, y, w, h in faces:
#cv2.imwrite("dset//User."+str(user)+"."+str(sample)+".jpg",gray[y:y+h,x:x+w])
save = frame[y:y+h, x:x+w]
cv.imwrite('./test.jpg', save)
dis, name = f_part.who_is_it('./test.jpg')
print(str(dis)+","+name)
if name != 'unknown':
known_face_list.append(name)
known_face_dist.append(dis)
known_detected += 1
else:
unknown_detected += 1
if known_detected > 0:
print("known: " + str(known_detected))
for i in range(known_detected):
print('i=' + str(i))
print(
known_face_list[i] + " at dist of: " + str(known_face_dist[i]))
temp = face_found_cap(str(known_face_list[i]))
generate_sound(temp)
elif unknown_detected == 1:
temp = face_not_found_cap()
generate_sound(temp)
generate_sound("Do you want to add this face in your database")
addn(save)
elif known_detected == 0 and unknown_detected == 0:
print("No person found")
generate_sound("No person found!")
else:
print("Too many people")
generate_sound("Too many people.")
except Exception as e:
generate_sound("No recognisable face found!")
print(e)
if cv.waitKey(1) & 0xFF == 27: # ASCII for Esc Key
break
else:
break
cap.release()
cv.destroyAllWindows()