개정판 c12ca4e3
Remove small objects before recognizing line
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 | ||
176 | 181 |
# DEBUG |
177 | 182 |
''' |
178 | 183 |
if __debug__: |
... | ... | |
317 | 322 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
318 | 323 | |
319 | 324 |
''' |
325 |
@brief remove small objects from givem image |
|
326 |
@author humkyung |
|
327 |
@date 2018.04.26 |
|
328 |
''' |
|
329 |
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) |
|
335 |
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) |
|
340 | ||
341 |
''' |
|
320 | 342 |
@brief recognize line |
321 | 343 |
@author humkyung |
322 | 344 |
@date 2018.04.19 |
내보내기 Unified diff