프로젝트

일반

사용자정보

개정판 698d2bef

ID698d2bef7da7455ff2321db2f0750a8c52733832
상위 018ee240
하위 4f79bc95

함의성이(가) 약 5년 전에 추가함

issue #480: improve line detection

Change-Id: Ia38ffb29083ca08a4893245f1929da046b60fdec

차이점 보기:

DTI_PID/DTI_PID/LineDetector.py
7 7
from PyQt5.QtCore import *
8 8
from PyQt5.QtGui import *
9 9
from PyQt5.QtWidgets import *
10
from AppDocData import AppDocData
10 11

  
11 12
__author__ = "humkyung <humkyung.doftech.co.kr>"
12 13
__version__ = '1.0.0'
......
247 248
        """adjust start point of line and then return start point and thickness of line
248 249
        return -1 for thickness if fail to calculate thickness
249 250
        """
250
        from AppDocData import AppDocData
251 251

  
252 252
        app_doc_data = AppDocData.instance()
253 253
        windowSize = app_doc_data.getSlidingWindowSize()
......
314 314
                    humkyung 2018.04.12 use connection points without rotating(already rotated)
315 315
                    humkyung 2018.09.01 use connector's direction for detecting line
316 316
    '''
317

  
318 317
    def detectConnectedLine(self, symbol, offsetX, offsetY):
319 318
        res = []
320 319

  
......
384 383
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
385 384
                                                           sys.exc_info()[-1].tb_lineno)
386 385
            App.mainWnd().addMessage.emit(MessageType.Error, message)
386
    
387
    def correct_angle(self, lines):
388
        """ fix angle """
389
        from HoughBundler import HoughBundler
390

  
391
        app_doc_data = AppDocData.instance()
392
        configs = app_doc_data.getConfigs('Line', 'Diagonal')                
393
        diagonal = HoughBundler()
394
        for index in reversed(range(len(lines))):
395
            line = lines[index]
396
            angle = diagonal.get_orientation([line[0][0], line[0][1], line[1][0], line[1][1]])
397
            if not (angle < 3 or angle > 87):
398
                if configs and int(configs[0].value) is not 1:
399
                    lines.pop(index)
400
            elif angle < 3 and angle > 0:
401
                new_x = int((line[0][0] + line[1][0]) / 2)
402
                line[0][0], line[1][0] = new_x, new_x
403
            elif angle > 87 and angle < 90:
404
                new_y = int((line[0][1] + line[1][1]) / 2)
405
                line[0][1], line[1][1] = new_y, new_y
387 406

  
388 407
    def mergeLines(self, connectedLines, toler=20, symbol_areas=None):
389 408
        """merge lines(1.connect collinear lines 2.connect lines)"""
......
413 432
                        for match in matches:
414 433
                            connectedLines.remove(match)
415 434
            # up to here
435

  
436
            self.correct_angle(connectedLines)
437

  
438
            # remove overlap line
439
            #for long_line in sorted(connectedLines, key=lambda param: param.length(), reverse=True):
440
            #    for short_line in sorted(connectedLines, key=lambda param: param.length()):
441
            #        pass
442
            # up to here
416 443
        except Exception as ex:
417 444
            from App import App
418 445
            from AppDocData import MessageType
......
575 602
    '''
576 603

  
577 604
    def detectLineThickness(self, pt, dir):
578
        import math
579
        from AppDocData import AppDocData
580 605
        docData = AppDocData.instance()
581 606
        windowSize = docData.getSlidingWindowSize()
582 607

  
......
588 613
        if black == self._image[pt[1] + round(dir[1] * windowSize[1]), pt[0] + round(dir[0] * windowSize[1])]:
589 614
            _pt = [pt[0] + round(dir[0] * windowSize[1]), pt[1] + round(dir[1] * windowSize[1])]
590 615
        else:
591
            return windowSize[1]
616
            return int(windowSize[1] / 2)
592 617

  
593 618
        color = black
594 619
        lhs = [pt[0], pt[1]]
......
614 639

  
615 640
    def detectLine(self, pt, dir, thickness, forward):
616 641
        """detect a line along given direction"""
617
        from AppDocData import AppDocData
618 642

  
619 643
        app_doc_data = AppDocData.instance()
620 644
        lineLengthConfigs = app_doc_data.getConfigs('Small Line Minimum Length', 'Min Length')
......
695 719
        """detect remain line after detecting symbol"""
696 720

  
697 721
        import os
698
        from AppDocData import AppDocData
699 722
        from HoughBundler import HoughBundler
700 723

  
701 724
        app_doc_data = AppDocData.instance()
......
734 757
            houghBundler = HoughBundler().process_lines(lines, None)
735 758

  
736 759
            remainLines = []
760
            configs = app_doc_data.getConfigs('Flow Mark', 'Length')
761
            min_length = int(configs[0].value) if 1 == len(configs) else 200
762

  
737 763
            for line in houghBundler:
738
                remainLines.append([[line[0][0], line[0][1]], [line[1][0], line[1][1]]])
764
                dx = line[0][0] - line[1][0]
765
                dy = line[1][0] - line[1][1]
766
                length = math.sqrt(dx * dx + dy * dy)
767

  
768
                if length > min_length:
769
                    remainLines.append([[line[0][0], line[0][1]], [line[1][0], line[1][1]]])
739 770

  
740 771
            # border line check
741 772
            borderRate = 0.07
......
753 784
                        self._image.shape[0] - borderY:
754 785
                    remainLines.pop(index)
755 786

  
787
            self.correct_angle(remainLines)
788

  
756 789
            return remainLines
757 790

  
758 791
    '''
......
763 796

  
764 797
    def saveImage(self):
765 798
        import datetime
766
        from AppDocData import AppDocData
767 799

  
768 800
        try:
769 801
            nowDate = datetime.datetime.now()
DTI_PID/DTI_PID/MainWindow.py
2554 2554
            project = docData.getCurrentProject()
2555 2555
            windowSize = docData.getSlidingWindowSize()
2556 2556

  
2557
            thickness = int(windowSize[1])
2557
            thickness = int(windowSize[1] / 2)
2558 2558

  
2559 2559
            if docData.needReOpening is not None:
2560 2560
                docData.needReOpening = True
DTI_PID/DTI_PID/RecognitionDialog.py
726 726
        from EngineeringTextItem import QEngineeringTextItem
727 727
        from EngineeringLineItem import QEngineeringLineItem
728 728
        from LineDetector import LineDetector
729
        from HoughBundler import HoughBundler
730 729

  
731 730
        try:
732 731
            listWidget.addItem('Starting line recognition')
......
761 760
            if configs and int(configs[0].value) is 1:
762 761
                remainLines = detector.detect_line_without_symbol()
763 762
                windowSize = app_doc_data.getSlidingWindowSize()
764
                thickness = int(windowSize[1])
765

  
766
                configs = app_doc_data.getConfigs('Line', 'Diagonal')
767
                if configs and int(configs[0].value) is not 1:
768
                    diagonal = HoughBundler()
769
                    for index in reversed(range(len(remainLines))):
770
                        angle = diagonal.get_orientation([remainLines[index][0][0], remainLines[index][0][1], remainLines[index][1][0], remainLines[index][1][1]])
771
                        if not (angle < 3 or angle > 87):
772
                            remainLines.pop(index)
763
                thickness = int(windowSize[1] / 2)
773 764

  
774 765
                for line in remainLines:
775 766
                    line.append(thickness)
DTI_PID/DTI_PID/UI/Configuration.ui
600 600
            <item row="5" column="0">
601 601
             <widget class="QLabel" name="label_45">
602 602
              <property name="text">
603
               <string>Detect Without Symbol</string>
603
               <string>Detect Without Symbol : </string>
604 604
              </property>
605 605
             </widget>
606 606
            </item>
......
1605 1605
  </connection>
1606 1606
 </connections>
1607 1607
 <buttongroups>
1608
  <buttongroup name="buttonGroup_4"/>
1609
  <buttongroup name="buttonGroup_5"/>
1610 1608
  <buttongroup name="buttonGroup_3"/>
1611 1609
  <buttongroup name="buttonGroup_2"/>
1610
  <buttongroup name="buttonGroup_5"/>
1611
  <buttongroup name="buttonGroup_4"/>
1612 1612
  <buttongroup name="buttonGroup"/>
1613 1613
 </buttongroups>
1614 1614
</ui>

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)