프로젝트

일반

사용자정보

개정판 661c5a80

ID661c5a80593ef56456cf9a35e9dd9e2c11b315b8
상위 5c4d5e92
하위 5d8f9002

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

issue #480: detect diagonal

Change-Id: I221276c2bd787ae0356b8dc1317399597f7e1b84

차이점 보기:

DTI_PID/DTI_PID/HoughBundler.py
149 149
                    groups = self.merge_lines_pipeline_2(i)
150 150
                    merged_lines = []
151 151
                    for group in groups:
152
                        merged_lines.append(self.merge_lines_segments1(group))
152
                        #merged_lines.append(self.merge_lines_segments1(group))
153
                        merged_lines.append(self.merge_lines_minBox(group))
153 154

  
154 155
                    merged_lines_all.extend(merged_lines)
155 156

  
156 157
        return merged_lines_all
157 158

  
159
    def merge_lines_minBox(self, group):
160
        import sys
161

  
162
        # make contour from points
163
        points = []
164
        for dots in group:
165
            points.append([dots[0], dots[1]])
166
            points.append([dots[2], dots[3]])
167
        
168
        ctr = np.array(points).reshape((-1,1,2)).astype(np.int32)
169

  
170
        # get minimum bounding box
171
        rect = cv2.minAreaRect(ctr)
172
        box = cv2.boxPoints(rect)
173
        box = np.int0(box)
174

  
175
        # find minimum edge
176
        ds = [[box[0], box[1]], [box[0], box[2]], [box[0], box[3]]]
177
        rd = [[box[2], box[3]], [box[1], box[3]], [box[1], box[2]]]
178
        minD = sys.maxsize
179
        index = 0
180
        i = 0
181
        for d in ds:
182
            dx = d[0][0] - d[1][0]
183
            dy = d[0][1] - d[1][1]
184
            nD = math.sqrt((dx*dx)+(dy*dy))
185
            if minD > nD:
186
                minD = nD
187
                index = i
188
            i = i + 1
189

  
190
        lineDot1 = [round((ds[index][0][0] + ds[index][1][0]) / 2), round((ds[index][0][1] + ds[index][1][1]) / 2)]
191
        lineDot2 = [round((rd[index][0][0] + rd[index][1][0]) / 2), round((rd[index][0][1] + rd[index][1][1]) / 2)]
192

  
193
        return [lineDot1, lineDot2]
194

  
158 195
if __name__ == '__main__':
159 196

  
160 197
    rate = 60
161
    image = cv2.imread('mmm.PNG')
198
    image = cv2.imread('as.PNG')
162 199
    #image2 = cv2.imread('skel.PNG', )
163 200
    edged = cv2.Canny(image, 100, 200)
164 201

  
DTI_PID/DTI_PID/LineDetector.py
575 575
            for line in lines:
576 576
                line.drawToImage(imgDiff, 255, thickness) if line.thickness is None else line.drawToImage(imgDiff, 255, line.thickness)
577 577
            cv2.imwrite(diffFilePath, imgDiff)
578
            #cv2.imwrite(os.path.join(project.getTempPath(), "DIFF_2_" + os.path.basename(path)), imgDiff)
578 579
            ## up to here
579 580

  
580 581
            imgNot = np.ones(imgDiff.shape, np.uint8)
......
586 587
            smallContours = []
587 588
            minimumSize = docData.getConfigs('Filter', 'MinimumSize')
588 589
            lineLengthConfigs = docData.getConfigs('Small Line Minimum Length', 'Min Length')
589
            lineMinLength = int(lineLengthConfigs[0].value) if 1 == len(lineLengthConfigs) else 10
590
            lineMinLength = int(lineLengthConfigs[0].value) if 1 == len(lineLengthConfigs) else 30
590 591
            for contour in contours:
591 592
                [x, y, w, h] = cv2.boundingRect(contour)
592 593

  
......
600 601
            edged = cv2.Canny(imgNotRemoveSmall, 100, 200)
601 602

  
602 603
            rate = 25
603
            lines = cv2.HoughLinesP(image=edged, rho=1, theta=np.pi/180, threshold=rate, minLineLength=lineMinLength, maxLineGap=25)
604
            lines = cv2.HoughLinesP(image=edged, rho=1, theta=np.pi/180, threshold=rate, minLineLength=lineMinLength*2, maxLineGap=25)
604 605

  
605 606
            houghBundler = HoughBundler().process_lines(lines, None)
606 607

  
DTI_PID/DTI_PID/MainWindow.py
1721 1721
                ##
1722 1722
                smallContours = []
1723 1723
                minimumSize = docData.getConfigs('Filter', 'MinimumSize')
1724
                lineLengthConfigs = docData.getConfigs('Small Line Minimum Length', 'Min Length')
1725
                lineMinLength = int(lineLengthConfigs[0].value) if 1 == len(lineLengthConfigs) else 10
1726 1724
                for contour in contours:
1727 1725
                    [x, y, w, h] = cv2.boundingRect(contour)
1728 1726

  
......
1747 1745
                    epsilon = cv2.arcLength(contour, True)*0.001
1748 1746
                    approx = cv2.approxPolyDP(contour, epsilon, True)
1749 1747
                    approx = [pt[0] for pt in approx]
1750
                    resultStr, resultList = self.determineRemainObject(idx, contours, imgNot, lineMinLength)
1748
                    resultStr, resultList = self.determineRemainObject(idx, contours, imgNot)
1751 1749
                    if resultStr == 'LineIndicator':
1752 1750
                        item = QEngineeringUnknownItem(approx, 'True', resultList[0], resultList[1])
1753 1751
                        docData.lineIndicators.append(item)
......
1774 1772
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
1775 1773
            self.addMessage.emit(MessageType.Error, message)
1776 1774

  
1777
    def determineRemainObject(self, idx, contours, imgNot, lineMinLength):
1775
    def determineRemainObject(self, idx, contours, imgNot):
1778 1776
        '''
1779 1777
            @brief      determine remain objects -> line no indicator, missing line or unknown
1780 1778
            @author     euisung
......
1783 1781
        '''
1784 1782
        import math
1785 1783
        [x, y, w, h] = cv2.boundingRect(contours[idx])
1786
        if (w < lineMinLength or h < lineMinLength):
1787
            return ('Unknown', [])
1788

  
1789
        # temporary filter because there is no diagonal detection
1784
        
1790 1785
        if (w < 250 and h < 250):
1791 1786
            return ('Unknown', [])
1792 1787
        
......
1872 1867
                #print(fLines)
1873 1868
                return ('LineIndicator', [isVH, mergedOtherLine])
1874 1869

  
1875
        # determine missing line
1876
        result = self.isMissingLine(w, h, maxDifAngle, maxDifH, maxDifW, fLines, horLines, verLines, otherLines)
1877
        if result:
1878
            return ('MissingLine', [])
1879

  
1880 1870
        return ('Unknown', [])
1881 1871

  
1882
    def isMissingLine(self, w, h, maxDifAngle, maxDifH, maxDifW, fLines, horLines, verLines, otherLines):
1883
        '''
1884
            @brief      determine lines that LineDetector can not catch
1885
            @author     euisung
1886
            @date       2019.03.25
1887
        '''
1888
        mergedLines = []
1889

  
1890

  
1891

  
1892

  
1893
        return False
1894

  
1895 1872
    def isLineNoIndicator(self, w, h, maxDifAngle, baseDifV, baseLines, otherLines):
1896 1873
        '''
1897 1874
            @brief      determine line no indicator
DTI_PID/DTI_PID/RecognitionDialog.py
461 461
            listWidget.addItem(worker.tr('Creating lines...'))
462 462

  
463 463
            for pts in connectedLines:
464
                print([area.x + pts[0][0], area.y + pts[0][1],area.x + pts[1][0], area.y + pts[1][1]])
464
                #print([area.x + pts[0][0], area.y + pts[0][1],area.x + pts[1][0], area.y + pts[1][1]])
465 465
                processLine = QEngineeringLineItem(vertices=[(area.x + param[0], area.y + param[1]) for param in pts[:-1]], thickness=pts[2])
466 466
                processLine.area = 'Drawing'
467 467

  
......
476 476

  
477 477
            i = 0
478 478
            for pts in remainLine:
479
                print(i)
480
                print(pts)
479
                #print(i)
480
                #print(pts)
481 481
                i = i + 1
482 482
                processLine = QEngineeringLineItem(vertices=[(param[0], param[1]) for param in pts[:]])
483 483
                processLine.area = 'Drawing'
......
487 487

  
488 488
                if processLine.length() > 100: # TODO: check critical length
489 489
                    processLine.addFlowArrow()
490
                    #pass
491 490

  
492 491
        except Exception as ex:
493 492
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)

내보내기 Unified diff

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