프로젝트

일반

사용자정보

개정판 a92bc8a0

IDa92bc8a01f6bcaf9fc16a3b8f5174ad9ad33d09a
상위 ee4fc60f
하위 d9cdb857

humkyung 이(가) 6년 이상 전에 추가함

Add Expand and Shrink size for recognizing text

차이점 보기:

DTI_PID/DTI_PID/Configuration_UI.py
1 1
# -*- coding: utf-8 -*-
2 2

  
3
# Form implementation generated from reading ui file 'Configuration.ui'
3
# Form implementation generated from reading ui file '.\ui\Configuration.ui'
4 4
#
5
# Created by: PyQt5 UI code generator 5.6
5
# Created by: PyQt5 UI code generator 5.10.1
6 6
#
7 7
# WARNING! All changes made in this file will be lost!
8 8

  
......
11 11
class Ui_ConfigurationDialog(object):
12 12
    def setupUi(self, ConfigurationDialog):
13 13
        ConfigurationDialog.setObjectName("ConfigurationDialog")
14
        ConfigurationDialog.resize(550, 502)
14
        ConfigurationDialog.resize(550, 560)
15 15
        font = QtGui.QFont()
16 16
        font.setFamily("맑은 고딕")
17 17
        ConfigurationDialog.setFont(font)
......
23 23
        self.Recognition = QtWidgets.QWidget()
24 24
        self.Recognition.setObjectName("Recognition")
25 25
        self.gridLayout_2 = QtWidgets.QGridLayout(self.Recognition)
26
        self.gridLayout_2.setContentsMargins(0, 0, 0, 0)
27 26
        self.gridLayout_2.setObjectName("gridLayout_2")
28 27
        self.groupBoxAttribute = QtWidgets.QGroupBox(self.Recognition)
29 28
        self.groupBoxAttribute.setObjectName("groupBoxAttribute")
......
181 180
        self.textAreaHelpLabel.setObjectName("textAreaHelpLabel")
182 181
        self.horizontalLayout_14.addWidget(self.textAreaHelpLabel)
183 182
        self.verticalLayout_5.addLayout(self.horizontalLayout_14)
183
        self.horizontalLayout_15 = QtWidgets.QHBoxLayout()
184
        self.horizontalLayout_15.setObjectName("horizontalLayout_15")
185
        self.label_20 = QtWidgets.QLabel(self.groupBoxText)
186
        self.label_20.setObjectName("label_20")
187
        self.horizontalLayout_15.addWidget(self.label_20)
188
        self.spinBoxExpandSize = QtWidgets.QSpinBox(self.groupBoxText)
189
        self.spinBoxExpandSize.setObjectName("spinBoxExpandSize")
190
        self.horizontalLayout_15.addWidget(self.spinBoxExpandSize)
191
        self.verticalLayout_5.addLayout(self.horizontalLayout_15)
192
        self.horizontalLayout_16 = QtWidgets.QHBoxLayout()
193
        self.horizontalLayout_16.setObjectName("horizontalLayout_16")
194
        self.label_21 = QtWidgets.QLabel(self.groupBoxText)
195
        self.label_21.setObjectName("label_21")
196
        self.horizontalLayout_16.addWidget(self.label_21)
197
        self.spinBoxShrinkSize = QtWidgets.QSpinBox(self.groupBoxText)
198
        self.spinBoxShrinkSize.setObjectName("spinBoxShrinkSize")
199
        self.horizontalLayout_16.addWidget(self.spinBoxShrinkSize)
200
        self.verticalLayout_5.addLayout(self.horizontalLayout_16)
184 201
        self.horizontalLayout_13 = QtWidgets.QHBoxLayout()
185 202
        self.horizontalLayout_13.setObjectName("horizontalLayout_13")
186 203
        self.label_17 = QtWidgets.QLabel(self.groupBoxText)
......
215 232
        self.tabTagNoRule = QtWidgets.QWidget()
216 233
        self.tabTagNoRule.setObjectName("tabTagNoRule")
217 234
        self.gridLayout_7 = QtWidgets.QGridLayout(self.tabTagNoRule)
218
        self.gridLayout_7.setContentsMargins(0, 0, 0, 0)
219 235
        self.gridLayout_7.setObjectName("gridLayout_7")
220 236
        self.groupBox_2 = QtWidgets.QGroupBox(self.tabTagNoRule)
221 237
        self.groupBox_2.setObjectName("groupBox_2")
......
311 327
        self.tabNominalPipeSize = QtWidgets.QWidget()
312 328
        self.tabNominalPipeSize.setObjectName("tabNominalPipeSize")
313 329
        self.gridLayout_4 = QtWidgets.QGridLayout(self.tabNominalPipeSize)
314
        self.gridLayout_4.setContentsMargins(0, 0, 0, 0)
315 330
        self.gridLayout_4.setObjectName("gridLayout_4")
316 331
        self.verticalLayout = QtWidgets.QVBoxLayout()
317 332
        self.verticalLayout.setObjectName("verticalLayout")
......
373 388
        self.label_19.setText(_translate("ConfigurationDialog", "텍스트 영역 검출 방식 : "))
374 389
        self.textAreaTypeARadioButton.setText(_translate("ConfigurationDialog", "Type A"))
375 390
        self.textAreaTypeBRadioButton.setText(_translate("ConfigurationDialog", "Type B"))
391
        self.label_20.setText(_translate("ConfigurationDialog", "팽창 크기 : "))
392
        self.label_21.setText(_translate("ConfigurationDialog", "침식 크기 : "))
376 393
        self.label_17.setText(_translate("ConfigurationDialog", "Minimum Text Size : "))
377 394
        self.label_18.setText(_translate("ConfigurationDialog", "Maximum Text Size : "))
378 395
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.Recognition), _translate("ConfigurationDialog", "인식"))
DTI_PID/DTI_PID/DTI_PID.py
1094 1094
    docData = AppDocData.instance()
1095 1095
    project = docData.getCurrentProject()
1096 1096

  
1097
    #configs = docData.getConfigs('Text Size', 'Min Text Size')
1098
    #self.ui.minTextSizeSpinBox.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.minTextSizeSpinBox.setValue(30)
1099 1097
    configs = docData.getConfigs('Text Size', 'Max Text Size')
1100 1098
    maxTextSize = int(configs[0].value) if 1 == len(configs) else 100
1101 1099

  
......
1106 1104
    for contour in contours:
1107 1105
        # remove too big one
1108 1106
        [x, y, w, h] = cv2.boundingRect(contour)
1109
        if (w > maxTextSize or h > maxTextSize): continue
1107
        if (w > maxTextSize and h > maxTextSize): continue
1110 1108

  
1111 1109
        area = cv2.contourArea(contour, True)
1112 1110
        if area >= 0:
......
1119 1117
    cv2.imwrite(filePath, contourImg)
1120 1118

  
1121 1119
    rects = []
1122
    eroded = cv2.erode(contourImg, np.ones((8,8), np.uint8))
1120
    configs = docData.getConfigs('Text Recognition', 'Expand Size')
1121
    expandSize = int(configs[0].value) if 1 == len(configs) else 10
1122
    eroded = cv2.erode(contourImg, np.ones((expandSize,expandSize), np.uint8))
1123
    
1124
    filePath = os.path.join(project.getTempPath(), 'eroded_OCR.png')
1125
    cv2.imwrite(filePath, eroded)
1126

  
1123 1127
    eroded = cv2.bitwise_not(eroded)
1124 1128
    image, contours, hierarchy = cv2.findContours(eroded, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)
1125 1129
    for contour in contours:
1126 1130
        area = cv2.contourArea(contour, True)
1127 1131
        if area < 0:
1128 1132
            [x, y, w, h] = cv2.boundingRect(contour)
1129
            if w < 10 and h < 10: continue; # skip too small one
1133
            if (w < 10 and h < 10) or (w > maxTextSize and h > maxTextSize): continue; # skip too small or big one
1130 1134
            
1131 1135
            img = contourImg[y:y+h, x:x+w]
1132 1136
            img = cv2.bitwise_not(img)
DTI_PID/DTI_PID/QConfigurationDialog.py
46 46
                    Jeongwoo 2018.05.18 read Small Line Minimum Length
47 47
                    Jeongwoo 2018.06.04 read Min/Max Text Size
48 48
                    Jeongwoo 2018.06.05 read Text Area Detection Method
49
                    humkyung 2018.06.20 add expand and shrink size for recognizing text
49 50
    '''
50 51
    def __init__(self, parent):
51 52
        QDialog.__init__(self, parent)
......
66 67
        else:
67 68
            self.ui.textAreaTypeBRadioButton.setChecked(True)
68 69

  
70
        configs = docData.getConfigs('Text Recognition', 'Expand Size')
71
        self.ui.spinBoxExpandSize.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxExpandSize.setValue(10)
72
        configs = docData.getConfigs('Text Recognition', 'Shrink Size')
73
        self.ui.spinBoxShrinkSize.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxShrinkSize.setValue(0)
74

  
69 75
        configs = docData.getConfigs('Text Size', 'Min Text Size')
70 76
        self.ui.minTextSizeSpinBox.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.minTextSizeSpinBox.setValue(30)
71 77
        configs = docData.getConfigs('Text Size', 'Max Text Size')
......
165 171
                    Jeongwoo 2018.05.18 save Small Line Minimum Length
166 172
                    Jeongwoo 2018.06.04 save Min/Max Text Size
167 173
                    Jeongwoo 2018.06.05 save Text Area Detection Method
174
                    humkyung 2018.06.20 save Expand and Shrink size for recognizing text
168 175
    '''
169 176
    def accept(self):
170 177
        try:
......
172 179

  
173 180
            configs = []
174 181
            configs.append(Config('Text Area', 'Text Area', 0 if self.ui.textAreaTypeARadioButton.isChecked() else 1))
182
            configs.append(Config('Text Recognition', 'Expand Size', self.ui.spinBoxExpandSize.value()))
183
            configs.append(Config('Text Recognition', 'Shrink Size', self.ui.spinBoxShrinkSize.value()))
175 184
            configs.append(Config('Text Size', 'Min Text Size', self.ui.minTextSizeSpinBox.value()))
176 185
            configs.append(Config('Text Size', 'Max Text Size', self.ui.maxTextSizeSpinBox.value()))
177 186
            configs.append(Config('Size', 'Delimiter', self.ui.lineEditSizeDelimiter.text()))
DTI_PID/DTI_PID/UI/Configuration.ui
7 7
    <x>0</x>
8 8
    <y>0</y>
9 9
    <width>550</width>
10
    <height>502</height>
10
    <height>560</height>
11 11
   </rect>
12 12
  </property>
13 13
  <property name="font">
......
311 311
             </layout>
312 312
            </item>
313 313
            <item>
314
             <layout class="QHBoxLayout" name="horizontalLayout_15">
315
              <item>
316
               <widget class="QLabel" name="label_20">
317
                <property name="text">
318
                 <string>팽창 크기 : </string>
319
                </property>
320
               </widget>
321
              </item>
322
              <item>
323
               <widget class="QSpinBox" name="spinBoxExpandSize"/>
324
              </item>
325
             </layout>
326
            </item>
327
            <item>
328
             <layout class="QHBoxLayout" name="horizontalLayout_16">
329
              <item>
330
               <widget class="QLabel" name="label_21">
331
                <property name="text">
332
                 <string>침식 크기 : </string>
333
                </property>
334
               </widget>
335
              </item>
336
              <item>
337
               <widget class="QSpinBox" name="spinBoxShrinkSize"/>
338
              </item>
339
             </layout>
340
            </item>
341
            <item>
314 342
             <layout class="QHBoxLayout" name="horizontalLayout_13">
315 343
              <item alignment="Qt::AlignLeft">
316 344
               <widget class="QLabel" name="label_17">

내보내기 Unified diff

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