프로젝트

일반

사용자정보

개정판 40b4bfe5

ID40b4bfe529f33e98c8efe185d7ce78f29a157767
상위 e605f280
하위 f1427639

humkyung 이(가) 약 7년 전에 추가함

1. Add QEngineeringLineItem,QGraphicsBoundingBoxItem,QRecognitionDialog
2. Add isTreated attribute to AbstractCommand

차이점 보기:

DTI_PID/DTI_PID/DTI_PID.py
37 37
from PyQt5.QtSvg import *
38 38
import DTI_PID_UI
39 39
import QtImageViewer
40
import SymbolSvg
41 40

  
42 41
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\Commands')
43 42
import CreateCommand
......
45 44

  
46 45
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\Shapes')
47 46
import QGraphicsPolylineItem
47
from QEngineeringLineItem import QEngineeringLineItem
48
from SymbolSvg import SymbolSvg
49
from QGraphicsBoundingBoxItem import QGraphicsBoundingBoxItem
48 50
#endregion
49 51

  
50 52
## Tesseract path
......
726 728
    global threadLock
727 729
    global textInfoList
728 730
    
731
    res = []
729 732
    try:
730 733
        srcList = []
731 734
        srcList.append(path)
......
795 798
            ####### Potrace
796 799
            imgLineList = potrace.passpotrace(removedSymbolImgPath)
797 800

  
798

  
799
            xg.writeXml(srcName, srcWidth, srcHeight, searchedSymbolList, textInfoList, imgLineList)
801
            xmlPath = xg.writeXml(srcName, srcWidth, srcHeight, searchedSymbolList, textInfoList, imgLineList)
802
            res.append(xmlPath)
800 803
            
801 804
            listWidget.addItem("Searched symbol count : " + str(len(searchedSymbolList)))
802 805

  
......
814 817
        msg.setText(ex)
815 818
        msg.exec_()
816 819
    
820
    return res
821
    
817 822
class Worker(QObject):
818 823
    from PyQt5.QtCore import QThread
819 824
    from PyQt5.QtWidgets import QApplication, QLabel, QWidget, QGridLayout
......
824 829

  
825 830
    #pyqtSlot()
826 831
    def procCounter(self): # A slot takes no params
827
        main(self.path, self.listWidget)
832
        self.xmlPath = main(self.path, self.listWidget)
828 833
        self.finished.emit()
829 834

  
830 835
class ExampleApp(QMainWindow, DTI_PID_UI.Ui_MainWindow):
......
838 843
        # connect signals and slots
839 844
        self.actionClose.triggered.connect(self.close)
840 845
        self.actionOpen.triggered.connect(self.openImageDrawing)
846
        self.actionEqpNozzle.triggered.connect(self.connectEqpNozzle)
847
        self.actionLine.triggered.connect(self.createLine)
841 848
        self.actionRecognition.triggered.connect(self.recognize)
842 849
    
843 850
    '''
......
846 853
    def openImageDrawing(self, MainWindow):
847 854
        self.path = self.graphicsView.loadImageFromFile()
848 855

  
849
        svg = SymbolSvg.SymbolSvg()
856
        svg = SymbolSvg()
850 857
        svg.setPos(100,100) 
851 858
        self.graphicsView.scene.addItem(svg)
852 859

  
860
        return self.path
861

  
862
    '''
863
        @brief  connect equipment and nozzle
864
    '''
865
    def connectEqpNozzle(self):
866
        self.graphicsView.command = None
867

  
868
    '''
869
        @brief  create a line
870
    '''
871
    def createLine(self):
853 872
        # set imageviewer's command
854
        self.graphicsView.command = CreateCommand.CreateCommand(self.graphicsView, QGraphicsPolylineItem.QGraphicsPolylineItem())
873
        self.graphicsView.command = CreateCommand.CreateCommand(self.graphicsView, QEngineeringLineItem())
855 874
        # up to here
856 875

  
857
        return self.path
858

  
859 876
    '''
860 877
        @brief recognize symbol and text
861 878
    '''
862 879
    def recognize(self, MainWindow):
863
        import Recognition_UI
880
        from QRecognitionDialog import QRecognitionDialog
864 881

  
865 882
        try:
866
            self.dlg = QDialog(self)
867
            self.ui = Recognition_UI.Ui_Recognition()
868
            self.ui.setupUi(self.dlg)
883
            self.dlg = QRecognitionDialog(self)
869 884
            self.startThread()
870 885
            self.dlg.show()
871 886
            self.dlg.exec_()
887

  
888
            if self.dlg.isAccepted == True:
889
                self.loadRecognitionResult(self.xmlPath[0])
872 890
        except Exception as ex:
873
            print('에러가 발생했습니다.\n', ex)
891
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
892

  
893
    '''
894
        @brief load recognition result
895
    '''
896
    def loadRecognitionResult(self, xmlPath):
897
        from xml.etree.ElementTree import Element, SubElement, dump, ElementTree, parse
898

  
899
        try:
900
            #xml = parse('d:\\Projects\\DTIPID\\DTI_PID\\DTI_PID\\res\\Result\\UY1-K-2007_P1_300dpi_black.xml')
901
            xml = parse(xmlPath)
902
            root = xml.getroot();
903
            for symbol in root.iter('SYMBOL'):
904
                pt = symbol.find('STARTPOINT').text.split(',')
905
                size = symbol.find('SIZE').text.split(',')
906
                item = QGraphicsBoundingBoxItem(float(pt[0]), float(pt[1]), float(size[0]), float(size[1]))
907
                item.setPen(QPen(Qt.red, 20, Qt.SolidLine))
908
                self.graphicsView.scene.addItem(item)
909
            for text in root.iter('TEXTINFO'):
910
                x = float(text.find('X').text)
911
                y = float(text.find('Y').text)
912
                width = float(text.find('WIDTH').text)
913
                height = float(text.find('HEIGHT').text)
914
                item = QGraphicsBoundingBoxItem(x, y, width, height)
915
                item.setPen(QPen(Qt.blue, 20, Qt.SolidLine))
916
                self.graphicsView.scene.addItem(item)
917
        except Exception as ex:
918
            print('error occured {} as at {0}'.format(ex, sys.exc_info()[-1].tb_lineno))
874 919

  
875 920
    '''
876 921
        @brief start thread
877 922
    '''
878 923
    def startThread(self):
879
        self.ui.buttonBox.setDisabled(True)
924
        self.dlg.ui.buttonBox.setDisabled(True)
880 925

  
881 926
        # 1 - create Worker and Thread inside the Form
882 927
        self.obj = Worker()  # no parent!
883 928
        self.obj.path = self.path
884
        self.obj.listWidget = self.ui.listWidget
929
        self.obj.listWidget = self.dlg.ui.listWidget
885 930
        self.thread = QThread()  # no parent!
886 931

  
887 932
        # 2 - Connect Worker`s Signals to Form method slots to post data.
......
906 951
        @brief set buttonbox's enabled flag
907 952
    '''
908 953
    def dlgExit(self):
909
        self.ui.buttonBox.setEnabled(True)
910
        
954
        self.xmlPath = self.obj.xmlPath
955
        self.dlg.ui.buttonBox.setEnabled(True)
911 956

  
912 957
if __name__ == '__main__':
913 958
    import DTI_PID_UI

내보내기 Unified diff

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