-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainWindow.py
More file actions
172 lines (136 loc) · 6.65 KB
/
mainWindow.py
File metadata and controls
172 lines (136 loc) · 6.65 KB
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
166
167
168
169
170
171
172
import sys
import Const
import numpy as np
from Process_video import process_video
from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
# initialize variables
self.scanOption = Const.SEPARATE_OPTION
self.sourceOption = Const.RECORD_VIDEO
self.isStopProcess = False
# set window properties
self.setGeometry(400, 50, 660, 660) # x_position, y_position, width, height
self.setWindowTitle("LessonShot")
self.setWindowIcon(QtGui.QIcon("Resources/board_icon.png"))
# set board image
self.boardImg = QtWidgets.QLabel(self)
self.boardImg.setGeometry(QtCore.QRect(10, 10, 640, 480))
self.boardImg.setPixmap(QtGui.QPixmap("Resources/board_img.png"))
self.boardImg.setScaledContents(True)
# set control frame
self.controlFrame = QtWidgets.QFrame(self)
self.controlFrame.setGeometry(QtCore.QRect(10, 490, 640, 160))
font = QtGui.QFont()
font.setPointSize(12)
self.controlFrame.setFont(font)
self.controlFrame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.controlFrame.setFrameShadow(QtWidgets.QFrame.Raised)
self.scanOptionL = QtWidgets.QLabel(self.controlFrame)
self.scanOptionL.setGeometry(QtCore.QRect(10, 10, 92, 19))
self.scanOptionL.setText("Scan Option:")
self.sourceOptionL = QtWidgets.QLabel(self.controlFrame)
self.sourceOptionL.setGeometry(QtCore.QRect(10, 40, 54, 19))
self.sourceOptionL.setText("Source Option:")
self.sourceOptionL.adjustSize()
self.sourceLocationL = QtWidgets.QLabel(self.controlFrame)
self.sourceLocationL.setGeometry(QtCore.QRect(10, 70, 118, 19))
self.sourceLocationL.setText("Source Location:")
self.outputLocationL = QtWidgets.QLabel(self.controlFrame)
self.outputLocationL.setGeometry(QtCore.QRect(10, 100, 119, 19))
self.outputLocationL.setText("Output Location:")
self.sourceTL = QtWidgets.QLineEdit(self.controlFrame)
self.sourceTL.setGeometry(QtCore.QRect(140, 70, 400, 20))
self.outputTL = QtWidgets.QLineEdit(self.controlFrame)
self.outputTL.setGeometry(QtCore.QRect(140, 100, 400, 20))
self.sourceBrowseB = QtWidgets.QPushButton(self.controlFrame)
self.sourceBrowseB.setGeometry(QtCore.QRect(550, 70, 75, 23))
self.sourceBrowseB.setText("Browse")
self.sourceBrowseB.clicked.connect(self.select_file)
self.outputBrowseB = QtWidgets.QPushButton(self.controlFrame)
self.outputBrowseB.setGeometry(QtCore.QRect(550, 100, 75, 23))
self.outputBrowseB.setText("Browse")
self.outputBrowseB.clicked.connect(self.select_folder)
self.sourceOptionCB = QtWidgets.QComboBox(self.controlFrame)
self.sourceOptionCB.setGeometry(QtCore.QRect(140, 40, 400, 22))
self.sourceOptionCB.setObjectName("sourceCB")
self.sourceOptionCB.addItem("Recorde Video (.mp4/ .avi)")
self.sourceOptionCB.addItem("Camera")
self.sourceOptionCB.activated.connect(self.set_source_option)
self.scanOptionCB = QtWidgets.QComboBox(self.controlFrame)
self.scanOptionCB.setGeometry(QtCore.QRect(140, 10, 400, 22))
self.scanOptionCB.addItem("Separate - cut image every write")
self.scanOptionCB.addItem("Append - cut image every time the board full")
self.scanOptionCB.activated.connect(self.set_scan_option)
self.startB = QtWidgets.QPushButton(self.controlFrame)
self.startB.setGeometry(QtCore.QRect(200, 125, 124, 29))
self.startB.setText("Start Processing")
self.startB.clicked.connect(self.start_process)
self.stopB = QtWidgets.QPushButton(self.controlFrame)
self.stopB.setGeometry(QtCore.QRect(335, 125, 124, 29))
self.stopB.setText("Stop Process")
self.stopB.clicked.connect(self.stop_process)
self.stopB.setEnabled(False)
def start_process(self):
source = self.sourceTL.text()
output_path = self.outputTL.text()
self.stopB.setEnabled(True)
self.startB.setEnabled(False)
process_video(self, source, output_path, self.scanOption, self.sourceOption)
self.isStopProcess = False
self.stopB.setEnabled(False)
self.startB.setEnabled(True)
self.boardImg.setPixmap(QtGui.QPixmap("Resources/board_img.png"))
def stop_process(self):
self.isStopProcess = True
def set_source_option(self):
option = self.sourceOptionCB.currentText()
if option.startswith("Recorde Video"):
self.sourceOption = Const.RECORD_VIDEO
self.sourceLocationL.setText("Source Location:")
self.sourceLocationL.adjustSize()
self.sourceBrowseB.setEnabled(True)
elif option.startswith("Camera"):
self.sourceOption = Const.CAMERA
self.sourceLocationL.setText("Camera Number:")
self.sourceLocationL.adjustSize()
self.sourceBrowseB.setEnabled(False)
def set_scan_option(self):
option = self.scanOptionCB.currentText()
if option.startswith("Separate"):
self.scanOption = Const.SEPARATE_OPTION
elif option.startswith("Append"):
self.scanOption = Const.APPEND_OPTION
def set_board_img(self, current_img):
# convert and set the image
h = current_img.shape[0]
w = current_img.shape[1]
ratio = h/w
fixed_h = h
fixed_w = w
if ratio > 3/4:
fixed_w = round((4/3) * h)
elif ratio < 3/4:
fixed_h = round((3/4) * w)
fixed_img = np.full((fixed_h, fixed_w, 3), 125, dtype=np.uint8)
fixed_img[(fixed_h - h) // 2: h + (fixed_h - h) // 2, (fixed_w - w) // 2: w + (fixed_w - w) // 2] = current_img
q_image = QtGui.QImage(fixed_img.data, fixed_w, fixed_h, 3 * fixed_w, QtGui.QImage.Format_BGR888)
pixmap = QtGui.QPixmap(q_image)
self.boardImg.setPixmap(pixmap)
def select_file(self):
file_path = QFileDialog.getOpenFileName(self, 'Open file', 'c:\\', "Video files (*.mp4 *.avi)")[0]
self.sourceTL.setText(file_path)
def select_folder(self):
folder_path = QFileDialog.getExistingDirectory()
self.outputTL.setText(folder_path)
def source_error(self, error_string):
self.sourceTL.setText(str(error_string))
def output_error(self, error_string):
self.outputTL.setText(str(error_string))
if __name__ == "__main__":
app = QApplication(sys.argv)
win = MainWindow()
win.show()
sys.exit(app.exec())