20 |
20 |
from QGraphicsBoundingBoxItem import QGraphicsBoundingBoxItem
|
21 |
21 |
import Configuration_Area_UI
|
22 |
22 |
|
|
23 |
class Worker(QObject):
|
|
24 |
from PyQt5.QtCore import QThread
|
|
25 |
from PyQt5.QtWidgets import QApplication, QLabel, QWidget, QGridLayout, QListWidget
|
|
26 |
import sys
|
|
27 |
|
|
28 |
'''
|
|
29 |
@brief signals
|
|
30 |
'''
|
|
31 |
finished = pyqtSignal()
|
|
32 |
intReady = pyqtSignal(int)
|
|
33 |
recognizeText = pyqtSignal(QObject)
|
|
34 |
updateProgress = pyqtSignal(int)
|
|
35 |
|
|
36 |
'''
|
|
37 |
@history 2018.05.25 Jeongwoo Add if-statements by isSymbolTextChecked and isLineChecked variable
|
|
38 |
2018.05.28 Jeongwoo Add Parameter 'xmlPath[0]'
|
|
39 |
2018.05.30 Jeongwoo Remove import recognizeLine and self.xmlPath and remove parameter on recognizeLine.emit() (xmlPath)
|
|
40 |
Change signal name (drawDetectedItems)
|
|
41 |
'''
|
|
42 |
def work(self): # A slot takes no params
|
|
43 |
try:
|
|
44 |
self.recognizeText.emit(self)
|
|
45 |
except Exception as ex:
|
|
46 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
47 |
|
23 |
48 |
class QHMBDialog(QDialog):
|
24 |
49 |
def __init__(self, parent):
|
25 |
50 |
from HMB_UI import Ui_HMBDialog
|
... | ... | |
131 |
156 |
@date 2018.07.11
|
132 |
157 |
'''
|
133 |
158 |
def onRecognizeText(self):
|
134 |
|
import re
|
|
159 |
if len(self.ui.lineEditColumnWidth.text()) > 0 and len(self.ui.lineEditRowHeight.text()) > 0 and len(self.ui.lineEditHMBArea.text()) > 0:
|
|
160 |
self.ui.buttonBox.setEnabled(False)
|
|
161 |
self.ui.progressBar.setValue(0)
|
|
162 |
self.startThread()
|
|
163 |
|
|
164 |
'''
|
|
165 |
@brief recognize text in selected area
|
|
166 |
@author humkyung
|
|
167 |
@date 2018.07.11
|
|
168 |
'''
|
|
169 |
def recognizeText(self, worker):
|
135 |
170 |
from TextDetector import TextDetector
|
136 |
171 |
|
137 |
172 |
try:
|
138 |
|
columnWidth = float(self.ui.lineEditColumnWidth.text())
|
139 |
|
rowHeight = float(self.ui.lineEditRowHeight.text())
|
140 |
|
if columnWidth > 0 and rowHeight > 0:
|
141 |
|
textDetector = TextDetector()
|
142 |
|
found = re.findall('\d+', self.ui.lineEditHMBArea.text())
|
143 |
|
if len(found) == 4:
|
144 |
|
appDocData = AppDocData.instance()
|
145 |
|
area = [float(x) for x in found]
|
146 |
|
img = appDocData.imgSrc[round(area[1]):round(area[1]+area[3]), round(area[0]):round(area[0]+area[2])]
|
147 |
|
texts = textDetector.getTextAreaInfo(img, area[0], area[1])
|
148 |
|
textDetector.recognizeText(appDocData.imgSrc, (area[0], area[1]), texts, [], None, None, 0)
|
149 |
|
#texts = textDetector.recognizeTextInArea(appDocData.imgSrc, area)
|
150 |
|
columns = round(area[2] / columnWidth)
|
151 |
|
rows = round(area[3] / rowHeight)
|
152 |
|
fixedColumns = self.ui.tableWidgetHMBData.columnCount()
|
153 |
|
self.ui.tableWidgetHMBData.setColumnCount(fixedColumns + columns)
|
154 |
|
self.ui.tableWidgetHMBData.setRowCount(rows)
|
155 |
|
|
156 |
|
for text in textDetector.textInfoList:
|
157 |
|
item = QTableWidgetItem(text.getText())
|
158 |
|
col = int((text.x - area[0]) / columnWidth)
|
159 |
|
row = int((text.y - area[1]) / rowHeight)
|
160 |
|
self.ui.tableWidgetHMBData.setItem(row, fixedColumns + col, item)
|
|
173 |
appDocData = AppDocData.instance()
|
|
174 |
|
|
175 |
textDetector = TextDetector()
|
|
176 |
img = appDocData.imgSrc[round(worker.area[1]):round(worker.area[1]+worker.area[3]), round(worker.area[0]):round(worker.area[0]+worker.area[2])]
|
|
177 |
texts = textDetector.getTextAreaInfo(img, worker.area[0], worker.area[1])
|
|
178 |
textDetector.recognizeText(appDocData.imgSrc, (worker.area[0], worker.area[1]), texts, [], worker.updateProgress, None, len(texts))
|
|
179 |
worker.textInfoList = textDetector.textInfoList.copy()
|
161 |
180 |
except Exception as ex:
|
162 |
181 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
182 |
finally:
|
|
183 |
worker.finished.emit()
|
|
184 |
|
|
185 |
'''
|
|
186 |
@brief start thread
|
|
187 |
@author humkyung
|
|
188 |
@date 2018.07.12
|
|
189 |
'''
|
|
190 |
def startThread(self):
|
|
191 |
import re
|
|
192 |
|
|
193 |
self.ui.buttonBox.setDisabled(True)
|
|
194 |
|
|
195 |
# 1 - create Worker and Thread inside the Form
|
|
196 |
self.obj = Worker() # no parent!
|
|
197 |
self.obj.columnWidth = float(self.ui.lineEditColumnWidth.text())
|
|
198 |
self.obj.rowHeight = float(self.ui.lineEditRowHeight.text())
|
|
199 |
found = re.findall('\d+', self.ui.lineEditHMBArea.text())
|
|
200 |
self.obj.area = [float(x) for x in found]
|
|
201 |
self.thread = QThread() # no parent!
|
|
202 |
|
|
203 |
# 2 - Move the Worker object to the Thread object
|
|
204 |
self.obj.moveToThread(self.thread)
|
|
205 |
|
|
206 |
# 3 - Connect Worker Signals to the Thread slots
|
|
207 |
self.obj.finished.connect(self.thread.quit)
|
|
208 |
self.obj.recognizeText.connect(self.recognizeText)
|
|
209 |
self.obj.updateProgress.connect(self.updateProgress)
|
|
210 |
|
|
211 |
# 4 - Connect Thread started signal to Worker operational slot method
|
|
212 |
self.thread.started.connect(self.obj.work)
|
|
213 |
|
|
214 |
# 5 - Thread finished signal will close the app if you want!
|
|
215 |
self.thread.finished.connect(self.dlgExit)
|
|
216 |
|
|
217 |
# 6 - Start the thread
|
|
218 |
self.thread.start()
|
|
219 |
|
|
220 |
'''
|
|
221 |
@brief update progressbar with given value
|
|
222 |
@author humkyung
|
|
223 |
@date 2018.07.12
|
|
224 |
'''
|
|
225 |
def updateProgress(self, maxValue):
|
|
226 |
if maxValue != -1:
|
|
227 |
self.ui.progressBar.setMaximum(maxValue)
|
|
228 |
self.ui.progressBar.setValue(self.ui.progressBar.value() + 1)
|
|
229 |
else:
|
|
230 |
self.ui.progressBar.setValue(0)
|
|
231 |
|
|
232 |
'''
|
|
233 |
@brief set buttonbox's enabled flag
|
|
234 |
@author humkyung
|
|
235 |
@date 2018.07.12
|
|
236 |
'''
|
|
237 |
def dlgExit(self):
|
|
238 |
try:
|
|
239 |
columns = round(self.obj.area[2] / self.obj.columnWidth)
|
|
240 |
rows = round(self.obj.area[3] / self.obj.rowHeight)
|
|
241 |
fixedColumns = self.ui.tableWidgetHMBData.columnCount()
|
|
242 |
self.ui.tableWidgetHMBData.setColumnCount(fixedColumns + columns)
|
|
243 |
self.ui.tableWidgetHMBData.setRowCount(rows)
|
|
244 |
|
|
245 |
for text in self.obj.textInfoList:
|
|
246 |
item = QTableWidgetItem(text.getText())
|
|
247 |
col = int((text.x - self.obj.area[0]) / self.obj.columnWidth)
|
|
248 |
row = int((text.y - self.obj.area[1]) / self.obj.rowHeight)
|
|
249 |
self.ui.tableWidgetHMBData.setItem(row, fixedColumns + col, item)
|
|
250 |
|
|
251 |
self.ui.progressBar.setValue(self.ui.progressBar.maximum())
|
|
252 |
self.ui.buttonBox.setEnabled(True)
|
|
253 |
except Exception as ex:
|
|
254 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
255 |
finally:
|
|
256 |
pass
|
163 |
257 |
|
164 |
258 |
'''
|
165 |
259 |
@brief accept dialog
|