-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainWindow.py
123 lines (107 loc) · 4.5 KB
/
mainWindow.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
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'main.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import cv2
import clasterWindow
import offer
import claster
import algorithm
import scrapping
import allegro_api
import clastersWindow
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowTitle("Klasyfikacja obrazów")
self.setupUi()
def setupUi(self):
self.setObjectName("Dialog")
self.resize(225, 213)
self.buttonBox = QtWidgets.QDialogButtonBox(self)
self.buttonBox.setGeometry(QtCore.QRect(-430, 160, 621, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.checkBox = QtWidgets.QCheckBox(self)
self.checkBox.setGeometry(QtCore.QRect(40, 50, 171, 21))
font = QtGui.QFont()
font.setPointSize(10)
self.checkBox.setFont(font)
self.checkBox.setCheckable(True)
self.checkBox.setChecked(True)
self.checkBox_2 = QtWidgets.QCheckBox(self)
self.checkBox_2.setGeometry(QtCore.QRect(40, 80, 161, 16))
font = QtGui.QFont()
font.setPointSize(10)
self.checkBox_2.setFont(font)
self.checkBox_2.setCheckable(True)
self.checkBox_2.setChecked(True)
self.label = QtWidgets.QLabel(self)
self.label.setGeometry(QtCore.QRect(40, 10, 181, 31))
font = QtGui.QFont()
font.setPointSize(12)
self.label.setFont(font)
self.retranslateUi(self)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
QtCore.QMetaObject.connectSlotsByName(self)
self.progressBar = QtWidgets.QProgressBar(self)
self.progressBar.setGeometry(QtCore.QRect(60, 120, 118, 23))
self.progressBar.setProperty("value", 0)
self.progressBar.setTextVisible(True)
self.progressBar.setInvertedAppearance(False)
self.show()
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.checkBox.setText(_translate("Dialog", "Podobieństwo obrazów"))
self.checkBox_2.setText(_translate("Dialog", "Podobieństwo tekstu"))
self.label.setText(_translate("Dialog", "Kryteria klasteryzacji:"))
def reject(self):
self.close();
@QtCore.pyqtSlot()
def notify(self, val):
self.progressBar.setProperty("value", val)
def accept(self):
offers = []
self.progressBar.setProperty("value", 0)
# texts = scrapping.download_and_get_text()
# texts = allegro_api.download_and_get_texts(self.progressBar, 100)
texts = allegro_api.import_texts("names.txt")
words_vector = scrapping.create_words_vector(texts)
images = {}
for i in range(len(texts)):
new_offer = offer.Offer("imgs/" + str(i + 1) + ".jpg", texts[i])
new_offer.text_to_vector(words_vector)
offers.append(new_offer)
image = cv2.imread("imgs/" + str(i + 1) + ".jpg")
images[str(i + 1) + ".jpg"] = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
self.progressBar.setProperty("value", 20+((i+1)/len(texts))*20)
claster_array = []
i = 0
pre_clasters = algorithm.pre_clastering(offers, self.checkBox.isChecked(), self.checkBox_2.isChecked())
for e in pre_clasters:
i += 1
claster_array.append(claster.Claster(e))
self.progressBar.setProperty("value", 40 + (i/len(offers))*10)
x = algorithm.algorithm(claster_array, self.checkBox.isChecked(), self.checkBox_2.isChecked(), self.progressBar, 10)
self.windows = {}
i = 0
for a in x:
self.windows[i] = clasterWindow.Ui_Dialog()
self.windows[i].setupUi(a.list)
# self.windows[i].show()
i += 1
self.progressBar.setProperty("value", 90 + (i/len(x))*10)
self.clasterWindow = clastersWindow.Ui_Dialog()
self.clasterWindow.setupUi(self.windows)
self.clasterWindow.show()
def init():
import sys
app = QtWidgets.QApplication(sys.argv)
ui = MainWindow()
app.exec()