/
main_windows.py
84 lines (65 loc) · 2.72 KB
/
main_windows.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
__author__ = 'KDQ'
import sys
from PyQt4 import QtGui, QtCore, Qt
from main_camera import Combine
from display_result import Display
import os
from PyQt4.QtCore import Qt
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
if os.path.exists('./temp') == False:
os.mkdir('./temp')
# self._action()
self.init()
# self.right._open('./temp/default.jpg')
def init(self):
# self.showMaximized()
self.resize(1200, 500)
self.setWindowTitle('FaceFrameWork')
# set split layout
self.split = QtGui.QSplitter(Qt.Horizontal, self)
# left widget is camera widget, this widget deal with take photos through OpenCV Lib
# ans transfer OpenCV Pic to PyQt4 QImage, then use QPainter to show PyQt Pic
self.left = Combine(self.split)
# right widget is display widget, this widget deal with process face detection algorithm,
# and show result in it
self.right = Display(self.split)
self.split.setStretchFactor(1, 1)
self.setCentralWidget(self.split)
# this is menu bar, in this instance, just use one to load pic
self._action()
menu = self.menuBar()
file = menu.addMenu('File')
action = menu.addMenu('Action')
file.addAction(self._open_file)
file.addAction(self._close_file)
action.addAction(self._photo)
action.addAction(self._start)
action.addAction(self._pause)
def _action(self):
self._open_file = QtGui.QAction('Open', self)
self._open_file.setShortcut('Ctrl+O')
self._open_file.triggered.connect(self._open)
self._close_file = QtGui.QAction('Close', self)
self._close_file.triggered.connect(self.close)
self._photo = QtGui.QAction('Photo', self)
self._photo.setShortcut('Ctrl+Q')
self._photo.triggered.connect(lambda :self.left.down._take_photo())
self._start = QtGui.QAction('Start', self)
self._start.setShortcut('Ctrl+S')
self._start.triggered.connect(lambda :self.left.down._start())
self._pause = QtGui.QAction('Pause', self)
self._pause.setShortcut('Ctrl+P')
self._pause.triggered.connect(lambda :self.left.down._pause())
def _open(self):
file_name = unicode(QtGui.QFileDialog().getOpenFileName(self,'Open', self.tr(''), self.tr('*')))
if len(file_name) == 0:
return False
self.right._open(file_name)
# Show pic in right widget and process face detection algorithm
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
main_window = MainWindow()
main_window.show()
sys.exit(app.exec_())