Skip to content

Commit

Permalink
Add GUI with fool protection methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Dostoyewski committed Apr 25, 2022
1 parent 040565f commit e06da4f
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
92 changes: 92 additions & 0 deletions gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import mimetypes
import sys

from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QFileDialog, QMessageBox

from main import ARUCODetector

mimetypes.init()


def isMediaFile(fileName):
"""
Check if file is video
:param fileName: path to file
:return:
"""
mimestart = mimetypes.guess_type(fileName)[0]
if mimestart != None:
mimestart = mimestart.split('/')[0]
if mimestart in ['video']:
return True
return False


class App(QMainWindow):

def __init__(self):
super().__init__()
# Time axis
self.left = 10
self.top = 50
self.title = 'Lab4 0.8'
# bar with buttons and checkbox
self.filepath = ''
self.btnStart = QPushButton('Start', self)
self.btnLoad = QPushButton('Загрузить видео', self)

self.infoLabel = QLabel('©Dostoyewski & Amgaran, THEORHECH INC.\n'
'All output files will be saved to\napp launch directory', self)
self.statusLabel = QLabel('', self)

self.widthp = 384
self.heightp = 240

self.initUI()

def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.widthp, self.heightp)
self.btnLoad.move(100, 20)
self.btnLoad.clicked.connect(self.openFileNameDialog)
self.statusLabel.move(100, 100)

self.btnStart.move(100, 70)

self.infoLabel.resize(250, 40)
self.infoLabel.move(100, 180)

self.btnStart.clicked.connect(self.start)

self.show()

def start(self):
detector = ARUCODetector(self.filepath)
self.statusLabel.setText('Обрабатываю...')
detector.run()
self.statusLabel.setText('Готово!')

def openFileNameDialog(self):
"""
Select scenario file
:return:
"""
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
filename, _ = QFileDialog.getOpenFileNames(self, "Загрузить видео", "", "", options=options)
if filename and isMediaFile(filename[0]):
self.filepath = filename[0]
else:
msg = QMessageBox()
msg.setIcon(QMessageBox.Critical)
msg.setText("Вы уверены, что это видео?")
msg.setInformativeText('Хм. По-моему, это какая-то ботва, а не видео. Перепроверьте то, что вы '
'скармливаете программе. Лучше всего *.mp4.')
msg.setWindowTitle("Эй, помедленнее!")
msg.exec_()


if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def run(self):
while True:
success, image = self.cap.read()
if image is None:
cv.destroyAllWindows()
break
key = cv.waitKey(1) & 0xFF
if (key == 27) or (key == ord('q')):
Expand All @@ -29,7 +30,7 @@ def run(self):
image = cv.circle(image, coords, 20, (255, 0, 0), -1)
out_d[str(idd[0]) + 'x'], out_d[str(idd[0]) + 'y'] = coords[0], coords[1]
self.res_df = self.res_df.append(out_d, ignore_index=True)
cv.imshow("original", image)
cv.imshow("Detection result", image)
else:
continue
self.res_df.to_excel('./out.xlsx')
Expand Down

0 comments on commit e06da4f

Please sign in to comment.