-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest3.py
74 lines (59 loc) · 2.84 KB
/
test3.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
from PyQt5 import QtCore, QtGui, QtWidgets
import cv2
from img_procces import find_roi, roi_img_predict
class Test3(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setFixedSize(850, 592)
MainWindow.setGeometry(480, 231, 850, 592)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.final_img = QtWidgets.QLabel(self.centralwidget)
self.final_img.setGeometry(QtCore.QRect(0, 0, 850, 541))
self.final_img.setText("")
self.final_img.setPixmap(QtGui.QPixmap("dependencies/images/start2.png"))
self.final_img.setScaledContents(True)
self.final_img.setObjectName("final_img")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 850, 26))
self.menubar.setObjectName("menubar")
self.menuLoad_img = QtWidgets.QMenu(self.menubar)
self.menuLoad_img.setObjectName("menuLoad_img")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionLoad_image = QtWidgets.QAction(MainWindow)
self.actionLoad_image.setObjectName("actionLoad_image")
self.menuLoad_img.addAction(self.actionLoad_image)
self.menubar.addAction(self.menuLoad_img.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.menuLoad_img.triggered.connect(self.load_and_predict)
def find_path(self, label):
slovo = ""
reversed_slovo = ""
for i in range(len(label)):
i += 1
if label[-i] == "/":
break
slovo = slovo + label[-i]
reversed_slovo = "".join(reversed(slovo))
final_name = "dependencies/test_imgs/" + reversed_slovo
return final_name
def load_and_predict(self):
imagePath, _ = QtWidgets.QFileDialog.getOpenFileName()
if imagePath != "":
path = self.find_path(imagePath)
img_to_process = cv2.imread(path)
img = cv2.resize(img_to_process, (390, 293))
img = find_roi(img)
roi_img_predict(img)
self.final_img.setPixmap(QtGui.QPixmap("./dependencies/images/predict3.jpg"))
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "test3-gui"))
self.menuLoad_img.setTitle(_translate("MainWindow", "Load"))
self.actionLoad_image.setText(_translate("MainWindow", "Load image"))
self.actionLoad_image.setShortcut(_translate("MainWindow", "Ctrl+L"))