-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMAIN_RUN.py
81 lines (66 loc) · 2.68 KB
/
MAIN_RUN.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
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 gensoundgtts import generate_sound
import tkinter as tk
def saveface():
x1 = entry1.get()
print(x1 + ' face saved')
root.destroy()
cv.imwrite(r"images//" +
str(x1) + ".jpg", frame)
data = {x1: f_part.img_to_encoding(
"images//" + str(x1) + ".jpg").tolist()}
f_part.digi_db.insert_one(data)
def ignoreface():
print("Not saved")
root.destroy()
cap = cv.VideoCapture('Sample Videos/test.mp4')
while True:
ret, frame = cap.read()
if ret:
font = cv.FONT_HERSHEY_SIMPLEX
cv.imshow("Video", frame)
if cv.waitKey(5) == ord('p'):
# print(K.image_data_format())
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(5) == ord('f'):
cv.imwrite('./test.jpg', frame)
try:
dis, name = f_part.who_is_it('./test.jpg')
print(str(dis)+","+name)
temp = face_found_cap(name)
generate_sound(temp)
if(name == 'unknown'):
temp = face_not_found_cap()
generate_sound(temp)
root = tk.Tk()
large_font = ('Times New Roman', 14)
canvas1 = tk.Canvas(root, width=300, height=200)
canvas1.pack()
label = tk.Label(root, text='Enter the Name')
canvas1.create_window(140, 50, window=label)
entry1Var = tk.StringVar(value='')
entry1 = tk.Entry(root, textvariable=entry1Var, font=large_font)
canvas1.create_window(150, 90, window=entry1)
button1 = tk.Button(text='SAVE', command=saveface)
button2 = tk.Button(text='IGNORE', command=ignoreface)
canvas1.create_window(100, 150, window=button1)
canvas1.create_window(180, 150, window=button2)
root.mainloop()
except:
print("No recognizable face detected")
generate_sound("No recognizable face detected")
if cv.waitKey(1) & 0xFF == 27: # ASCII for Esc Key
break
else:
break
cap.release()
cv.destroyAllWindows()