-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
140 lines (119 loc) · 3.89 KB
/
main.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
import sys
from PyQt5 import QtWidgets, uic
from PyQt5.QtGui import QPixmap, QImage
from PyQt5.QtCore import QTimer, qVersion
import numpy as np
import video
import audio
import pyqtgraph as pg
import threading
import time
class myThreadVideo (threading.Thread):
def __init__(self, threadID):
threading.Thread.__init__(self)
self.threadID = threadID
self.stopped=False
def stop(self):
self.stopped = True
def run(self):
while True:
if self.stopped:
self.stopped=False
cam.close()
return
grabFrame()
time.sleep(0.1)
# Convert a Mat to a Pixmap
def img2pixmap(image):
height, width, channel = image.shape
bytesPerLine = 3 * width
qimage = QImage(image.data, width, height, bytesPerLine, QImage.Format_BGR888)
pixmap = QPixmap.fromImage(qimage)
return pixmap
# Cyclic capture image
def grabFrame():
cap=cam.capture()
image = cam.classify(cap)
window.label_videoCam.setPixmap(img2pixmap(image))
# Cyclic capture sound
def recording():
global mic, total_data, max_hold
#raw_data = mic.record()
#raw_data = mic.get_audio_input_stream()
raw_data,lastSpeaker,last_keyword = mic.get_frames()
'''PyQtGraph plot'''
# data_sample = np.fromstring(raw_data, dtype=np.int16) #convert raw bytes to interger
#total_data = np.concatenate([total_data, data_sample])
if len(raw_data) > 0:
amplitude = np.hstack(raw_data)
if len(amplitude) > audio.MAX_PLOT_SIZE:
amplitude = amplitude[audio.CHUNK:]
window.lineEdit_lastSpeakerId.setText(lastSpeaker)
window.lineEdit_lastKeyword.setText(last_keyword)
audio_waveform.setData(amplitude)
#lastSpeaker,last_keyword=mic.get_results()
#window.lineEdit_lastSpeakerId.setText(lastSpeaker)
#window.lineEdit_lastKeyword.setText(last_keyword)
# Starts image capture
def on_cameraON_clicked():
window.btn_cameraOn.setEnabled(False)
window.btn_cameraOff.setEnabled(True)
window.btn_screenshot.setEnabled(True)
cam.open(0);
global thread1
thread1= myThreadVideo(1)
thread1.start()
# Stops image capture
def on_cameraOFF_clicked():
window.btn_cameraOff.setEnabled(False)
window.btn_cameraOn.setEnabled(True)
window.btn_screenshot.setEnabled(False)
thread1.stop()
# Starts sound capture
def on_micOn_clicked():
window.btn_micOn.setEnabled(False)
window.btn_micOff.setEnabled(True)
mic.open()
qtimerRecord.start()
# Stops sound capture
def on_micOff_clicked():
window.btn_micOn.setEnabled(True)
window.btn_micOff.setEnabled(False)
qtimerRecord.stop()
mic.close()
mic.save("file.wav")
def on_screenshot():
cam.screenshot()
def closeEvent():
print("close")
# Creation of the camera
cam = video.Video()
# Creation of the micro
mic = audio.Audio()
app = QtWidgets.QApplication(sys.argv)
window = uic.loadUi("prototype.ui")
#Signals
window.btn_cameraOn.clicked.connect(on_cameraON_clicked)
window.btn_cameraOn.setEnabled(True)
window.btn_cameraOff.clicked.connect(on_cameraOFF_clicked)
window.btn_cameraOff.setEnabled(False)
window.btn_micOn.clicked.connect(on_micOn_clicked)
window.btn_micOn.setEnabled(True)
window.btn_micOff.clicked.connect(on_micOff_clicked)
window.btn_micOff.setEnabled(False)
window.label_videoCam.setScaledContents(True)
window.btn_screenshot.clicked.connect(on_screenshot)
window.btn_screenshot.setEnabled(False)
# Audio plot time domain waveform
audio_plot = window.plotWidget
pg.PlotWidget.getPlotItem(audio_plot).setTitle("Audio Signal")
pg.PlotWidget.getPlotItem(audio_plot).showGrid(True, True)
pg.PlotWidget.getPlotItem(audio_plot).addLegend()
pg.PlotWidget.setBackground(audio_plot,'w')
audio_waveform = audio_plot.plot(pen=(24, 215, 248), name = "Waveform")
total_data = []
# Micro timer
qtimerRecord = QTimer()
qtimerRecord.timeout.connect(recording)
window.show()
app.exec()