프로젝트

일반

사용자정보

개정판 6c9f6e02

ID6c9f6e026b8bad7c01047a32e75a5029a90b922e
상위 4967d6d0
하위 43a3463c

백흠경이(가) 6년 이상 전에 추가함

Implementing issue #584: show progress while recognizing text

차이점 보기:

DTI_PID/DTI_PID/HMBDialog.py
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
DTI_PID/DTI_PID/HMB_UI.py
90 90
        self.horizontalLayout = QtWidgets.QHBoxLayout()
91 91
        self.horizontalLayout.setObjectName("horizontalLayout")
92 92
        self.lineEditHMBArea = QtWidgets.QLineEdit(self.groupBoxHMBData)
93
        self.lineEditHMBArea.setMaximumSize(QtCore.QSize(150, 16777215))
93 94
        self.lineEditHMBArea.setObjectName("lineEditHMBArea")
94 95
        self.horizontalLayout.addWidget(self.lineEditHMBArea)
95 96
        self.pushButtonHMBArea = QtWidgets.QPushButton(self.groupBoxHMBData)
......
100 101
        self.pushButtonRecognizeText.setMaximumSize(QtCore.QSize(84, 16777215))
101 102
        self.pushButtonRecognizeText.setObjectName("pushButtonRecognizeText")
102 103
        self.horizontalLayout.addWidget(self.pushButtonRecognizeText, 0, QtCore.Qt.AlignRight)
104
        self.progressBar = QtWidgets.QProgressBar(self.groupBoxHMBData)
105
        self.progressBar.setProperty("value", 0)
106
        self.progressBar.setObjectName("progressBar")
107
        self.horizontalLayout.addWidget(self.progressBar)
103 108
        self.verticalLayout.addLayout(self.horizontalLayout)
104 109
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
105 110
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
DTI_PID/DTI_PID/TextDetector.py
200 200
                        appDocData.activeDrawing.setAttr('Unit', text[0].getText())
201 201
                # up to here
202 202

  
203
                #area = appDocData.getArea('Drawing')
204 203
                for tInfo in tInfoList:
205 204
                    if tInfo.getW() >= MIN_TEXT_SIZE or tInfo.getH() >= MIN_TEXT_SIZE:
206 205
                        x = tInfo.getX() - round(offset[0])
DTI_PID/DTI_PID/UI/HMB.ui
179 179
          <item>
180 180
           <layout class="QHBoxLayout" name="horizontalLayout">
181 181
            <item>
182
             <widget class="QLineEdit" name="lineEditHMBArea"/>
182
             <widget class="QLineEdit" name="lineEditHMBArea">
183
              <property name="maximumSize">
184
               <size>
185
                <width>150</width>
186
                <height>16777215</height>
187
               </size>
188
              </property>
189
             </widget>
183 190
            </item>
184 191
            <item>
185 192
             <widget class="QPushButton" name="pushButtonHMBArea">
......
207 214
              </property>
208 215
             </widget>
209 216
            </item>
217
            <item>
218
             <widget class="QProgressBar" name="progressBar">
219
              <property name="value">
220
               <number>0</number>
221
              </property>
222
             </widget>
223
            </item>
210 224
           </layout>
211 225
          </item>
212 226
          <item>

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)