개정판 a662c689
issue #000: fix line detection
Change-Id: If4607e4d111a2bfa13e744246b5734a9f544a83f
DTI_PID/DTI_PID/LineDetector.py | ||
---|---|---|
566 | 566 | |
567 | 567 |
return None |
568 | 568 | |
569 |
def detectLineWithoutSymbol(self, path, offsetX, offsetY): |
|
569 |
def detectLineWithoutSymbol(self, area):# path, offsetX, offsetY):
|
|
570 | 570 |
''' |
571 | 571 |
@brief detect remain line after detection using symbol info |
572 | 572 |
@author euisung |
... | ... | |
577 | 577 |
from HoughBundler import HoughBundler |
578 | 578 | |
579 | 579 |
docData = AppDocData.instance() |
580 |
project = docData.getCurrentProject() |
|
581 | ||
582 |
diffFilePath = os.path.join(project.getTempPath(), "DIFF_" + os.path.basename(path)) |
|
583 |
if os.path.isfile(diffFilePath): |
|
584 |
imgDiff = cv2.threshold(cv2.cvtColor(cv2.imread(diffFilePath, 1), cv2.COLOR_BGR2GRAY), 127, 255, cv2.THRESH_BINARY)[1] |
|
585 | ||
586 |
## remove already detected line |
|
587 |
lines = docData.lines |
|
588 |
for line in lines: |
|
589 |
line.drawToImage(imgDiff, 255, thickness) if line.thickness is None else line.drawToImage(imgDiff, 255, line.thickness) |
|
590 |
#cv2.imwrite(diffFilePath, imgDiff) |
|
591 |
#cv2.imwrite(os.path.join(project.getTempPath(), "DIFF_2_" + os.path.basename(path)), imgDiff) |
|
592 |
## up to here |
|
593 | ||
594 |
imgNot = np.ones(imgDiff.shape, np.uint8) |
|
595 |
cv2.bitwise_not(imgDiff, imgNot) |
|
580 |
img = area.img |
|
581 | ||
582 |
if True: |
|
583 |
imgNot = np.ones(img.shape, np.uint8) |
|
584 |
cv2.bitwise_not(img, imgNot) |
|
596 | 585 |
imgNot = cv2.dilate(imgNot, np.ones((8,8), np.uint8)) |
597 | 586 | |
598 | 587 |
image, contours, hierarchy = cv2.findContours(imgNot, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) |
... | ... | |
629 | 618 |
# border line check |
630 | 619 |
borderRate = 0.07 |
631 | 620 |
borderY, borderX = round(imgNot.shape[0] * borderRate), round(imgNot.shape[1] * borderRate) |
632 |
range(len(remainLines) - 1, -1, -1) |
|
621 | ||
633 | 622 |
for index in range(len(remainLines) - 1, -1, -1): |
634 | 623 |
if remainLines[index][0][0] < borderX and remainLines[index][1][0] < borderX: |
635 | 624 |
remainLines.pop(index) |
636 |
elif remainLines[index][0][0] > offsetX + self._image.shape[1] - borderX and remainLines[index][1][0] > offsetX + self._image.shape[1] - borderX:
|
|
625 |
elif remainLines[index][0][0] > self._image.shape[1] - borderX and remainLines[index][1][0] > self._image.shape[1] - borderX:
|
|
637 | 626 |
remainLines.pop(index) |
638 | 627 |
elif remainLines[index][0][1] < borderY and remainLines[index][1][1] < borderY: |
639 | 628 |
remainLines.pop(index) |
640 |
elif remainLines[index][0][1] > offsetY + self._image.shape[0] - borderY and remainLines[index][1][1] > offsetY + self._image.shape[0] - borderY:
|
|
629 |
elif remainLines[index][0][1] > self._image.shape[0] - borderY and remainLines[index][1][1] > self._image.shape[0] - borderY:
|
|
641 | 630 |
remainLines.pop(index) |
642 | 631 | |
643 | 632 |
return remainLines |
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
1919 | 1919 |
docData = AppDocData.instance() |
1920 | 1920 |
project = docData.getCurrentProject() |
1921 | 1921 |
windowSize = docData.getSlidingWindowSize() |
1922 |
|
|
1922 | 1923 |
thickness = int(windowSize[1]) |
1923 | 1924 | |
1924 | 1925 |
if docData.needReOpening is not None: |
DTI_PID/DTI_PID/RecognitionDialog.py | ||
---|---|---|
427 | 427 |
connectedLines.extend(res) |
428 | 428 | |
429 | 429 |
# line detection without symbol connection point info |
430 |
remainLines = detector.detectLineWithoutSymbol(path, round(area.x), round(area.y)) |
|
431 |
connectedLines.extend([[[line[0][0]-round(area.x),line[0][1]-round(area.y)],[line[1][0]-round(area.x),line[1][1]-round(area.y)],10] for line in remainLines]) |
|
430 |
remainLines = detector.detectLineWithoutSymbol(area)#path, round(area.x), round(area.y)) |
|
431 |
windowSize = appDocData.getSlidingWindowSize() |
|
432 |
thickness = int(windowSize[1]) |
|
433 |
for line in remainLines: |
|
434 |
line.append(thickness) |
|
435 |
connectedLines.extend(remainLines) |
|
436 |
#connectedLines.extend([[[line[0][0]-round(area.x),line[0][1]-round(area.y)],[line[1][0]-round(area.x),line[1][1]-round(area.y)],10] for line in remainLines]) |
|
432 | 437 | |
433 | 438 |
listWidget.addItem('Connecting lines') |
434 | 439 |
if len(connectedLines) > 1: |
내보내기 Unified diff