개정판 d1cf37a9
환경설정에 Min/Max Text Size 항목 추가 및 Contour 를 이용한 텍스트 영역 검출 수정
DTI_PID/DTI_PID/Configuration_UI.py | ||
---|---|---|
11 | 11 |
class Ui_ConfigurationDialog(object): |
12 | 12 |
def setupUi(self, ConfigurationDialog): |
13 | 13 |
ConfigurationDialog.setObjectName("ConfigurationDialog") |
14 |
ConfigurationDialog.resize(550, 464)
|
|
14 |
ConfigurationDialog.resize(550, 474)
|
|
15 | 15 |
font = QtGui.QFont() |
16 | 16 |
font.setFamily("맑은 고딕") |
17 | 17 |
ConfigurationDialog.setFont(font) |
... | ... | |
25 | 25 |
self.gridLayout_2 = QtWidgets.QGridLayout(self.Recognition) |
26 | 26 |
self.gridLayout_2.setContentsMargins(0, 0, 0, 0) |
27 | 27 |
self.gridLayout_2.setObjectName("gridLayout_2") |
28 |
self.groupBoxAttribute = QtWidgets.QGroupBox(self.Recognition) |
|
29 |
self.groupBoxAttribute.setObjectName("groupBoxAttribute") |
|
30 |
self.gridLayout_6 = QtWidgets.QGridLayout(self.groupBoxAttribute) |
|
31 |
self.gridLayout_6.setObjectName("gridLayout_6") |
|
32 |
self.verticalLayout_3 = QtWidgets.QVBoxLayout() |
|
33 |
self.verticalLayout_3.setObjectName("verticalLayout_3") |
|
34 |
self.horizontalLayout_8 = QtWidgets.QHBoxLayout() |
|
35 |
self.horizontalLayout_8.setObjectName("horizontalLayout_8") |
|
36 |
self.label_6 = QtWidgets.QLabel(self.groupBoxAttribute) |
|
37 |
self.label_6.setObjectName("label_6") |
|
38 |
self.horizontalLayout_8.addWidget(self.label_6, 0, QtCore.Qt.AlignVCenter) |
|
39 |
self.lineEditSizeDelimiter = QtWidgets.QLineEdit(self.groupBoxAttribute) |
|
40 |
self.lineEditSizeDelimiter.setObjectName("lineEditSizeDelimiter") |
|
41 |
self.horizontalLayout_8.addWidget(self.lineEditSizeDelimiter, 0, QtCore.Qt.AlignVCenter) |
|
42 |
self.verticalLayout_3.addLayout(self.horizontalLayout_8) |
|
43 |
self.gridLayout_6.addLayout(self.verticalLayout_3, 0, 0, 1, 1) |
|
44 |
self.gridLayout_2.addWidget(self.groupBoxAttribute, 1, 1, 1, 1) |
|
28 | 45 |
self.groupBox = QtWidgets.QGroupBox(self.Recognition) |
29 | 46 |
self.groupBox.setObjectName("groupBox") |
30 | 47 |
self.gridLayout_5 = QtWidgets.QGridLayout(self.groupBox) |
... | ... | |
67 | 84 |
self.smallLineMinLengthSpinBox.setObjectName("smallLineMinLengthSpinBox") |
68 | 85 |
self.horizontalLayout_12.addWidget(self.smallLineMinLengthSpinBox) |
69 | 86 |
self.gridLayout_5.addLayout(self.horizontalLayout_12, 4, 0, 1, 1) |
70 |
self.gridLayout_2.addWidget(self.groupBox, 1, 1, 1, 1)
|
|
87 |
self.gridLayout_2.addWidget(self.groupBox, 2, 1, 1, 1)
|
|
71 | 88 |
self.groupBoxLineNo = QtWidgets.QGroupBox(self.Recognition) |
72 | 89 |
self.groupBoxLineNo.setObjectName("groupBoxLineNo") |
73 | 90 |
self.gridLayout_3 = QtWidgets.QGridLayout(self.groupBoxLineNo) |
... | ... | |
115 | 132 |
self.horizontalLayout_3.setObjectName("horizontalLayout_3") |
116 | 133 |
self.verticalLayout_2.addLayout(self.horizontalLayout_3) |
117 | 134 |
self.gridLayout_3.addLayout(self.verticalLayout_2, 6, 0, 1, 1) |
118 |
self.gridLayout_2.addWidget(self.groupBoxLineNo, 2, 1, 1, 1) |
|
119 |
self.groupBoxAttribute = QtWidgets.QGroupBox(self.Recognition) |
|
120 |
self.groupBoxAttribute.setObjectName("groupBoxAttribute") |
|
121 |
self.gridLayout_6 = QtWidgets.QGridLayout(self.groupBoxAttribute) |
|
122 |
self.gridLayout_6.setObjectName("gridLayout_6") |
|
123 |
self.verticalLayout_3 = QtWidgets.QVBoxLayout() |
|
124 |
self.verticalLayout_3.setObjectName("verticalLayout_3") |
|
125 |
self.horizontalLayout_8 = QtWidgets.QHBoxLayout() |
|
126 |
self.horizontalLayout_8.setObjectName("horizontalLayout_8") |
|
127 |
self.label_6 = QtWidgets.QLabel(self.groupBoxAttribute) |
|
128 |
self.label_6.setObjectName("label_6") |
|
129 |
self.horizontalLayout_8.addWidget(self.label_6, 0, QtCore.Qt.AlignVCenter) |
|
130 |
self.lineEditSizeDelimiter = QtWidgets.QLineEdit(self.groupBoxAttribute) |
|
131 |
self.lineEditSizeDelimiter.setObjectName("lineEditSizeDelimiter") |
|
132 |
self.horizontalLayout_8.addWidget(self.lineEditSizeDelimiter, 0, QtCore.Qt.AlignVCenter) |
|
133 |
self.verticalLayout_3.addLayout(self.horizontalLayout_8) |
|
134 |
self.gridLayout_6.addLayout(self.verticalLayout_3, 0, 0, 1, 1) |
|
135 |
self.gridLayout_2.addWidget(self.groupBoxAttribute, 0, 1, 1, 1) |
|
135 |
self.gridLayout_2.addWidget(self.groupBoxLineNo, 3, 1, 1, 1) |
|
136 |
self.groupBoxText = QtWidgets.QGroupBox(self.Recognition) |
|
137 |
self.groupBoxText.setObjectName("groupBoxText") |
|
138 |
self.gridLayout_14 = QtWidgets.QGridLayout(self.groupBoxText) |
|
139 |
self.gridLayout_14.setObjectName("gridLayout_14") |
|
140 |
self.verticalLayout_5 = QtWidgets.QVBoxLayout() |
|
141 |
self.verticalLayout_5.setObjectName("verticalLayout_5") |
|
142 |
self.horizontalLayout_13 = QtWidgets.QHBoxLayout() |
|
143 |
self.horizontalLayout_13.setObjectName("horizontalLayout_13") |
|
144 |
self.label_17 = QtWidgets.QLabel(self.groupBoxText) |
|
145 |
self.label_17.setObjectName("label_17") |
|
146 |
self.horizontalLayout_13.addWidget(self.label_17, 0, QtCore.Qt.AlignLeft) |
|
147 |
self.minTextSizeSpinBox = QtWidgets.QSpinBox(self.groupBoxText) |
|
148 |
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) |
|
149 |
sizePolicy.setHorizontalStretch(0) |
|
150 |
sizePolicy.setVerticalStretch(0) |
|
151 |
sizePolicy.setHeightForWidth(self.minTextSizeSpinBox.sizePolicy().hasHeightForWidth()) |
|
152 |
self.minTextSizeSpinBox.setSizePolicy(sizePolicy) |
|
153 |
self.minTextSizeSpinBox.setMaximumSize(QtCore.QSize(16777215, 16777215)) |
|
154 |
self.minTextSizeSpinBox.setProperty("value", 30) |
|
155 |
self.minTextSizeSpinBox.setObjectName("minTextSizeSpinBox") |
|
156 |
self.horizontalLayout_13.addWidget(self.minTextSizeSpinBox) |
|
157 |
self.label_18 = QtWidgets.QLabel(self.groupBoxText) |
|
158 |
self.label_18.setObjectName("label_18") |
|
159 |
self.horizontalLayout_13.addWidget(self.label_18) |
|
160 |
self.maxTextSizeSpinBox = QtWidgets.QSpinBox(self.groupBoxText) |
|
161 |
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) |
|
162 |
sizePolicy.setHorizontalStretch(0) |
|
163 |
sizePolicy.setVerticalStretch(0) |
|
164 |
sizePolicy.setHeightForWidth(self.maxTextSizeSpinBox.sizePolicy().hasHeightForWidth()) |
|
165 |
self.maxTextSizeSpinBox.setSizePolicy(sizePolicy) |
|
166 |
self.maxTextSizeSpinBox.setProperty("value", 60) |
|
167 |
self.maxTextSizeSpinBox.setObjectName("maxTextSizeSpinBox") |
|
168 |
self.horizontalLayout_13.addWidget(self.maxTextSizeSpinBox) |
|
169 |
self.verticalLayout_5.addLayout(self.horizontalLayout_13) |
|
170 |
self.gridLayout_14.addLayout(self.verticalLayout_5, 0, 0, 1, 1) |
|
171 |
self.gridLayout_2.addWidget(self.groupBoxText, 0, 1, 1, 1) |
|
136 | 172 |
self.tabWidget.addTab(self.Recognition, "") |
137 | 173 |
self.tabTagNoRule = QtWidgets.QWidget() |
138 | 174 |
self.tabTagNoRule.setObjectName("tabTagNoRule") |
... | ... | |
278 | 314 |
def retranslateUi(self, ConfigurationDialog): |
279 | 315 |
_translate = QtCore.QCoreApplication.translate |
280 | 316 |
ConfigurationDialog.setWindowTitle(_translate("ConfigurationDialog", "Configuration")) |
317 |
self.groupBoxAttribute.setTitle(_translate("ConfigurationDialog", "속성 검출")) |
|
318 |
self.label_6.setText(_translate("ConfigurationDialog", "Size Delimiter : ")) |
|
281 | 319 |
self.groupBox.setTitle(_translate("ConfigurationDialog", "라인 검출")) |
282 | 320 |
self.label_4.setText(_translate("ConfigurationDialog", "Small Object Size : ")) |
283 | 321 |
self.label_5.setText(_translate("ConfigurationDialog", " < Area < ")) |
... | ... | |
289 | 327 |
self.radioButtonInch.setText(_translate("ConfigurationDialog", "Inch")) |
290 | 328 |
self.label_2.setText(_translate("ConfigurationDialog", "Delimiter : ")) |
291 | 329 |
self.pushButtonAddProperty.setText(_translate("ConfigurationDialog", "추가")) |
292 |
self.groupBoxAttribute.setTitle(_translate("ConfigurationDialog", "속성 검출")) |
|
293 |
self.label_6.setText(_translate("ConfigurationDialog", "Size Delimiter : ")) |
|
330 |
self.groupBoxText.setTitle(_translate("ConfigurationDialog", "텍스트 검출")) |
|
331 |
self.label_17.setText(_translate("ConfigurationDialog", "Minimum Text Size : ")) |
|
332 |
self.label_18.setText(_translate("ConfigurationDialog", "Maximum Text Size : ")) |
|
294 | 333 |
self.tabWidget.setTabText(self.tabWidget.indexOf(self.Recognition), _translate("ConfigurationDialog", "인식")) |
295 | 334 |
self.groupBox_2.setTitle(_translate("ConfigurationDialog", "Instrument Tag No Rule")) |
296 | 335 |
self.label_8.setText(_translate("ConfigurationDialog", "Measured Variable Code")) |
... | ... | |
305 | 344 |
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabTagNoRule), _translate("ConfigurationDialog", "태그 넘버 룰")) |
306 | 345 |
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabNominalPipeSize), _translate("ConfigurationDialog", "Nominal Pipe Size")) |
307 | 346 |
|
308 |
import DTI_PID_rc |
|
309 | 347 |
|
310 | 348 |
if __name__ == "__main__": |
311 | 349 |
import sys |
DTI_PID/DTI_PID/DTI_PID.py | ||
---|---|---|
1034 | 1034 |
[x, y, w, h] = cv2.boundingRect(contour) |
1035 | 1035 |
|
1036 | 1036 |
# remove small one less than character size |
1037 |
if (w < 15 or h < 15): continue
|
|
1037 |
if (w < 20 or h < 20): continue
|
|
1038 | 1038 |
#if w > h: |
1039 | 1039 |
# rects.append(QRect(x, y, w, h)) # expand rect |
1040 | 1040 |
#elif w < h: |
... | ... | |
1063 | 1063 |
cv2.imwrite('D:/Visual Studio Project/DTIPID/DTIPID/DTI_PID/DTI_PID/res/Result/PC-K/Temp/Erode_PC-K-2203_P1_800DPI___partial.png', eroded) |
1064 | 1064 |
|
1065 | 1065 |
chan, imgW, imgH = img.shape[::-1] |
1066 |
index = 0 |
|
1066 | 1067 |
for rect in rects: |
1068 |
index = index + 1 |
|
1067 | 1069 |
isVertical = False |
1068 | 1070 |
textInfoList = None |
1069 |
if rect.width() >= rect.height(): |
|
1071 |
if rect.width() >= rect.height() or rect.height() < 50:
|
|
1070 | 1072 |
isVertical = False |
1071 | 1073 |
textInfoList = TOCR.getTextInfo(contourOcrImg[rect.y():rect.y()+rect.height(), rect.x():rect.x()+rect.width()], (rect.x(), rect.y())) |
1072 | 1074 |
else: |
... | ... | |
1086 | 1088 |
cv2.putText(img, textInfo.getText(), (textInfo.getX(), textInfo.getY()+textInfo.getH()), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 3) |
1087 | 1089 |
if isVertical: |
1088 | 1090 |
img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE) |
1091 |
|
|
1092 |
print(str(index) + " / " + str(len(rects)) + " Finished") |
|
1089 | 1093 |
#cv2.imshow('test', img[rect.y():rect.y()+rect.height(), rect.x():rect.x()+rect.width()]) |
1090 | 1094 |
#cv2.waitKey(0) |
1091 | 1095 |
#cv2.destroyAllWindows() |
1092 | 1096 |
|
1093 | 1097 |
cv2.imwrite('D:/Visual Studio Project/DTIPID/DTIPID/DTI_PID/DTI_PID/res/Result/PC-K/Temp/OCR_PC-K-2203_P1_800DPI___partial.png', img) |
1098 |
stop = timeit.default_timer() |
|
1099 |
print('FINISHED : ' + str((stop-start)/60) + ' min') |
|
1094 | 1100 |
|
1095 | 1101 |
#app = QApplication(sys.argv) |
1096 | 1102 |
|
DTI_PID/DTI_PID/QConfigurationDialog.py | ||
---|---|---|
44 | 44 |
@history humkyung 2018.05.05 read configuration for instrument and opc tag no rule |
45 | 45 |
humkyung 2018.05.09 read line no tag rule configuration |
46 | 46 |
Jeongwoo 2018.05.18 read Small Line Minimum Length |
47 |
Jeongwoo 2018.06.04 read Min/Max Text Size |
|
47 | 48 |
''' |
48 | 49 |
def __init__(self, parent): |
49 | 50 |
QDialog.__init__(self, parent) |
... | ... | |
57 | 58 |
self.itemModel = QStandardItemModel() |
58 | 59 |
|
59 | 60 |
docData = AppDocData.instance() |
61 |
configs = docData.getConfigs('Text Size', 'Min Text Size') |
|
62 |
self.ui.minTextSizeSpinBox.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.minTextSizeSpinBox.setValue(30) |
|
63 |
configs = docData.getConfigs('Text Size', 'Max Text Size') |
|
64 |
self.ui.maxTextSizeSpinBox.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.maxTextSizeSpinBox.setValue(60) |
|
65 |
|
|
60 | 66 |
configs = docData.getConfigs('Size', 'Delimiter') |
61 | 67 |
self.ui.lineEditSizeDelimiter.setText(configs[0].value if 1 == len(configs) else 'X') |
62 | 68 |
|
... | ... | |
149 | 155 |
humkyung 2018.05.05 save instrument and opc tag no rule |
150 | 156 |
humkyung 2018.05.09 save line no tag rule |
151 | 157 |
Jeongwoo 2018.05.18 save Small Line Minimum Length |
158 |
Jeongwoo 2018.06.04 save Min/Max Text Size |
|
152 | 159 |
''' |
153 | 160 |
def accept(self): |
154 | 161 |
try: |
155 | 162 |
self.isAccepted = True |
156 | 163 |
|
157 | 164 |
configs = [] |
165 |
configs.append(Config('Text Size', 'Min Text Size', self.ui.minTextSizeSpinBox.value())) |
|
166 |
configs.append(Config('Text Size', 'Max Text Size', self.ui.maxTextSizeSpinBox.value())) |
|
158 | 167 |
configs.append(Config('Size', 'Delimiter', self.ui.lineEditSizeDelimiter.text())) |
159 | 168 |
configs.append(Config('Small Object Size', 'Min Area', self.ui.spinBoxMinArea.value())) |
160 | 169 |
configs.append(Config('Small Object Size', 'Max Area', self.ui.spinBoxMaxArea.value())) |
DTI_PID/DTI_PID/UI/Configuration.ui | ||
---|---|---|
7 | 7 |
<x>0</x> |
8 | 8 |
<y>0</y> |
9 | 9 |
<width>550</width> |
10 |
<height>464</height>
|
|
10 |
<height>474</height>
|
|
11 | 11 |
</rect> |
12 | 12 |
</property> |
13 | 13 |
<property name="font"> |
... | ... | |
33 | 33 |
</attribute> |
34 | 34 |
<layout class="QGridLayout" name="gridLayout_2"> |
35 | 35 |
<item row="1" column="1"> |
36 |
<widget class="QGroupBox" name="groupBoxAttribute"> |
|
37 |
<property name="title"> |
|
38 |
<string>속성 검출</string> |
|
39 |
</property> |
|
40 |
<layout class="QGridLayout" name="gridLayout_6"> |
|
41 |
<item row="0" column="0"> |
|
42 |
<layout class="QVBoxLayout" name="verticalLayout_3"> |
|
43 |
<item> |
|
44 |
<layout class="QHBoxLayout" name="horizontalLayout_8"> |
|
45 |
<item alignment="Qt::AlignVCenter"> |
|
46 |
<widget class="QLabel" name="label_6"> |
|
47 |
<property name="text"> |
|
48 |
<string>Size Delimiter : </string> |
|
49 |
</property> |
|
50 |
</widget> |
|
51 |
</item> |
|
52 |
<item alignment="Qt::AlignVCenter"> |
|
53 |
<widget class="QLineEdit" name="lineEditSizeDelimiter"/> |
|
54 |
</item> |
|
55 |
</layout> |
|
56 |
</item> |
|
57 |
</layout> |
|
58 |
</item> |
|
59 |
</layout> |
|
60 |
</widget> |
|
61 |
</item> |
|
62 |
<item row="2" column="1"> |
|
36 | 63 |
<widget class="QGroupBox" name="groupBox"> |
37 | 64 |
<property name="title"> |
38 | 65 |
<string>라인 검출</string> |
... | ... | |
102 | 129 |
</layout> |
103 | 130 |
</widget> |
104 | 131 |
</item> |
105 |
<item row="2" column="1">
|
|
132 |
<item row="3" column="1">
|
|
106 | 133 |
<widget class="QGroupBox" name="groupBoxLineNo"> |
107 | 134 |
<property name="title"> |
108 | 135 |
<string>Line No</string> |
... | ... | |
193 | 220 |
</widget> |
194 | 221 |
</item> |
195 | 222 |
<item row="0" column="1"> |
196 |
<widget class="QGroupBox" name="groupBoxAttribute">
|
|
223 |
<widget class="QGroupBox" name="groupBoxText">
|
|
197 | 224 |
<property name="title"> |
198 |
<string>속성 검출</string>
|
|
225 |
<string>텍스트 검출</string>
|
|
199 | 226 |
</property> |
200 |
<layout class="QGridLayout" name="gridLayout_6">
|
|
227 |
<layout class="QGridLayout" name="gridLayout_14">
|
|
201 | 228 |
<item row="0" column="0"> |
202 |
<layout class="QVBoxLayout" name="verticalLayout_3">
|
|
229 |
<layout class="QVBoxLayout" name="verticalLayout_5">
|
|
203 | 230 |
<item> |
204 |
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
|
205 |
<item alignment="Qt::AlignVCenter">
|
|
206 |
<widget class="QLabel" name="label_6">
|
|
231 |
<layout class="QHBoxLayout" name="horizontalLayout_13">
|
|
232 |
<item alignment="Qt::AlignLeft">
|
|
233 |
<widget class="QLabel" name="label_17">
|
|
207 | 234 |
<property name="text"> |
208 |
<string>Size Delimiter : </string>
|
|
235 |
<string>Minimum Text Size : </string>
|
|
209 | 236 |
</property> |
210 | 237 |
</widget> |
211 | 238 |
</item> |
212 |
<item alignment="Qt::AlignVCenter"> |
|
213 |
<widget class="QLineEdit" name="lineEditSizeDelimiter"/> |
|
239 |
<item> |
|
240 |
<widget class="QSpinBox" name="minTextSizeSpinBox"> |
|
241 |
<property name="sizePolicy"> |
|
242 |
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> |
|
243 |
<horstretch>0</horstretch> |
|
244 |
<verstretch>0</verstretch> |
|
245 |
</sizepolicy> |
|
246 |
</property> |
|
247 |
<property name="maximumSize"> |
|
248 |
<size> |
|
249 |
<width>16777215</width> |
|
250 |
<height>16777215</height> |
|
251 |
</size> |
|
252 |
</property> |
|
253 |
<property name="value"> |
|
254 |
<number>30</number> |
|
255 |
</property> |
|
256 |
</widget> |
|
257 |
</item> |
|
258 |
<item> |
|
259 |
<widget class="QLabel" name="label_18"> |
|
260 |
<property name="text"> |
|
261 |
<string>Maximum Text Size : </string> |
|
262 |
</property> |
|
263 |
</widget> |
|
264 |
</item> |
|
265 |
<item> |
|
266 |
<widget class="QSpinBox" name="maxTextSizeSpinBox"> |
|
267 |
<property name="sizePolicy"> |
|
268 |
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> |
|
269 |
<horstretch>0</horstretch> |
|
270 |
<verstretch>0</verstretch> |
|
271 |
</sizepolicy> |
|
272 |
</property> |
|
273 |
<property name="value"> |
|
274 |
<number>60</number> |
|
275 |
</property> |
|
276 |
</widget> |
|
214 | 277 |
</item> |
215 | 278 |
</layout> |
216 | 279 |
</item> |
... | ... | |
444 | 507 |
<tabstop>lineEditOPCTag</tabstop> |
445 | 508 |
<tabstop>tabWidget</tabstop> |
446 | 509 |
</tabstops> |
447 |
<resources> |
|
448 |
<include location="../res/DTI_PID.qrc"/> |
|
449 |
</resources> |
|
510 |
<resources/> |
|
450 | 511 |
<connections> |
451 | 512 |
<connection> |
452 | 513 |
<sender>buttonBox</sender> |
내보내기 Unified diff