프로젝트

일반

사용자정보

개정판 29fa6d45

ID29fa6d455d3fddb13db77bb11116211b0938d8b9
상위 df0ec478
하위 39e90f36

백흠경이(가) 6년 이상 전에 추가함

issue #480:
- 라인 두께가 얇을때 인식하지 못하는 오류 보정

차이점 보기:

DTI_PID/DTI_PID/AppDocData.py
2574 2574
            conn.commit()
2575 2575
        # Catch the exception
2576 2576
        except Exception as ex:
2577
            from App import App
2577 2578
            # Roll back any change if something goes wrong
2578 2579
            conn.rollback()
2579
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
2580

  
2581
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
2582
            App.mainWnd().addMessage.emit(MessageType.Error, message)
2580 2583
        finally:
2581 2584
            # Close the db connection
2582 2585
            conn.close()
......
2766 2769
                from App import App
2767 2770

  
2768 2771
                message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
2769
                App.mainWin().addMessage(MessageType.Error, message)
2772
                App.mainWnd().addMessage.emit(MessageType.Error, message)
2770 2773
        finally:
2771 2774
            conn.close()
2772 2775

  
DTI_PID/DTI_PID/LineDetector.py
184 184
            white = 255
185 185
            black = 0
186 186

  
187
            norm = [-dir[1], dir[0]]
187 188
            if black == self._image[pt[1] + round(dir[1]*windowSize[1]), pt[0] + round(dir[0]*windowSize[1])]:
188 189
                _pt = [pt[0] + round(dir[0]*windowSize[1]), pt[1] + round(dir[1]*windowSize[1])]
189 190
            else:
190
                return (pt, -1)
191

  
192
            norm = [-dir[1], dir[0]]
191
                found = False
192
                for step in [1,2,-1,-2]:
193
                    if black == self._image[pt[1] + round(dir[1]*windowSize[1] + norm[1]*step), pt[0] + round(dir[0]*windowSize[1] + norm[0]*step)]:
194
                        _pt = [pt[0] + round(dir[0]*windowSize[1] + norm[0]*step), pt[1] + round(dir[1]*windowSize[1] + norm[1]*step)]
195
                        found = True
196
                        break
197

  
198
                if not found: return (pt, -1)
193 199

  
194 200
            color = black 
195 201
            lhs = [_pt[0], _pt[1]]
DTI_PID/DTI_PID/MainWindow.py
384 384
        '''
385 385
        from AppDocData import AppDocData
386 386

  
387
        appDocData = AppDocData.instance()
387
        try:
388
            appDocData = AppDocData.instance()
388 389

  
389
        appDocData.deleteDataListBeforeSave()
390
        
391
        titleBlockProps = appDocData.getTitleBlockProperties()
392
        #items = self.graphicsView.scene.items()
393
        items = appDocData.allItems
394
        titleBlockItems = []
395
        for item in items:
396
            if type(item) is QEngineeringLineNoTextItem:
397
                item.saveLineData()
390
            appDocData.deleteDataListBeforeSave()
391
            
392
            titleBlockProps = appDocData.getTitleBlockProperties()
393
            #items = self.graphicsView.scene.items()
394
            items = appDocData.allItems
395
            titleBlockItems = []
396
            for item in items:
397
                if type(item) is QEngineeringLineNoTextItem:
398
                    item.saveLineData()
398 399

  
399
            elif type(item) is QEngineeringTextItem:
400
                for titleBlockProp in titleBlockProps:
401
                    if item.area == titleBlockProp[0]:
402
                        titleBlockItems.append(item)
400
                elif type(item) is QEngineeringTextItem:
401
                    for titleBlockProp in titleBlockProps:
402
                        if item.area == titleBlockProp[0]:
403
                            titleBlockItems.append(item)
403 404

  
404
        dbItems = [item for item in items if type(item) is QEngineeringInstrumentItem or type(item) is QEngineeringEquipmentItem or\
405
        type(item) is QEngineeringNoteItem or type(item) is SymbolSvgItem] + titleBlockItems
406
        appDocData.saveToDatabase(dbItems)
405
            dbItems = [item for item in items if type(item) is QEngineeringInstrumentItem or type(item) is QEngineeringEquipmentItem or\
406
            type(item) is QEngineeringNoteItem or type(item) is SymbolSvgItem] + titleBlockItems
407
            appDocData.saveToDatabase(dbItems)
408
        except Exception as ex:
409
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
410
            self.addMessage.emit(MessageType.Error, message)
407 411

  
408 412
    '''
409 413
        @brief      action save click event
DTI_PID/DTI_PID/RecognitionDialog.py
61 61
    finished = pyqtSignal()
62 62
    intReady = pyqtSignal(int)
63 63
    displayTitle = pyqtSignal(str)
64
    #drawDetectedItems = pyqtSignal(list, list, list, list, QObject)
65
    #drawDetectedLines = pyqtSignal(list, QObject)
66
    #drawUnknownItems = pyqtSignal(str, QObject)
67 64
    displayMessage = pyqtSignal(QListWidgetItem)
68 65
    updateProgress = pyqtSignal(int, str)
69 66
    updateBatchProgress = pyqtSignal(int, int)
......
632 629
                    overlapArea = 0
633 630
                    symbolIndex = -1
634 631
                    for i in range(len(searchedSymbolList)):
635
                        '''
636
                        _pt = searchedSymbolList[i].getSp()
637
                        rect = QRectF(_pt[0], _pt[1], searchedSymbolList[i].getWidth(), searchedSymbolList[i].getHeight())
638
                        _rect = QRectF(searchedItemSp[0], searchedItemSp[1], sw, sh)
639
                        if rect.intersects(_rect):
640
                            intersect = rect.intersected(_rect)
641
                            overlapArea = intersect.width()*intersect.height()
642
                            if overlapArea > sw*sh*0.1:
632
                        area = Worker.contains(searchedSymbolList[i], searchedItemSp, sw, sh)
633
                        if area > ACCEPT_OVERLAY_AREA:
634
                            if area > overlapArea:
635
                                overlapArea = area
643 636
                                symbolIndex = i
644
                                break
645
                        '''
646
                        overlapArea = Worker.contains(searchedSymbolList[i], searchedItemSp, sw, sh)
647
                        if overlapArea > ACCEPT_OVERLAY_AREA:
637
                            """
648 638
                            categories = [appDocData.isEquipmentType(symbolType), appDocData.isEquipmentType(searchedSymbolList[i].getType())]
649 639
                            if categories[0] == categories[1]:
650 640
                                symbolIndex = i
651 641
                                break
642
                            """
652 643
                            
653 644
                    hitRate = tmRes[pt[1], pt[0]]
654 645
    
......
675 666
                                                                        ','.join(str(x) for x in originalPoint), 
676 667
                                                                        '/'.join('{},{},{}'.format(param[0], param[1], param[2]) for param in connectionPoint), 
677 668
                                                                        baseSymbol, additionalSymbol,isExceptDetect)
678
                                    ## DEBUG
679
                                    ##message = '//// {}:{}-{} ////'.format(symbolName, searchedItemSp, hitRate)
680
                                    ##worker.displayLog.emit(MessageType.Normal, message)
681
                                    ## up to here
682
    
683 669
                                    threadLock.release()
684 670
                            ## 현재 심볼과 검출된 심볼이 같지 않을 경우 (포함)
685 671
                            elif appDocData.isEquipmentType(searchedSymbol.getType()):
686
                                ## DEBUG
687
                                message = '{}->{}:{}-{}'.format(searchedSymbol.getName(), symbolName, searchedItemSp, hitRate)
688
                                worker.displayLog.emit(MessageType.Normal, message)
689
                                ## up to here
690
    
691
                                threadLock.acquire()
692
                                foundSymbolCount = foundSymbolCount + 1
693
                                Worker.addSearchedSymbol(symbolName, symbolType , 
694
                                    searchedItemSp, sw, sh, symbolThreshold, hitRate, hitRate, symbolRotatedAngle , 
695
                                    isDetectOnOrigin, symbolRotateCount, symbolOcrOption, isContainChild , 
696
                                    originalPoint, connectionPoint, baseSymbol, additionalSymbol,isExceptDetect)
697
                                threadLock.release()
698
                                        
672
                                if searchedSymbol.area > sw*sh*10:  # searched equipment area is greather than 10 times of symbol's area
673
                                    threadLock.acquire()
674
                                    foundSymbolCount = foundSymbolCount + 1
675
                                    Worker.addSearchedSymbol(symbolName, symbolType , 
676
                                        searchedItemSp, sw, sh, symbolThreshold, hitRate, hitRate, symbolRotatedAngle , 
677
                                        isDetectOnOrigin, symbolRotateCount, symbolOcrOption, isContainChild , 
678
                                        originalPoint, connectionPoint, baseSymbol, additionalSymbol,isExceptDetect)
679
                                    threadLock.release()
680
                            else:
681
                                searchedSymbol = searchedSymbolList[symbolIndex]
682
                                symbolHitRate = searchedSymbol.getHitRate()
683
                                if symbolHitRate < hitRate:
684
                                    threadLock.acquire()
685
                                    searchedSymbolList[symbolIndex] = symbol.Symbol(symbolName, symbolType , 
686
                                                                        searchedItemSp, sw, sh, symbolThreshold, symbolMinMatchCount, hitRate, symbolRotatedAngle , 
687
                                                                        isDetectOnOrigin, symbolRotateCount, symbolOcrOption, isContainChild , 
688
                                                                        ','.join(str(x) for x in originalPoint), 
689
                                                                        '/'.join('{},{},{}'.format(param[0], param[1], param[2]) for param in connectionPoint), 
690
                                                                        baseSymbol, additionalSymbol,isExceptDetect)
691
                                    threadLock.release()
692

  
699 693
                ## Rotate Symbol
700 694
                symGray = cv2.rotate(symGray, cv2.ROTATE_90_COUNTERCLOCKWISE)
701 695
                symbolRotatedAngle = symbolRotatedAngle + 90
......
1448 1442

  
1449 1443
        try:
1450 1444
            self.ui.buttonBox.setEnabled(True)
1451

  
1445
            
1446
            self.ui.progressBar.setValue(self.ui.progressBar.maximum())
1452 1447
            #if not self.batch:
1453 1448
            #    self.parent.drawDetectedItemsToScene()
1454 1449
        except Exception as ex:
......
1497 1492
        try:
1498 1493
            self.parent.drawUnknownItems(path)
1499 1494
        finally:
1500
            loop.quit()  
1501

  
1502
    '''
1503
        @history    2018.05.25  Jeongwoo    Moved from MainWindow
1504
                    2018.05.28  Jeongwoo    Add xmlPath Parameter and append LineInfo into xml
1505
                    2018.05.29  Jeongwoo    Change method to add item
1506
                    2018.05.30  Jeongwoo    Remove parameter (xmlPath)
1507
                    humkyung 2018.06.11 add drawing path to parameter and write recognized lines to image
1508
                    humkyung 2018.07.04 call arrangeLinePosition after creating line
1509
    '''
1510
    '''
1511
    def recognizeLine(self, path, listWidget, graphicsView, worker):
1512
        from shapely.geometry import Point, LineString
1513
        from SymbolSvgItem import SymbolSvgItem
1514
        from QEngineeringFlowArrowItem import QEngineeringFlowArrowItem
1515
        from EngineeringLineNoTextItem import QEngineeringLineNoTextItem
1516
        from EngineeringTextItem import QEngineeringTextItem
1517
        from EngineeringLineItem import QEngineeringLineItem
1518
        from LineDetector import LineDetector
1519
    
1520
        try:
1521
            listWidget.addItem('Starting line recognization')
1522
    
1523
            #remove already existing line and flow arrow item
1524
            items = [item for item in worker.graphicsView.scene.items() if (type(item) is QEngineeringLineItem) or (type(item) is QEngineeringFlowArrowItem)]
1525
            for item in items:
1526
                worker.graphicsView.scene.removeItem(item)
1527
            #up to here
1528
    
1529
            # detect line
1530
            connectedLines = []
1531
    
1532
            area = AppDocData.instance().getArea('Drawing')
1533
            area.img = worker.removeSmallObjects(area.img)
1534
            detector = LineDetector(area.img)
1535
    
1536
            symbols = []
1537
            for item in worker.graphicsView.scene.items():
1538
                if issubclass(type(item), SymbolSvgItem):
1539
                    symbols.append(item)
1540
                    res = detector.detectConnectedLine(item, round(area.x), round(area.y))
1541
                    if res is not None:
1542
                        connectedLines.extend(res)
1543
    
1544
            listWidget.addItem('Connecting lines')
1545
            if len(connectedLines) > 1:
1546
                detector.mergeLines(connectedLines, toler=5)
1547
                # connect line to symbol
1548
                try:
1549
                    for line in connectedLines:
1550
                        matches = [symbol for symbol in symbols if symbol.isConnectable(line, (round(area.x), round(area.y)), toler=20)]
1551
                        for symbol in matches:
1552
                            detector.connectLineToSymbol(line, (round(area.x), round(area.y)), symbol)
1553
                except Exception as ex:
1554
                    message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
1555
                    MainWindow.instance().displayMessage.emit(MessageType.Error, message)
1556
                # up to here
1557
    
1558
                # connect line to line
1559
                toler = 10
1560
                try:
1561
                    for line in connectedLines:
1562
                        matches = [it for it in connectedLines if (it is not line) and (not detector.isParallel(line, it))]
1563
    
1564
                        # get closest line
1565
                        selected = []
1566
                        shapelyLine = LineString(line)
1567
                        for match in matches:
1568
                            dist = [shapelyLine.distance(Point(match[0][0], match[0][1])),shapelyLine.distance(Point(match[1][0], match[1][1]))]
1569
                            if dist[0] < toler or dist[1] < toler:
1570
                                selected.append(match)
1571
                        # up to here
1572
    
1573
                        for match in selected:
1574
                            detector.connectLineToLine(match, line, toler)
1575
                except Exception as ex:
1576
                    message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
1577
                    workder.displayLog.emit(MessageType.Error, message)
1578
                # up to here
1579
    
1580
            for pts in connectedLines:
1581
                processLine = QEngineeringLineItem(vertices=[(area.x + param[0], area.y + param[1]) for param in pts])
1582
                graphicsView.scene.addItem(processLine)
1583
                #lines.append(processLine)
1584
    
1585
                if processLine.length() > 100: # TODO: check critical length
1586
                    processLine.addFlowArrow()
1587
            
1588
            # re-order process line's start,end according to flow mark
1589
            worker.arrangeLinePosition(lines, symbols, listWidget)
1590
            # up to here
1591
        except Exception as ex:
1592
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
1593
            worker.displayLog.emit(MessageType.Error, message)
1594
        finally:
1595
            listWidget.addItem('Finished line recognization')
1596
            worker.finished.emit()
1597
    '''
1495
            loop.quit()  
DTI_PID/DTI_PID/symbol.py
23 23
        self.rotatedAngle = rotatedAngle
24 24
        self.text = ''
25 25

  
26
    @property
27
    def area(self):
28
        '''
29
        return area of symbol
30
        '''
31
        return self.width*self.height
32

  
26 33
    '''
27 34
        @brief      
28 35
        @author

내보내기 Unified diff

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