개정판 33657cfd
Remove small objects before recognizing line
DTI_PID/DTI_PID/Configuration_UI.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 |
|
3 |
# Form implementation generated from reading ui file 'UI/Configuration.ui'
|
|
3 |
# Form implementation generated from reading ui file '.\UI\Configuration.ui'
|
|
4 | 4 |
# |
5 | 5 |
# Created by: PyQt5 UI code generator 5.10.1 |
6 | 6 |
# |
... | ... | |
26 | 26 |
self.gridLayout_2.setObjectName("gridLayout_2") |
27 | 27 |
self.groupBox = QtWidgets.QGroupBox(self.Recognition) |
28 | 28 |
self.groupBox.setObjectName("groupBox") |
29 |
self.formLayout = QtWidgets.QFormLayout(self.groupBox) |
|
30 |
self.formLayout.setObjectName("formLayout") |
|
29 |
self.gridLayout_5 = QtWidgets.QGridLayout(self.groupBox) |
|
30 |
self.gridLayout_5.setObjectName("gridLayout_5") |
|
31 |
self.horizontalLayout_6 = QtWidgets.QHBoxLayout() |
|
32 |
self.horizontalLayout_6.setObjectName("horizontalLayout_6") |
|
33 |
self.label_4 = QtWidgets.QLabel(self.groupBox) |
|
34 |
self.label_4.setObjectName("label_4") |
|
35 |
self.horizontalLayout_6.addWidget(self.label_4) |
|
36 |
self.spinBoxMinArea = QtWidgets.QSpinBox(self.groupBox) |
|
37 |
self.spinBoxMinArea.setObjectName("spinBoxMinArea") |
|
38 |
self.horizontalLayout_6.addWidget(self.spinBoxMinArea) |
|
39 |
self.label_5 = QtWidgets.QLabel(self.groupBox) |
|
40 |
self.label_5.setObjectName("label_5") |
|
41 |
self.horizontalLayout_6.addWidget(self.label_5, 0, QtCore.Qt.AlignHCenter) |
|
42 |
self.spinBoxMaxArea = QtWidgets.QSpinBox(self.groupBox) |
|
43 |
self.spinBoxMaxArea.setObjectName("spinBoxMaxArea") |
|
44 |
self.horizontalLayout_6.addWidget(self.spinBoxMaxArea) |
|
45 |
self.gridLayout_5.addLayout(self.horizontalLayout_6, 0, 0, 1, 1) |
|
31 | 46 |
self.horizontalLayout = QtWidgets.QHBoxLayout() |
32 | 47 |
self.horizontalLayout.setSizeConstraint(QtWidgets.QLayout.SetNoConstraint) |
33 | 48 |
self.horizontalLayout.setObjectName("horizontalLayout") |
... | ... | |
41 | 56 |
self.spinBoxHeight = QtWidgets.QSpinBox(self.groupBox) |
42 | 57 |
self.spinBoxHeight.setObjectName("spinBoxHeight") |
43 | 58 |
self.horizontalLayout.addWidget(self.spinBoxHeight) |
44 |
self.formLayout.setLayout(0, QtWidgets.QFormLayout.SpanningRole, self.horizontalLayout)
|
|
59 |
self.gridLayout_5.addLayout(self.horizontalLayout, 1, 0, 1, 1)
|
|
45 | 60 |
self.gridLayout_2.addWidget(self.groupBox, 0, 1, 1, 1) |
46 | 61 |
self.groupBoxLineNo = QtWidgets.QGroupBox(self.Recognition) |
47 | 62 |
self.groupBoxLineNo.setObjectName("groupBoxLineNo") |
... | ... | |
123 | 138 |
_translate = QtCore.QCoreApplication.translate |
124 | 139 |
ConfigurationDialog.setWindowTitle(_translate("ConfigurationDialog", "Configuration")) |
125 | 140 |
self.groupBox.setTitle(_translate("ConfigurationDialog", "라인 검출")) |
141 |
self.label_4.setText(_translate("ConfigurationDialog", "Small Object Size : ")) |
|
142 |
self.label_5.setText(_translate("ConfigurationDialog", " < Area < ")) |
|
126 | 143 |
self.label.setText(_translate("ConfigurationDialog", "Sliding Window Size(WxH) : ")) |
127 | 144 |
self.groupBoxLineNo.setTitle(_translate("ConfigurationDialog", "Line No")) |
128 | 145 |
self.label_3.setText(_translate("ConfigurationDialog", "Size Unit : ")) |
DTI_PID/DTI_PID/DTI_PID.py | ||
---|---|---|
929 | 929 |
|
930 | 930 |
stop = timeit.default_timer() |
931 | 931 |
seconds = stop - start |
932 |
f = open(os.path.dirname(os.path.realpath(__file__)) + "\\res\\Result\\result_"+ docData.imgName+"_600dpi.txt", 'a+') |
|
933 |
data = "Running Time : " + str(seconds / 60) + "min\n" |
|
934 |
f.write(data) |
|
935 |
f.close() |
|
932 |
#f = open(os.path.dirname(os.path.realpath(__file__)) + "\\res\\Result\\result_"+ docData.imgName+"_600dpi.txt", 'a+')
|
|
933 |
#data = "Running Time : " + str(seconds / 60) + "min\n"
|
|
934 |
#f.write(data)
|
|
935 |
#f.close()
|
|
936 | 936 |
|
937 | 937 |
listWidget.addItem("\nRunning Time : " + str(seconds / 60) + "min\n") |
938 | 938 |
except Exception as ex: |
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
173 | 173 |
AppDocData.instance().setCurrentPidSource(Image.open(self.path)) |
174 | 174 |
self.resultTreeWidget.setCurrentPID(baseName) |
175 | 175 |
|
176 |
srcImage = cv2.imread(self.path) |
|
177 |
imgray = cv2.cvtColor(srcImage, cv2.COLOR_BGR2GRAY) |
|
178 |
ret,thresh = cv2.threshold(imgray,127,255,0); |
|
179 |
self.removeSmallObjects(thresh) |
|
180 |
|
|
181 | 176 |
# DEBUG |
182 | 177 |
''' |
183 | 178 |
if __debug__: |
... | ... | |
267 | 262 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
268 | 263 |
|
269 | 264 |
return self.path |
270 |
# |
|
271 |
# @brief called when scene is changed |
|
272 |
# @author humkyung |
|
273 |
# @date 2018.04.10 |
|
274 |
# @history 18.04.11 Jeongwoo ResultTreeWidget(SymbolExplorer) |
|
275 |
#''' |
|
276 |
#def sceneChanged(self, data): |
|
277 |
# print("changed") |
|
278 |
# pass |
|
279 | 265 |
|
280 | 266 |
''' |
281 | 267 |
@brief create a symbol |
... | ... | |
322 | 308 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
323 | 309 |
|
324 | 310 |
''' |
325 |
@brief remove small objects from givem image
|
|
311 |
@brief remove small objects from given image
|
|
326 | 312 |
@author humkyung |
327 | 313 |
@date 2018.04.26 |
328 | 314 |
''' |
329 | 315 |
def removeSmallObjects(self, image): |
330 |
image,contours,_ = cv2.findContours(image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE); |
|
331 |
selectedContours=[] |
|
332 |
for contour in contours: |
|
333 |
if cv2.isContourConvex(contour): |
|
334 |
approx = cv2.approxPolyDP(contour, 0.2*cv2.arcLength(contour, True), True) |
|
316 |
try: |
|
317 |
docData = AppDocData.instance() |
|
318 |
configs = docData.getConfigs('Small Object Size', 'Min Area') |
|
319 |
minArea = int(configs[0].value) if 1 == len(configs) else 20 |
|
320 |
configs = docData.getConfigs('Small Object Size', 'Max Area') |
|
321 |
maxArea = int(configs[0].value) if 1 == len(configs) else 50 |
|
322 |
|
|
323 |
#path = os.path.join(AppDocData.instance().getCurrentProject().getTempPath(), 'before_contours.png') |
|
324 |
#cv2.imwrite(path, image) |
|
325 |
|
|
326 |
_,contours,_ = cv2.findContours(image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE); |
|
327 |
selectedContours=[] |
|
328 |
for contour in contours: |
|
329 |
#if cv2.isContourConvex(contour): |
|
330 |
#approx = cv2.approxPolyDP(contour, 0.2*cv2.arcLength(contour, True), True) |
|
335 | 331 |
area = cv2.contourArea(contour) |
336 |
if area > 20 and area < 50: selectedContours.append(contour) |
|
337 |
contourImage = cv2.drawContours(image, selectedContours, -1, (255,255,255), -1); |
|
338 |
path = os.path.join(AppDocData.instance().getCurrentProject().getTempPath(), 'contours.png') |
|
339 |
cv2.imwrite(path, contourImage) |
|
332 |
if area > minArea and area < maxArea: selectedContours.append(contour) |
|
333 |
contourImage = cv2.drawContours(image, selectedContours, -1, (255,255,255), -1); |
|
334 |
#path = os.path.join(AppDocData.instance().getCurrentProject().getTempPath(), 'contours.png') |
|
335 |
#cv2.imwrite(path, contourImage) |
|
336 |
except Exception as ex: |
|
337 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
338 |
|
|
339 |
return contourImage |
|
340 | 340 |
|
341 | 341 |
''' |
342 | 342 |
@brief recognize line |
343 | 343 |
@author humkyung |
344 | 344 |
@date 2018.04.19 |
345 |
@history humkyung 2018.04.26 remove small objects before recognizing line |
|
345 | 346 |
''' |
346 | 347 |
def recognizeLine(self, MainWindow): |
347 | 348 |
from LineDetector import LineDetector |
... | ... | |
358 | 359 |
connectedLines = [] |
359 | 360 |
|
360 | 361 |
area = AppDocData.instance().getArea('Drawing') |
362 |
area.img = self.removeSmallObjects(area.img) |
|
361 | 363 |
detector = LineDetector(area.img) |
362 | 364 |
|
363 | 365 |
symbols = [] |
DTI_PID/DTI_PID/QConfigurationDialog.py | ||
---|---|---|
52 | 52 |
self.itemModel = QStandardItemModel() |
53 | 53 |
|
54 | 54 |
docData = AppDocData.instance() |
55 |
# set min,max area for small object |
|
56 |
configs = docData.getConfigs('Small Object Size', 'Min Area') |
|
57 |
self.ui.spinBoxMinArea.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxMinArea.setValue(20) |
|
58 |
configs = docData.getConfigs('Small Object Size', 'Max Area') |
|
59 |
self.ui.spinBoxMaxArea.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxMaxArea.setValue(50) |
|
60 |
# up to here |
|
61 |
|
|
55 | 62 |
windowSize = docData.getSlidingWindowSize() |
56 | 63 |
self.ui.spinBoxWidth.setValue(windowSize[0]) |
57 | 64 |
self.ui.spinBoxHeight.setValue(windowSize[1]) |
... | ... | |
109 | 116 |
@author humkyung |
110 | 117 |
@date 2018.??.?? |
111 | 118 |
@history humkyung 2018.04.24 save size unit of line no |
119 |
humkyung 2018.04.26 save min,max area for small object |
|
112 | 120 |
''' |
113 | 121 |
def accept(self): |
114 | 122 |
try: |
115 | 123 |
self.isAccepted = True |
116 | 124 |
|
117 | 125 |
configs = [] |
126 |
configs.append(Config('Small Object Size', 'Min Area', self.ui.spinBoxMinArea.value())) |
|
127 |
configs.append(Config('Small Object Size', 'Max Area', self.ui.spinBoxMaxArea.value())) |
|
118 | 128 |
configs.append(Config('Sliding Window', 'Width', self.ui.spinBoxWidth.value())) |
119 | 129 |
configs.append(Config('Sliding Window', 'Height', self.ui.spinBoxHeight.value())) |
120 | 130 |
configs.append(Config('Line No', 'Size Unit', 'Metric' if self.ui.radioButtonMetric.isChecked() else 'Inch')) |
DTI_PID/DTI_PID/UI/Configuration.ui | ||
---|---|---|
37 | 37 |
<property name="title"> |
38 | 38 |
<string>라인 검출</string> |
39 | 39 |
</property> |
40 |
<layout class="QFormLayout" name="formLayout"> |
|
41 |
<item row="0" column="0" colspan="2"> |
|
40 |
<layout class="QGridLayout" name="gridLayout_5"> |
|
41 |
<item row="0" column="0"> |
|
42 |
<layout class="QHBoxLayout" name="horizontalLayout_6"> |
|
43 |
<item> |
|
44 |
<widget class="QLabel" name="label_4"> |
|
45 |
<property name="text"> |
|
46 |
<string>Small Object Size : </string> |
|
47 |
</property> |
|
48 |
</widget> |
|
49 |
</item> |
|
50 |
<item> |
|
51 |
<widget class="QSpinBox" name="spinBoxMinArea"/> |
|
52 |
</item> |
|
53 |
<item alignment="Qt::AlignHCenter"> |
|
54 |
<widget class="QLabel" name="label_5"> |
|
55 |
<property name="text"> |
|
56 |
<string> < Area < </string> |
|
57 |
</property> |
|
58 |
</widget> |
|
59 |
</item> |
|
60 |
<item> |
|
61 |
<widget class="QSpinBox" name="spinBoxMaxArea"/> |
|
62 |
</item> |
|
63 |
</layout> |
|
64 |
</item> |
|
65 |
<item row="1" column="0"> |
|
42 | 66 |
<layout class="QHBoxLayout" name="horizontalLayout"> |
43 | 67 |
<property name="sizeConstraint"> |
44 | 68 |
<enum>QLayout::SetNoConstraint</enum> |
내보내기 Unified diff