-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
112 lines (89 loc) · 3.46 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
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMainWindow, QApplication, QFileDialog
from PyQt5.uic import loadUi
from PyQt5 import QtGui
import torch
import cv2
model = torch.hub.load('ultralytics/yolov5', 'custom', path='model/best-6.pt')
class Agricorn(QMainWindow):
def __init__(self):
super(Agricorn, self).__init__()
loadUi("ui/start.ui", self)
self.started.clicked.connect(self.gotodashboard)
self.about_us.clicked.connect(self.gotoaboutus)
def gotodashboard(self):
halamanutama = Dashboard()
widget.addWidget(halamanutama)
widget.setCurrentIndex(widget.currentIndex() + 1)
def gotoaboutus(self):
aboutwindow = AboutUs()
widget.addWidget(aboutwindow)
widget.setCurrentIndex(widget.currentIndex() + 1)
class Dashboard(QMainWindow):
def __init__(self):
super(Dashboard, self).__init__()
self.jumlah = None
self.penanganan = None
loadUi("ui/dashboard2.ui", self)
self.UploadImage.clicked.connect(self.uploadfoto)
self.Kembali.clicked.connect(self.gotostart)
def uploadfoto(self):
namaf = QFileDialog.getOpenFileName(self, 'Pilih file gambar', 'c:')
filename = namaf[0].split('/')[-1]
if filename:
result = model(namaf[0], size=640)
result.save(save_dir='result/')
deteksi = result.pandas().xyxy[0].to_dict()
#print(deteksi)
print(len(deteksi["name"]))
jumlah = len(deteksi["name"])
if len(deteksi["name"]) != 0:
print('Result is not empty')
print(deteksi)
deteksi = deteksi["name"][0]
deteksi = str(deteksi)
print(deteksi)
self.hasil.setText(deteksi.upper())
self.jumlah.setText(str(jumlah))
if deteksi == 'hawar':
self.penanganan.setPixmap(QtGui.QPixmap('data/hawar.png'))
elif deteksi == 'karat':
self.penanganan.setPixmap(QtGui.QPixmap('data/karat.png'))
elif deteksi == 'bercak':
self.penanganan.setPixmap(QtGui.QPixmap('data/bercak.png'))
else:
print('Result is empty')
self.hasil.setText('Unknown')
self.jumlah.setText('Null')
self.penanganan.setPixmap(QtGui.QPixmap('data/error.png'))
img = cv2.imread(f'result/{filename}', cv2.IMREAD_UNCHANGED)
h = 631
w = 491
s = (h, w)
resized = cv2.resize(img, s, interpolation=cv2.INTER_AREA)
cv2.imwrite('result2.jpg', resized)
self.image.setPixmap(QtGui.QPixmap('result2.jpg'))
else:
pass
def gotostart(self):
startwindow = Agricorn()
widget.addWidget(startwindow)
widget.setCurrentIndex(widget.currentIndex() + 1)
class AboutUs(QMainWindow):
def __init__(self):
super(AboutUs, self).__init__()
loadUi("ui/window_about.ui", self)
self.Kembali.clicked.connect(self.gotohomepage)
def gotohomepage(self):
mainwindow = Agricorn()
widget.addWidget(mainwindow)
widget.setCurrentIndex(widget.currentIndex() + 1)
app = QApplication(sys.argv)
mainwindow = Agricorn()
widget = QtWidgets.QStackedWidget()
widget.addWidget(mainwindow)
widget.setFixedWidth(911)
widget.setFixedHeight(600)
widget.show()
sys.exit(app.exec_())