프로젝트

일반

사용자정보

개정판 27b83026

ID27b83026538803e1638f7a26fe7df6465ecf3b6b
상위 a2fb89cf
하위 08e90cd7

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

issue #486: remain color

차이점 보기:

DTI_PID/DTI_PID/LineNoTracer.py
161 161
                        remainLineNos.append(lineno)
162 162
                
163 163
                ## lineIndicator
164
                extendPixel = 10
164 165
                for lineIndicator in self._lineIndicator:
165 166
                    maxOverLap = 0
166 167
                    matchLineNo = None
......
176 177
                                if x1 - x2 is 0:
177 178
                                    xOverlap = True
178 179
                                    w += 1
180
                        if not xOverlap:
181
                            continue
179 182
                        for y1 in range(reNoRect[1], reNoRect[3] + 1):
180 183
                            for y2 in range(liInRect[1], liInRect[3] + 1):
181 184
                                if y1 - y2 is 0:
......
185 188
                        if not xOverlap or not yOverlap:
186 189
                            continue
187 190
                        overLapRate = (w / lineIndicator.boundingRect().width() * 100) if lineIndicator.boundingRect().width() > lineIndicator.boundingRect().height() else (h / lineIndicator.boundingRect().height() * 100)
188
                        print(overLapRate)
191
                        #print(overLapRate)
189 192
                        if maxOverLap < overLapRate:
190 193
                            maxOverLap = overLapRate
191 194
                            matchLineNo = remainLineNo
192
                            lineIndicator.setBrush(QBrush(QColor(255, 0, 0, 127)))
195
                            #lineIndicator.setBrush(QBrush(QColor(255, 0, 0, 127)))
193 196

  
194 197
                    if matchLineNo is not None:
195
                        print(matchLineNo.text() + ' indicator : ' + str(lineIndicator.boundingRect().x()) + ', ' + str(lineIndicator.boundingRect().y()))
198
                        #print(matchLineNo.text() + ' indicator : ' + str(lineIndicator.boundingRect().x()) + ', ' + str(lineIndicator.boundingRect().y()))
196 199
                        matchLine = None
197
                        x1, y1, x2, y2 = lineIndicator.otherLine[0], lineIndicator.otherLine[1], lineIndicator.otherLine[2], lineIndicator.otherLine[3]
198
                        startXorY = (min(liInRect[0], liInRect[2]) - 4) if lineIndicator.isVH == 'V' else (min(liInRect[1], liInRect[3]) - 4)
199
                        endXorY = (max(liInRect[0], liInRect[2]) - 4) if lineIndicator.isVH == 'V' else (max(liInRect[1], liInRect[3]) - 4)
200
                        x1, y1, x2, y2 = round(lineIndicator.boundingRect().x() + lineIndicator.otherLine[0]), round(lineIndicator.boundingRect().y() + lineIndicator.otherLine[1]), round(lineIndicator.boundingRect().x() + lineIndicator.otherLine[2]), round(lineIndicator.boundingRect().y() + lineIndicator.otherLine[3])
201
                        startXorY = (min(liInRect[0], liInRect[2]) - extendPixel) if lineIndicator.isVH == 'V' else (min(liInRect[1], liInRect[3]) - extendPixel)
202
                        endXorY = (max(liInRect[0], liInRect[2]) + extendPixel) if lineIndicator.isVH == 'V' else (max(liInRect[1], liInRect[3]) + extendPixel)
200 203
                        fXorY = []
201 204
                        for dXOrdY in range(startXorY, endXorY + 1): # if horizontal -> Y, if vertical -> X
202 205
                            if lineIndicator.isVH == 'V':
203
                                fXorY.append(((y2-y1)/(x2-x1))*dXOrdY + y1 - ((y2-y1)/(x2-x1))*x1) # f(x)
206
                                fXorY.append(round(((y2-y1)/(x2-x1))*dXOrdY + y1 - ((y2-y1)/(x2-x1))*x1)) # f(x)
204 207
                            else:
205
                                fXorY.append(((x2-x1)/(y2-y1))*dXOrdY + x1 - ((x2-x1)/(y2-y1))*x1) # f(y)
208
                                fXorY.append(round(((x2-x1)/(y2-y1))*dXOrdY + x1 - ((x2-x1)/(y2-y1))*y1)) # f(y)
206 209

  
207 210
                        for line in self._lines:
208 211
                            axis1Overlap = False
......
211 214

  
212 215
                            if lineIndicator.isVH == 'V':
213 216
                                range11 = range(startXorY, endXorY + 1)
214
                                range12 = range(lX1, lX2 + 1)
217
                                range12 = range(min(lX1, lX2), max(lX1, lX2)+ 1)
215 218
                                range21 = fXorY
216
                                range22 = range(lY1, lY2 + 1)
219
                                range22 = range(min(lY1, lY2), max(lY1, lY2) + 1)
217 220
                            else:
218 221
                                range11 = range(startXorY, endXorY + 1)
219
                                range12 = range(lY1, lY2 + 1)
222
                                range12 = range(min(lY1, lY2), max(lY1, lY2) + 1)
220 223
                                range21 = fXorY
221
                                range22 = range(lX1, lX2 + 1)
224
                                range22 = range(min(lX1, lX2), max(lX1, lX2) + 1)
222 225

  
223 226
                            for axis11 in range11:
224 227
                                for axis12 in range12:
......
226 229
                                        axis1Overlap = True
227 230
                                        break
228 231
                                if axis1Overlap: break
232
                            if not axis1Overlap:
233
                                continue
229 234
                            for axis21 in range21:
230 235
                                for axis22 in range22:
231 236
                                    if axis21 - axis22 is 0:
......
238 243
                                break
239 244
                        if matchLine is not None:
240 245
                            matchLineNo.conns.append(matchLine)
241
                            print('connected ' + matchLineNo.text() + 'and ' + matchLine.uid)                     
246
                            lineIndicator.lineIndicator = 'Match'
247
                            lineIndicator.setBrush(QBrush(QColor(0, 0, 255, 127)))
248
                            #print('connected ' + matchLineNo.text() + ' and ' + matchLine.uid)                     
242 249
                ## up to here
243 250
                            
244 251
                # set start line's owner
DTI_PID/DTI_PID/MainWindow.py
1688 1688
                    approx = cv2.approxPolyDP(contour, epsilon, True)
1689 1689
                    approx = [pt[0] for pt in approx]
1690 1690
                    isLineNoInd, isVH, otherLine = self.isLineNoIndicator(idx, contours, imgNot)
1691
                    if isLineNoInd:
1692
                        item = QEngineeringUnknownItem(approx, True, isVH, otherLine)
1691
                    if isLineNoInd == 'True':
1692
                        item = QEngineeringUnknownItem(approx, isLineNoInd, isVH, otherLine)
1693 1693
                        docData.lineIndicators.append(item)
1694 1694
                    else:
1695
                        item = QEngineeringUnknownItem(approx, False)
1695
                        item = QEngineeringUnknownItem(approx, isLineNoInd)
1696 1696
                        docData.unknowns.append(item)
1697 1697
                    item.area = 'Drawing'
1698 1698
                    docData.allItems.append(item)
......
1720 1720
        import math
1721 1721
        [x, y, w, h] = cv2.boundingRect(contours[idx])
1722 1722
        if (w < 250 and h < 250):
1723
            return (False, None, None)
1723
            return ('False', None, None)
1724 1724

  
1725 1725
        fLines = []
1726
        maxDifAngle = 3
1726 1727
        mask = np.zeros_like(imgNot)
1727 1728
        cv2.drawContours(mask, contours, idx, 123, -1) # Draw filled contour in mask
1728 1729
        out = np.zeros_like(imgNot) # Extract out the object and place into output image
......
1740 1741
        edged2 = cv2.Canny(out, 100, 200)
1741 1742
        lines = cv2.HoughLines(edged2, 1, np.pi/180, 60)
1742 1743
        if lines is None:
1743
            return (False, None, None)
1744
            return ('False', None, None)
1744 1745
        for line in lines:
1745 1746
            r, theta = line[0]
1746 1747
            a, b = np.cos(theta), np.sin(theta)
1747 1748
            x0, y0 = a * r, b * r
1748 1749
            x1, y1 = int(x0 + 1000 * (-b)), int(y0 + 1000 * a)
1749 1750
            x2, y2 = int(x0 - 1000 * (-b)), int(y0 - 1000 * a)
1750
            cv2.line(out, (x1, y1), (x2, y2), (0, 255, 0), 3)
1751
            #cv2.line(out, (x1, y1), (x2, y2), (0, 255, 0), 3)
1751 1752
            degree = math.atan2(y2 - y1, x2 - x1) * 180 / math.pi
1752 1753
            fLine = [x1, y1, x2, y2, degree]
1753 1754
            fLines.append(fLine)
......
1758 1759
        isVH = None
1759 1760
        for fLine in fLines:
1760 1761
            degree = math.fabs(fLine[4])
1761
            if degree >= 88:
1762
            if degree >= 90 - maxDifAngle:
1762 1763
                verLines.append(fLine)
1763
            elif degree <= 2:
1764
            elif degree <= maxDifAngle:
1764 1765
                horLines.append(fLine)
1765 1766
            else:
1766 1767
                otherLines.append(fLine)
1767 1768
        if (len(horLines) > 0 and len(verLines) > 0) or len(otherLines) is 0 or (len(horLines) == 0 and len(verLines) == 0):
1768
            return (False, None, None)
1769
            return ('False', None, None)
1769 1770

  
1770 1771
        baseLines = []
1771 1772
        baseDifV = 0
......
1783 1784
            baseDifV = maxDifW
1784 1785
            for verLine in verLines:
1785 1786
                x1, y1, x2, y2 = verLine[0], verLine[1], verLine[2], verLine[3]
1786
                x = ((x2-x1)/(y2-y1))*y + x1 - ((x2-x1)/(y2-y1))*x1
1787
                x = ((x2-x1)/(y2-y1))*y + x1 - ((x2-x1)/(y2-y1))*y1
1787 1788
                verLine.append(x)
1788 1789
            baseLines = verLines
1789 1790
            isVH = 'V'
......
1804 1805
                j += 1
1805 1806
            i += 1
1806 1807
        if not isSameLine:
1807
            return (False, None, None)
1808
            return ('False', None, None)
1808 1809

  
1809 1810
        isSameLine = True
1810 1811
        i = 0
......
1823 1824
                    j += 1
1824 1825
                    continue
1825 1826
                difV = math.fabs(otherLine[4] - otherLinee[4])
1826
                if difV > 2:
1827
                if difV > maxDifAngle:
1827 1828
                   isSameLine = False
1828 1829
                   break
1829 1830
                j += 1
1830 1831
            i += 1
1831 1832
        if not isSameLine:
1832
            return (False, None, None)
1833
            return ('False', None, None)
1833 1834
                
1834 1835
        isSameLine = True
1835 1836
        mergedOtherLine = [0, 0, 0, 0]
......
1855 1856
            mergedOtherLine[2] += otherLine[2]
1856 1857
            mergedOtherLine[3] += otherLine[3]
1857 1858
        if not isSameLine:
1858
            (False, None, None)
1859
            ('False', None, None)
1859 1860
                        
1860 1861
        # Show the output image
1861 1862
        #print('line no indicator')
1863
        mergedOtherLine[0] = round(mergedOtherLine[0] / len(otherLines))
1864
        mergedOtherLine[1] = round(mergedOtherLine[1] / len(otherLines))
1865
        mergedOtherLine[2] = round(mergedOtherLine[2] / len(otherLines))
1866
        mergedOtherLine[3] = round(mergedOtherLine[3] / len(otherLines))
1867
        #cv2.line(out, (mergedOtherLine[0], mergedOtherLine[1]), (mergedOtherLine[2], mergedOtherLine[3]), (255, 255, 255), 3)
1862 1868
        #cv2.imshow('Output', out)
1863 1869
        #cv2.waitKey(0)
1864 1870
        #cv2.destroyAllWindows()
1865
        return (True, isVH, mergedOtherLine)
1871
        return ('True', isVH, mergedOtherLine)
1866 1872

  
1867 1873
    '''
1868 1874
        @brief      load recognition result
DTI_PID/DTI_PID/Shapes/EngineeringUnknownItem.py
54 54
        self.setZValue(QEngineeringUnknownItem.ZVALUE)
55 55

  
56 56
        self.setPen(QPen(Qt.red, 1, Qt.DashDotLine))
57
        if self.lineIndicator:
58
            self.setBrush(QBrush(QColor(0, 255, 0, 127)))
57
        if self.lineIndicator == 'Match':
58
            self.setBrush(QBrush(QColor(0, 0, 255, 127)))
59 59
        else:
60 60
            self.setBrush(QBrush(QColor(255, 255, 0, 127)))
61 61

  
......
185 185
            points = [[int(float(coord)) for coord in pt.split(',')] for pt in node.find('POINTS').text.split('\n')]
186 186
            lineIndicator = node.find('LINEINDICATOR').text.split('#')
187 187
            if lineIndicator[0] == 'True':
188
                item = QEngineeringUnknownItem(points, True, lineIndicator[1], [int(lineIndicator[2]), int(lineIndicator[3]), int(lineIndicator[4]), int(lineIndicator[5])])
188
                item = QEngineeringUnknownItem(points, 'True', lineIndicator[1], [int(lineIndicator[2]), int(lineIndicator[3]), int(lineIndicator[4]), int(lineIndicator[5])])
189
            elif lineIndicator[0] == 'Match':
190
                item = QEngineeringUnknownItem(points, 'Match', lineIndicator[1], [int(lineIndicator[2]), int(lineIndicator[3]), int(lineIndicator[4]), int(lineIndicator[5])])
189 191
            else:
190
                item = QEngineeringUnknownItem(points, False)
192
                item = QEngineeringUnknownItem(points, 'False')
191 193
            
192 194
            if node.find('AREA') is None:
193 195
                appDocData = AppDocData.instance()
......
245 247
            node.append(ptNode)
246 248

  
247 249
            lINode = Element('LINEINDICATOR')
248
            if self.lineIndicator:
250
            if self.lineIndicator == 'True':
249 251
                lINode.text = 'True' + '#' + self.isVH + '#' + str(self.otherLine[0]) + '#' + str(self.otherLine[1]) + '#' + str(self.otherLine[2]) + '#' + str(self.otherLine[3])
252
            elif self.lineIndicator == 'Match':
253
                lINode.text = 'Match' + '#' + self.isVH + '#' + str(self.otherLine[0]) + '#' + str(self.otherLine[1]) + '#' + str(self.otherLine[2]) + '#' + str(self.otherLine[3])
250 254
            else:
251 255
                lINode.text = 'False' + '#' + 'None' + '#' + 'None'
252 256
            node.append(lINode)

내보내기 Unified diff

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