개정판 07e0ffd0
issue #98: add drawing opening option, fix size text detection
Change-Id: Iff19f5f2b9879d18c75d4ae931ed8f1b502240ab
DTI_PID/DTI_PID/CodeTables.py | ||
---|---|---|
26 | 26 |
if self.name == "NOMINALDIAMETER": |
27 | 27 |
""" uid, code, metric, inch, inchstr, allowable_inch_str, metricstr, allowable_metric_str """ |
28 | 28 |
for value in self.values: |
29 |
if size_unit.upper() == 'INCH': |
|
29 |
if size_unit.upper() == 'INCH' or size_unit.upper() == 'IMPERIAL':
|
|
30 | 30 |
tokens = [x for x in value[5].replace(' ', '').split(',') if x and text.startswith(x)] |
31 | 31 |
if text.startswidth(value[4]) or tokens: return value[4] |
32 | 32 |
elif size_unit.upper() == 'METRIC': |
DTI_PID/DTI_PID/ConfigurationDialog.py | ||
---|---|---|
106 | 106 |
configs = docData.getConfigs('Filter', 'FlatSize') |
107 | 107 |
self.ui.spinBoxFlatSize.setValue(int(configs[0].value)) if 1 == len( |
108 | 108 |
configs) else self.ui.spinBoxFlatSize.setValue(0) |
109 |
configs = docData.getConfigs('Filter', 'Mode') |
|
110 |
if configs: |
|
111 |
size = int(configs[0].value) |
|
112 |
self.ui.radioButtonMode2.setChecked(True if size == 1 else False) |
|
113 |
self.ui.radioButtonMode1.setChecked(True if size == 0 else False) |
|
114 |
else: |
|
115 |
self.ui.radioButtonMode2.setChecked(False) |
|
116 |
self.ui.radioButtonMode1.setChecked(True) |
|
109 | 117 |
|
110 | 118 |
# set min,max area for small object |
111 | 119 |
configs = docData.getConfigs('Small Object Size', 'Min Area') |
... | ... | |
784 | 792 |
configs.append(Config('Filter', 'ErodeSize', self.ui.spinBoxUnrecognitionIgnoreStep.value())) |
785 | 793 |
configs.append(Config('Filter', 'DilateSize', self.ui.spinBoxDilateSize.value())) |
786 | 794 |
configs.append(Config('Filter', 'FlatSize', self.ui.spinBoxFlatSize.value())) |
795 |
configs.append(Config('Filter', 'Mode', '0' if self.ui.radioButtonMode1.isChecked() else '1')) |
|
787 | 796 |
configs.append(Config('Small Object Size', 'Min Area', self.ui.spinBoxMinArea.value())) |
788 | 797 |
configs.append(Config('Small Object Size', 'Max Area', self.ui.spinBoxMaxArea.value())) |
789 | 798 |
configs.append(Config('Sliding Window', 'Width', self.ui.spinBoxWidth.value())) |
DTI_PID/DTI_PID/Configuration_UI.py | ||
---|---|---|
33 | 33 |
self.gridLayout_8.setObjectName("gridLayout_8") |
34 | 34 |
self.gridLayout_27 = QtWidgets.QGridLayout() |
35 | 35 |
self.gridLayout_27.setObjectName("gridLayout_27") |
36 |
self.label_10 = QtWidgets.QLabel(self.groupBoxFilter) |
|
37 |
self.label_10.setMaximumSize(QtCore.QSize(230, 16777215)) |
|
38 |
self.label_10.setObjectName("label_10") |
|
39 |
self.gridLayout_27.addWidget(self.label_10, 0, 0, 1, 1) |
|
40 |
self.spinBoxMinimumSize = QtWidgets.QSpinBox(self.groupBoxFilter) |
|
41 |
self.spinBoxMinimumSize.setObjectName("spinBoxMinimumSize") |
|
42 |
self.gridLayout_27.addWidget(self.spinBoxMinimumSize, 0, 1, 1, 1) |
|
43 | 36 |
self.spinBoxUnrecognitionIgnoreStep = QtWidgets.QSpinBox(self.groupBoxFilter) |
44 | 37 |
self.spinBoxUnrecognitionIgnoreStep.setMaximum(10) |
45 | 38 |
self.spinBoxUnrecognitionIgnoreStep.setObjectName("spinBoxUnrecognitionIgnoreStep") |
46 | 39 |
self.gridLayout_27.addWidget(self.spinBoxUnrecognitionIgnoreStep, 1, 1, 1, 1) |
40 |
self.spinBoxMinimumSize = QtWidgets.QSpinBox(self.groupBoxFilter) |
|
41 |
self.spinBoxMinimumSize.setObjectName("spinBoxMinimumSize") |
|
42 |
self.gridLayout_27.addWidget(self.spinBoxMinimumSize, 0, 1, 1, 1) |
|
43 |
self.spinBoxFlatSize = QtWidgets.QSpinBox(self.groupBoxFilter) |
|
44 |
self.spinBoxFlatSize.setObjectName("spinBoxFlatSize") |
|
45 |
self.gridLayout_27.addWidget(self.spinBoxFlatSize, 3, 1, 1, 1) |
|
47 | 46 |
self.label_29 = QtWidgets.QLabel(self.groupBoxFilter) |
48 | 47 |
self.label_29.setMaximumSize(QtCore.QSize(230, 16777215)) |
49 | 48 |
self.label_29.setObjectName("label_29") |
50 | 49 |
self.gridLayout_27.addWidget(self.label_29, 2, 0, 1, 1) |
51 |
self.spinBoxDilateSize = QtWidgets.QSpinBox(self.groupBoxFilter)
|
|
52 |
self.spinBoxDilateSize.setMaximum(10)
|
|
53 |
self.spinBoxDilateSize.setObjectName("spinBoxDilateSize")
|
|
54 |
self.gridLayout_27.addWidget(self.spinBoxDilateSize, 2, 1, 1, 1)
|
|
50 |
self.label_10 = QtWidgets.QLabel(self.groupBoxFilter)
|
|
51 |
self.label_10.setMaximumSize(QtCore.QSize(230, 16777215))
|
|
52 |
self.label_10.setObjectName("label_10")
|
|
53 |
self.gridLayout_27.addWidget(self.label_10, 0, 0, 1, 1)
|
|
55 | 54 |
self.label_33 = QtWidgets.QLabel(self.groupBoxFilter) |
56 | 55 |
self.label_33.setMinimumSize(QtCore.QSize(230, 0)) |
57 | 56 |
self.label_33.setMaximumSize(QtCore.QSize(230, 16777215)) |
... | ... | |
61 | 60 |
self.label_32.setMaximumSize(QtCore.QSize(230, 16777215)) |
62 | 61 |
self.label_32.setObjectName("label_32") |
63 | 62 |
self.gridLayout_27.addWidget(self.label_32, 3, 0, 1, 1) |
64 |
self.spinBoxFlatSize = QtWidgets.QSpinBox(self.groupBoxFilter) |
|
65 |
self.spinBoxFlatSize.setObjectName("spinBoxFlatSize") |
|
66 |
self.gridLayout_27.addWidget(self.spinBoxFlatSize, 3, 1, 1, 1) |
|
63 |
self.spinBoxDilateSize = QtWidgets.QSpinBox(self.groupBoxFilter) |
|
64 |
self.spinBoxDilateSize.setMaximum(10) |
|
65 |
self.spinBoxDilateSize.setObjectName("spinBoxDilateSize") |
|
66 |
self.gridLayout_27.addWidget(self.spinBoxDilateSize, 2, 1, 1, 1) |
|
67 |
self.label_38 = QtWidgets.QLabel(self.groupBoxFilter) |
|
68 |
self.label_38.setObjectName("label_38") |
|
69 |
self.gridLayout_27.addWidget(self.label_38, 4, 0, 1, 1) |
|
70 |
self.horizontalLayout_6 = QtWidgets.QHBoxLayout() |
|
71 |
self.horizontalLayout_6.setObjectName("horizontalLayout_6") |
|
72 |
self.radioButtonMode1 = QtWidgets.QRadioButton(self.groupBoxFilter) |
|
73 |
self.radioButtonMode1.setObjectName("radioButtonMode1") |
|
74 |
self.buttonGroup_5 = QtWidgets.QButtonGroup(ConfigurationDialog) |
|
75 |
self.buttonGroup_5.setObjectName("buttonGroup_5") |
|
76 |
self.buttonGroup_5.addButton(self.radioButtonMode1) |
|
77 |
self.horizontalLayout_6.addWidget(self.radioButtonMode1) |
|
78 |
self.radioButtonMode2 = QtWidgets.QRadioButton(self.groupBoxFilter) |
|
79 |
self.radioButtonMode2.setObjectName("radioButtonMode2") |
|
80 |
self.buttonGroup_5.addButton(self.radioButtonMode2) |
|
81 |
self.horizontalLayout_6.addWidget(self.radioButtonMode2) |
|
82 |
self.gridLayout_27.addLayout(self.horizontalLayout_6, 4, 1, 1, 1) |
|
67 | 83 |
self.gridLayout_8.addLayout(self.gridLayout_27, 0, 0, 1, 1) |
68 | 84 |
self.gridLayout_2.addWidget(self.groupBoxFilter, 2, 1, 1, 1) |
69 | 85 |
self.groupBoxText = QtWidgets.QGroupBox(self.Recognition) |
... | ... | |
636 | 652 |
_translate = QtCore.QCoreApplication.translate |
637 | 653 |
ConfigurationDialog.setWindowTitle(_translate("ConfigurationDialog", "Configuration")) |
638 | 654 |
self.groupBoxFilter.setTitle(_translate("ConfigurationDialog", "Filter")) |
639 |
self.label_10.setText(_translate("ConfigurationDialog", "Minimum Detection Size : ")) |
|
640 | 655 |
self.label_29.setText(_translate("ConfigurationDialog", "Drawing Thickness Reinforcement Step : ")) |
656 |
self.label_10.setText(_translate("ConfigurationDialog", "Minimum Detection Size : ")) |
|
641 | 657 |
self.label_33.setText(_translate("ConfigurationDialog", "Unrecognition Ignore Step : ")) |
642 | 658 |
self.label_32.setText(_translate("ConfigurationDialog", "Drawing Flattening Step : ")) |
659 |
self.label_38.setText(_translate("ConfigurationDialog", "Drawing Opening Mode")) |
|
660 |
self.radioButtonMode1.setText(_translate("ConfigurationDialog", "Default")) |
|
661 |
self.radioButtonMode2.setText(_translate("ConfigurationDialog", "Advanced")) |
|
643 | 662 |
self.groupBoxText.setTitle(_translate("ConfigurationDialog", "Text Detection")) |
644 | 663 |
self.label_18.setText(_translate("ConfigurationDialog", "Maximum Text Size : ")) |
645 | 664 |
self.label_17.setText(_translate("ConfigurationDialog", "Minimum Text Size : ")) |
DTI_PID/DTI_PID/Drawing.py | ||
---|---|---|
122 | 122 |
import numpy as np |
123 | 123 |
|
124 | 124 |
if self._image is None: |
125 |
app_doc_data = AppDocData.instance() |
|
126 |
|
|
125 | 127 |
numpyArray = np.asarray(bytearray(self.contents), dtype=np.uint8) |
126 | 128 |
image = cv2.imdecode(numpyArray, cv2.IMREAD_UNCHANGED) |
127 | 129 |
self._image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) |
128 |
self._image = cv2.threshold(self._image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1] |
|
130 |
|
|
131 |
# drawing opening mode |
|
132 |
configs = app_doc_data.getConfigs('Filter', 'Mode') |
|
133 |
if 1 == len(configs) and int(configs[0].value) is not 0: |
|
134 |
kernel_sharpen_2 = np.array([[-1, -1, -1, -1, -1], [-1, 2, 2, 2, -1], [-1, 2, 8, 2, -1], [-1, 2, 2, 2, -1], |
|
135 |
[-2, -1, -1, -1, -1]]) / 8.0 # 정규화위해 8로나눔 |
|
136 |
self._image = cv2.filter2D(self._image, -1, kernel_sharpen_2) |
|
137 |
self._image = cv2.GaussianBlur(self._image, (5, 5), 10, 10) |
|
138 |
self._image = cv2.adaptiveThreshold(self._image, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 15, 5) |
|
139 |
|
|
140 |
selected_contours = [] |
|
141 |
contours, hierarchy = cv2.findContours(self._image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) |
|
142 |
index = 0 |
|
143 |
for contour in contours: |
|
144 |
child, parent = hierarchy[0][index][2], hierarchy[0][index][3] |
|
145 |
if child == -1: |
|
146 |
[x, y, w, h] = cv2.boundingRect(contour) |
|
147 |
if w * h < 5*5: |
|
148 |
selected_contours.append(contour) |
|
149 |
index += 1 |
|
150 |
# draw contour with white color |
|
151 |
self._image = cv2.drawContours(self._image, selected_contours, -1, (255, 255, 255), -1) |
|
152 |
else: |
|
153 |
self._image = cv2.threshold(self._image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1] |
|
154 |
#self._image = cv2.adaptiveThreshold(self._image, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 15, 2) |
|
129 | 155 |
|
130 |
app_doc_data = AppDocData.instance() |
|
131 | 156 |
configs = app_doc_data.getConfigs('Filter', 'DilateSize') |
132 | 157 |
if 1 == len(configs) and int(configs[0].value) is not 0: |
133 | 158 |
size = int(configs[0].value) |
DTI_PID/DTI_PID/NominalPipeSize.py | ||
---|---|---|
65 | 65 |
''' |
66 | 66 |
|
67 | 67 |
def find(self, value, size_unit='Inch'): |
68 |
if size_unit.upper() == 'INCH': |
|
68 |
if size_unit.upper() == 'INCH' or size_unit.upper() == 'IMPERIAL':
|
|
69 | 69 |
if (self.inchStr == value) or (value in self.allowable_inch_str.split(',')): |
70 | 70 |
return self.inchStr |
71 | 71 |
elif size_unit.upper() == 'METRIC': |
... | ... | |
81 | 81 |
def find_starts_with(self, value, size_unit='Inch'): |
82 | 82 |
""" find text start with """ |
83 | 83 |
try: |
84 |
if size_unit.upper() == 'INCH': |
|
84 |
if size_unit.upper() == 'INCH' or size_unit.upper() == 'IMPERIAL':
|
|
85 | 85 |
if value.startswith(self.inchStr): |
86 | 86 |
return self.inchStr, self.inchStr |
87 | 87 |
else: |
DTI_PID/DTI_PID/UI/Configuration.ui | ||
---|---|---|
44 | 44 |
<layout class="QGridLayout" name="gridLayout_8"> |
45 | 45 |
<item row="0" column="0"> |
46 | 46 |
<layout class="QGridLayout" name="gridLayout_27"> |
47 |
<item row="0" column="0"> |
|
48 |
<widget class="QLabel" name="label_10"> |
|
49 |
<property name="maximumSize"> |
|
50 |
<size> |
|
51 |
<width>230</width> |
|
52 |
<height>16777215</height> |
|
53 |
</size> |
|
54 |
</property> |
|
55 |
<property name="text"> |
|
56 |
<string>Minimum Detection Size : </string> |
|
57 |
</property> |
|
58 |
</widget> |
|
59 |
</item> |
|
60 |
<item row="0" column="1"> |
|
61 |
<widget class="QSpinBox" name="spinBoxMinimumSize"/> |
|
62 |
</item> |
|
63 | 47 |
<item row="1" column="1"> |
64 | 48 |
<widget class="QSpinBox" name="spinBoxUnrecognitionIgnoreStep"> |
65 | 49 |
<property name="maximum"> |
... | ... | |
67 | 51 |
</property> |
68 | 52 |
</widget> |
69 | 53 |
</item> |
54 |
<item row="0" column="1"> |
|
55 |
<widget class="QSpinBox" name="spinBoxMinimumSize"/> |
|
56 |
</item> |
|
57 |
<item row="3" column="1"> |
|
58 |
<widget class="QSpinBox" name="spinBoxFlatSize"/> |
|
59 |
</item> |
|
70 | 60 |
<item row="2" column="0"> |
71 | 61 |
<widget class="QLabel" name="label_29"> |
72 | 62 |
<property name="maximumSize"> |
... | ... | |
80 | 70 |
</property> |
81 | 71 |
</widget> |
82 | 72 |
</item> |
83 |
<item row="2" column="1"> |
|
84 |
<widget class="QSpinBox" name="spinBoxDilateSize"> |
|
85 |
<property name="maximum"> |
|
86 |
<number>10</number> |
|
73 |
<item row="0" column="0"> |
|
74 |
<widget class="QLabel" name="label_10"> |
|
75 |
<property name="maximumSize"> |
|
76 |
<size> |
|
77 |
<width>230</width> |
|
78 |
<height>16777215</height> |
|
79 |
</size> |
|
80 |
</property> |
|
81 |
<property name="text"> |
|
82 |
<string>Minimum Detection Size : </string> |
|
87 | 83 |
</property> |
88 | 84 |
</widget> |
89 | 85 |
</item> |
... | ... | |
119 | 115 |
</property> |
120 | 116 |
</widget> |
121 | 117 |
</item> |
122 |
<item row="3" column="1"> |
|
123 |
<widget class="QSpinBox" name="spinBoxFlatSize"/> |
|
118 |
<item row="2" column="1"> |
|
119 |
<widget class="QSpinBox" name="spinBoxDilateSize"> |
|
120 |
<property name="maximum"> |
|
121 |
<number>10</number> |
|
122 |
</property> |
|
123 |
</widget> |
|
124 |
</item> |
|
125 |
<item row="4" column="0"> |
|
126 |
<widget class="QLabel" name="label_38"> |
|
127 |
<property name="text"> |
|
128 |
<string>Drawing Opening Mode</string> |
|
129 |
</property> |
|
130 |
</widget> |
|
131 |
</item> |
|
132 |
<item row="4" column="1"> |
|
133 |
<layout class="QHBoxLayout" name="horizontalLayout_6"> |
|
134 |
<item> |
|
135 |
<widget class="QRadioButton" name="radioButtonMode1"> |
|
136 |
<property name="text"> |
|
137 |
<string>Default</string> |
|
138 |
</property> |
|
139 |
<attribute name="buttonGroup"> |
|
140 |
<string notr="true">buttonGroup_5</string> |
|
141 |
</attribute> |
|
142 |
</widget> |
|
143 |
</item> |
|
144 |
<item> |
|
145 |
<widget class="QRadioButton" name="radioButtonMode2"> |
|
146 |
<property name="text"> |
|
147 |
<string>Advanced</string> |
|
148 |
</property> |
|
149 |
<attribute name="buttonGroup"> |
|
150 |
<string notr="true">buttonGroup_5</string> |
|
151 |
</attribute> |
|
152 |
</widget> |
|
153 |
</item> |
|
154 |
</layout> |
|
124 | 155 |
</item> |
125 | 156 |
</layout> |
126 | 157 |
</item> |
... | ... | |
1385 | 1416 |
</connections> |
1386 | 1417 |
<buttongroups> |
1387 | 1418 |
<buttongroup name="buttonGroup_2"/> |
1419 |
<buttongroup name="buttonGroup_3"/> |
|
1388 | 1420 |
<buttongroup name="buttonGroup"/> |
1389 | 1421 |
<buttongroup name="buttonGroup_4"/> |
1390 |
<buttongroup name="buttonGroup_3"/>
|
|
1422 |
<buttongroup name="buttonGroup_5"/>
|
|
1391 | 1423 |
</buttongroups> |
1392 | 1424 |
</ui> |
내보내기 Unified diff