예제 #1
0
    def __init__(self):
        super(mainWindow, self).__init__()
        self.ui = Ui_mainWindow()
        self.ui.setupUi(self)

        #sub-folder inside is OK
        self.sound_dir = '/home/duc/Desktop/ML_WorkSpace/tools/LabelSpeech/test_data/VIVOSDEV01'
        self.list_file = tuple(os.walk(self.sound_dir))[0][2]

        #auto create labels.txt by the path
        self.label_path = 'test_data/labels.txt'
        with codecs.open(self.label_path, 'r+', encoding='utf8') as f:
            self.anno_list = [line.replace('\n', '').split('\t') for line in f]
            if not len(self.anno_list):
                self.anno_list = [[f, ''] for f in self.list_file]

        self.index = 0
        self.updateScreen()

        self.ui.saveButton.clicked.connect(self.saveFn)
        self.ui.nextButton.setShortcut('s')

        self.ui.nextButton.clicked.connect(self.nextFn)
        self.ui.nextButton.setShortcut('d')

        self.ui.backButton.clicked.connect(self.backFn)
        self.ui.backButton.setShortcut('a')

        self.ui.delButton.clicked.connect(self.delFn)
        self.ui.saveButton.setShortcut('del')

        self.ui.gotoButton.clicked.connect(self.gotoFn)
        self.ui.playButton.clicked.connect(self.playSound)
예제 #2
0
 def __init__(self):
     super().__init__()
     self.ui = Ui_mainWindow()
     self.styleFile = open("styles.qss").read()
     self.setStyleSheet(self.styleFile)
     self.ui.setupUi(self)
     self.socketThread = None
     #self.show()
     self.ui.buttonConnect.clicked.connect(self.openMonitor)
예제 #3
0
파일: main.py 프로젝트: ttducqt/LabelOCR
    def __init__(self):
        super(mainWindow, self).__init__()
        self.ui = Ui_mainWindow()
        self.ui.setupUi(self)
        
        self.dir_path = '/home/duc/Desktop/ML_WorkSpace/ocr/train'
        with open(os.path.join(self.dir_path, 'labels.txt'), 'r') as f:
            self.anno_list = [line.replace('\n','').split('\t') for line in f]

        self.index = 0
        self.updateFrame()
        
        self.ui.nextButton.clicked.connect(self.nextFn)
        self.ui.saveButton.clicked.connect(self.saveFn)
        self.ui.backButton.clicked.connect(self.backFn)
        self.ui.delButton.clicked.connect(self.delFn)
        self.ui.gotoButton.clicked.connect(self.gotoFn)

        shortcut = QShortcut(QKeySequence('Shift+Ctrl+Z'), self.ui.nextButton)
예제 #4
0
파일: main.py 프로젝트: ttducqt/LabelOCR
class mainWindow(QWidget):
    def __init__(self):
        super(mainWindow, self).__init__()
        self.ui = Ui_mainWindow()
        self.ui.setupUi(self)
        
        self.dir_path = '/home/duc/Desktop/ML_WorkSpace/ocr/train'
        with open(os.path.join(self.dir_path, 'labels.txt'), 'r') as f:
            self.anno_list = [line.replace('\n','').split('\t') for line in f]

        self.index = 0
        self.updateFrame()
        
        self.ui.nextButton.clicked.connect(self.nextFn)
        self.ui.saveButton.clicked.connect(self.saveFn)
        self.ui.backButton.clicked.connect(self.backFn)
        self.ui.delButton.clicked.connect(self.delFn)
        self.ui.gotoButton.clicked.connect(self.gotoFn)

        shortcut = QShortcut(QKeySequence('Shift+Ctrl+Z'), self.ui.nextButton)

    def updateFrame(self):
        if abs(self.index) >= len(self.anno_list):
            self.index = 0

        self.ui.frame.setPixmap(
            PySide2.QtGui.QPixmap(os.path.join(self.dir_path, 
                                self.anno_list[self.index][0]))
        )
        self.ui.labelBox.setText(self.anno_list[self.index][1])
        self.ui.idxBox.setText(str(self.index))
        # print(self.anno_list[self.index])

    def checkEdit(self):
        if self.ui.labelBox.text() != self.anno_list[self.index][1]:
            self.anno_list[self.index][1] = self.ui.labelBox.text()

    def nextFn(self):
        self.checkEdit()
        self.index += 1
        self.updateFrame()
    
    def backFn(self):
        self.checkEdit()
        self.index -= 1
        self.updateFrame()
    
    def saveFn(self):
        self.ui.saveButton.setText('Saving.........Plz wait')
        with open(os.path.join(self.dir_path, 'labels.txt'), 'w') as f:
            for line in self.anno_list:
                f.write('\t'.join(line)+'\n')
        
        self.ui.saveButton.setText('Saving successfull, click agian to save')

    def delFn(self):
        os.remove(os.path.join(self.dir_path, self.anno_list[self.index][0]))
        del(self.anno_list[self.index])
        self.updateFrame()
    
    def gotoFn(self):
        self.index = int(self.ui.idxBox.text())
        self.updateFrame()
예제 #5
0
class AppWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_mainWindow()
        self.styleFile = open("styles.qss").read()
        self.setStyleSheet(self.styleFile)
        self.ui.setupUi(self)
        self.socketThread = None
        #self.show()
        self.ui.buttonConnect.clicked.connect(self.openMonitor)

    def openMonitor(self):
        print("opening")
        self.connectToSerialDevices()
        #self.socketThread = None
        self.monitor_window = QWidget()
        self.monitor_window.setStyleSheet(self.styleFile)
        self.monitor = Ui_Monitor()
        self.monitor.setupUi(self.monitor_window)
        self.monitor_window.show()
        self.console = ConsoleWidget()
        self.monitor.console.addWidget(self.console)
        self.openSockets()

    def connectToSerialDevices(self):
        print("connecting to serial devices")
        bd_port = self.ui.bd_port.text()
        ub_port = self.ui.ub_port.text()
        subprocess.Popen("python serial_manager.py {} {}".format(
            bd_port, ub_port),
                         shell=True)
        #subprocess.Popen("{}/serial_manager.py {} {}".format(os.getcwd(), bd_port, ub_port), shell=True)
        #self.mySerialManager = SerialManager(bd_port, ub_port, config.SERIAL_PUBLISH, config.SERIAL_SUBSCRIBE)
        #self.mySerialManager.manage()

    def openSockets(self):
        print("opening sockets")
        try:
            context = zmq.Context()
            self.telemSocket = context.socket(zmq.SUB)
            self.telemSocket.connect(config.GUI_SUBSCRIBE)
            self.telemSocket.setsockopt_string(zmq.SUBSCRIBE, '')

            self.commandSocket = context.socket(zmq.PUB)
            self.commandSocket.bind(config.GUI_PUBLISH)
            print("sockets open")
        except (zmq.ZMQError, zmq.ZMQBindError) as err:
            print("Error: {}".format(err))
            return

        if (self.socketThread is not None):
            self.socketThread.terminate()
            self.socketThread.socket.close()

        self.socketThread = SocketMonitor(self.telemSocket)
        self.socketThread.signal.connect(self.gotSig)
        self.socketThread.start()

    def gotSig(self, msg):
        #print("\nReceived New Packet...")
        for key in msg:
            #print(key)
            #print(msg[key][0])
            if self.monitor.nff_groupbox.findChild(QLabel, key):
                item = self.monitor.nff_groupbox.findChild(QLabel, key)
            elif self.monitor.bd_groupbox.findChild(QLabel, key):
                item = self.monitor.bd_groupbox.findChild(QLabel, key)
            else:
                continue
            item.setText(str(msg[key][0]))
            if msg[key][1] == 1:
                item.setStyleSheet('color: #f93943')  #red
            else:
                item.setStyleSheet('color: #063D23')  #green
예제 #6
0
class AppWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_mainWindow()
        self.styleFile = open("styles.qss").read()
        self.setStyleSheet(self.styleFile)
        self.ui.setupUi(self)
        self.socketThread = None
        #self.show()
        self.listSerialDevices()
        self.ui.buttonConnect.clicked.connect(self.openMonitor)

    def openMonitor(self):
        print("opening monitor")
        self.connectToSerialDevices()
        #self.socketThread = None
        self.monitor_window = QWidget()
        self.monitor_window.setStyleSheet(self.styleFile)
        self.monitor = Ui_Monitor()
        self.monitor.setupUi(self.monitor_window)
        self.close()
        self.monitor_window.show()
        self.console = ConsoleWidget()
        self.monitor.console.addWidget(self.console)
        self.runServer()
        self.openSockets()
        self.initNFFSim()

    def listSerialDevices(self):
        comlist = serial.tools.list_ports.comports()
        for x in comlist:
            self.ui.sc_port.addItem(x.device)
            self.ui.ub_port.addItem(x.device)

    def connectToSerialDevices(self):
        sc_port = self.ui.sc_port.itemText(self.ui.sc_port.currentIndex())
        ub_port = self.ui.ub_port.itemText(self.ui.ub_port.currentIndex())
        self.serialManager = SerialManager(sc_port, ub_port,
                                           config.SERIAL_PUBLISH,
                                           config.SERIAL_SUBSCRIBE,
                                           config.SERIAL_NFF_SUBSCRIBE)
        self.serialManager.start()

    def runServer(self):
        self.server = Server(self.monitor, config.SERVER_SUBSCRIBE,
                             config.SERVER_PUBLISH)
        self.server.start()

    def openSockets(self):
        print("opening gui sockets")
        try:
            context = zmq.Context()
            self.telemSocket = context.socket(zmq.SUB)
            self.telemSocket.connect(config.GUI_SUBSCRIBE)
            self.telemSocket.setsockopt_string(zmq.SUBSCRIBE, '')

            self.commandSocket = context.socket(zmq.PUB)
            self.commandSocket.bind(config.GUI_PUBLISH)
            # print("sockets open")
        except (zmq.ZMQError, zmq.ZMQBindError) as err:
            print("Error: {}".format(err))
            return

        if (self.socketThread is not None):
            self.socketThread.terminate()
            self.socketThread.socket.close()

        self.socketThread = SocketMonitor(self.telemSocket)
        self.socketThread.signal.connect(self.gotSig)
        self.socketThread.start()

    def initNFFSim(self):
        self.nffSim = NFFSim(self.monitor, config.NFF_PUBLISH)
        self.monitor.run_sim.clicked.connect(self.nffSim.start)
        self.monitor.pause_sim.clicked.connect(self.nffSim.pause)
        self.monitor.abort_sim.clicked.connect(self.nffSim.stop)

    def gotSig(self, msg):
        #print("\nReceived New Packet...")
        # print(msg)
        for key in msg:
            # print(key)
            # print(msg[key][0])
            if self.monitor.nff_groupbox.findChild(QLabel, key):
                item = self.monitor.nff_groupbox.findChild(QLabel, key)
            elif self.monitor.sc_groupbox.findChild(QLabel, key):
                item = self.monitor.sc_groupbox.findChild(QLabel, key)
            elif self.monitor.ub_groupbox.findChild(QLabel, key):
                item = self.monitor.ub_groupbox.findChild(QLabel, key)
            else:
                continue
            item.setText(str(msg[key][0]))
            if msg[key][1] == 1:
                item.setStyleSheet('color: #f93943')  #red
            else:
                item.setStyleSheet('color: #063D23')  #green
예제 #7
0
class mainWindow(QWidget):
    def __init__(self):
        super(mainWindow, self).__init__()
        self.ui = Ui_mainWindow()
        self.ui.setupUi(self)

        #sub-folder inside is OK
        self.sound_dir = '/home/duc/Desktop/ML_WorkSpace/tools/LabelSpeech/test_data/VIVOSDEV01'
        self.list_file = tuple(os.walk(self.sound_dir))[0][2]

        #auto create labels.txt by the path
        self.label_path = 'test_data/labels.txt'
        with codecs.open(self.label_path, 'r+', encoding='utf8') as f:
            self.anno_list = [line.replace('\n', '').split('\t') for line in f]
            if not len(self.anno_list):
                self.anno_list = [[f, ''] for f in self.list_file]

        self.index = 0
        self.updateScreen()

        self.ui.saveButton.clicked.connect(self.saveFn)
        self.ui.nextButton.setShortcut('s')

        self.ui.nextButton.clicked.connect(self.nextFn)
        self.ui.nextButton.setShortcut('d')

        self.ui.backButton.clicked.connect(self.backFn)
        self.ui.backButton.setShortcut('a')

        self.ui.delButton.clicked.connect(self.delFn)
        self.ui.saveButton.setShortcut('del')

        self.ui.gotoButton.clicked.connect(self.gotoFn)
        self.ui.playButton.clicked.connect(self.playSound)

    def playSound(self):
        playsound(os.path.join(self.sound_dir, self.anno_list[self.index][0]))

    def updateScreen(self):
        if abs(self.index) >= len(self.anno_list):
            self.index = 0

        self.ui.fileNameBox.setText(
            str(os.path.join(self.sound_dir, self.anno_list[self.index][0])))

        self.ui.labelBox.setText(self.anno_list[self.index][1])
        self.ui.idxBox.setText(str(self.index))

    def checkEdit(self):
        if self.ui.labelBox.toPlainText() != self.anno_list[self.index][1]:
            self.anno_list[self.index][1] = self.ui.labelBox.toPlainText()

    def nextFn(self):
        self.checkEdit()
        self.index += 1
        self.updateScreen()

    def backFn(self):
        self.checkEdit()
        self.index -= 1
        self.updateScreen()

    def saveFn(self):
        self.checkEdit()
        self.ui.saveButton.setText('Saving')
        with codecs.open(os.path.join(self.label_path), 'w+',
                         encoding='utf8') as f:
            for line in self.anno_list:
                f.write('\t'.join(line) + '\n')

        self.ui.saveButton.setText('Save')

    def delFn(self):
        os.remove(os.path.join(self.sound_dir, self.anno_list[self.index][0]))
        del (self.anno_list[self.index])
        self.updateScreen()

    def gotoFn(self):
        self.index = int(self.ui.idxBox.text())
        self.updateScreen()