-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain_form.py
165 lines (139 loc) · 6.47 KB
/
Main_form.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import tkinter
from cv2 import cv2
import PIL.Image, PIL.ImageTk
import time
import numpy as np
from functools import partial
from threading import Thread
from Facedetection import Face_detection as Fd
from Facerecognition import Face_recognition as Fr
from Objectdetection import Object_detection as Od
from SpeechRecognition import speech_to_text as St
from SpeechRecognition import text as Ts
import FaceRecognition_form as Fr
#def annotate(image):
class App:
def __init__(self, window, window_title, video_source=0):
self.window = window
self.window.geometry("750x1200")
self.window.title(window_title)
self.video_source = video_source
label=tkinter.Label(window,text="Camera", font=("Helvetica", 12) )
label.place(x=80, y=30)
var1 = tkinter.StringVar(window)
var1.set("--select--")
option = tkinter.OptionMenu(self.window, var1, " --select--", "webcam", "driodcam")
option.pack()
option.place(x=170, y=25)
label=tkinter.Label(window,text="Modules", font=("Helvetica", 12) )
label.place(x=520, y=30)
fd = tkinter.IntVar()
fr = tkinter.IntVar()
od = tkinter.IntVar()
ar = tkinter.IntVar()
fe = tkinter.IntVar()
sr = tkinter.IntVar()
ts = tkinter.IntVar()
st = tkinter.IntVar()
ng= tkinter.IntVar()
ii = tkinter.IntVar()
sg = tkinter.IntVar()
c1 = tkinter.Checkbutton(window, text='Face Detection',variable=fd, font=("Helvetica", 10))
c1.place(x=420, y=50)
c2 = tkinter.Checkbutton(window, text='Face Recognition',variable=fr, onvalue=1, offvalue=0, font=("Helvetica", 10))
c2.place(x=420, y=70)
c3 = tkinter.Checkbutton(window, text='Object Detection',variable=od, onvalue=1, offvalue=0, font=("Helvetica", 10))
c3.place(x=420, y=90)
c4 = tkinter.Checkbutton(window, text='Activity Recognition',variable=ar, font=("Helvetica", 10))
c4.place(x=420, y=110)
c5= tkinter.Checkbutton(window, text='Facial Expression',variable=fe, font=("Helvetica", 10))
c5.place(x=420, y=130)
c6 = tkinter.Checkbutton(window, text='Scene Recognition',variable=sr, font=("Helvetica", 10))
c6.place(x=420, y=150)
c7 = tkinter.Checkbutton(window, text='Text to speech',variable=ts, font=("Helvetica", 10))
c7.place(x=560, y=50)
c8 = tkinter.Checkbutton(window, text='speech to text',variable=st, font=("Helvetica", 10))
c8.place(x=560, y=70)
c9= tkinter.Checkbutton(window, text='Natural Language genartion',variable=ng, font=("Helvetica", 10))
c9.place(x=560, y=90)
c10 = tkinter.Checkbutton(window, text='Intent Identification',variable=ii, font=("Helvetica", 10))
c10.place(x=560, y=110)
c11 = tkinter.Checkbutton(window, text='Summary generation',variable=sg, font=("Helvetica", 10))
c11.place(x=560, y=130)
action_btnStart=tkinter.Button(window, text="Start Video", width=20, height=1, command=partial(self.start_video,od,st,ts,fd), font=("Helvetica", 11))
action_btnStart.place(x=70, y=150)
action_btnStop=tkinter.Button(window, text="Stop Video", width=20, height=1, command=self.stop_video, font=("Helvetica", 11))
action_btnStop.place(x=220, y=150)
self.text = tkinter.Text(fg="gray",font=("Helvetica", 10))
self.text.place(x=150,y=600,height=20,width=400)
self.text.insert(tkinter.END,"speechtotext/texttospeech")
self.text.configure(state=tkinter.DISABLED)
def on_click(event):
self.text.configure(state=tkinter.NORMAL)
self.text.delete('1.0', tkinter.END)
# make the callback only work once
self.text.unbind('<Button-1>', on_click_id)
on_click_id = self.text.bind('<Button-1>', on_click)
btn_register=tkinter.Button(window, text="Register Face", width=20, height=1,command=self.a, font=("Helvetica", 11))
btn_register.place(x=270, y=650)
self.window.mainloop()
def start_video(self,od,st,ts,fd):
self.vid = MyVideoCapture(self.video_source)
self.canvas = tkinter.Canvas(self.window,width = 600, height = 350)
self.canvas.pack(padx=20, pady=200)
self.delay = 10
self.update(od,st,ts,fd)
def stop_video(self):
#elf.vid.release()
'''def start_stop():
if btn_text=="Start":
action_btnStart.configure(text = "Stop")
#btn_text.set("Stop")
else:
action_btnStart.configure(text = "Start")'''
def update(self,od,st,ts,fd):
# Get a frame from the video source
ret, frame = self.vid.get_frame()
if(fd.get()):
frame=Fd.detectFace(frame)
if(od.get()):
frame=Od.detectObject(frame)
if(st.get()):
txt=St.recognizeSpeech()
self.text.configure(state=tkinter.NORMAL)
self.text.delete('1.0',tkinter.END)
self.text.insert(tkinter.END,txt)
if(ts.get()):
txt=self.text.get('1.0',tkinter.END)
Ts.text(txt)
if ret:
self.photo = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(frame))
self.canvas.create_image(0, 0, image = self.photo, anchor = tkinter.NW)
self.window.after(self.delay, self.update,od,st,ts,fd)
def a(self):
self.window.destroy()
Fr.regiserFace()
class MyVideoCapture:
def __init__(self, video_source=0):
self.vid = cv2.VideoCapture(video_source)
self.vid.set(cv2.CAP_PROP_BUFFERSIZE, 2)
if not self.vid.isOpened():
raise ValueError("Unable to open video source", video_source)
self.FPS = 1/30
self.FPS_MS = int(self.FPS * 1000)
def get_frame(self):
if self.vid.isOpened():
ret, frame = self.vid.read()
if ret:
# Return a boolean success flag and the current frame converted to BGR
return (ret, cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
else:
return (ret, None)
else:
return (ret, None)
# Release the video source when the object is destroyed
def __del__(self):
if self.vid.isOpened():
self.vid.release()
# Create a window and pass it to the Application object
App(tkinter.Tk(), "Conversational Application")