Beispiel #1
0
def draw_connections(root, preview):
    sts: DisplaySettings = DisplaySettings()

    draw = ImageDraw.Draw(preview)

    for c in root.info_bar.listbox_connections.get(0, last=END):
        parts = tuple(c.split(','))
        code1, code2 = parts

        ls = []
        for s in root.info_bar.listbox_landmarks.get(0, last=END):
            parts = tuple(s.split(','))
            _, code, r, _, x, y = parts
            r, x, y = tuple(map(int, (r, x, y)))
            if code in [code1, code2]:
                ls.append((r, x, y))

        if len(ls) != 2:
            print(
                f'WARNING: failed with connection {c}, found {len(ls)} landmarks instead of 2'
            )
        else:
            draw_connection_line(draw, ls, sts)
            if root.info_bar.draw_distances.get():
                draw_distance_text(draw, ls, root, sts)
            if root.info_bar.draw_angles.get():
                draw_connection_angle(draw, ls, sts)
                draw_connection_angle(draw, ls[::-1], sts)
Beispiel #2
0
def draw_slides(root, preview):
    sts: DisplaySettings = DisplaySettings()
    draw = ImageDraw.Draw(preview)

    sh = root.info_bar.slide_height.get()
    sw = int(sh / 1.5)
    centers = root.info_bar.slide_centers

    for center_xy in centers:
        draw.rectangle((center_xy[0] - sw // 2, center_xy[1] - sh // 2,
                        center_xy[0] + sw // 2, center_xy[1] + sh // 2),
                       fill=None,
                       outline=sts.slidesColor)
Beispiel #3
0
def draw_landmarks(root, preview):
    sts: DisplaySettings = DisplaySettings()

    draw = ImageDraw.Draw(preview)

    sz = sts.landmarkFontSize
    font = ImageFont.truetype(sts.font_path, size=sz)
    lw = sts.connectionWidth

    for s in root.info_bar.listbox_landmarks.get(0, last=END):
        parts = tuple(s.split(','))
        _, code, r, color, x, y = parts
        r, x, y = tuple(map(int, (r, x, y)))

        for d in range(int(lw)):
            r1 = r + d
            draw.ellipse((x - r1, y - r1, x + r1, y + r1), outline=color)
            r1 += 0.5
            draw.ellipse((x - r1, y - r1, x + r1, y + r1), outline=color)

        tw, th = draw.textsize(code, font=font)
        draw.text((x - tw // 2, y - th // 2), code, font=font)
    def export_slides(self, _=None):
        self.status_bar.set_status('Exporting ...')
        preview = PIL_Image.fromarray(self.img)

        if self.info_bar.draw_landmarks.get():
            draw_landmarks(self, preview)

        if self.info_bar.draw_connections.get():
            draw_connections(self, preview)

        sts = DisplaySettings()
        us = sts.export_upsize
        order = sts.export_interpolation_order

        out_dir = os.path.splitext(self.file_path)[0] + '_slides'
        os.makedirs(out_dir, exist_ok=True)
        img = np.array(preview)
        for i, xy in enumerate(self.info_bar.slide_centers):
            sh = self.info_bar.slide_height.get()
            sw = int(sh / 1.5)
            left = max(1, min(xy[0] - sw // 2, self.img.shape[1] - sw - 1))
            top = max(1, min(xy[1] - sh // 2, self.img.shape[0] - sh - 1))

            slide = img[top:top + sh, left:left + sw]
            slide = resize(slide, (slide.shape[0] * us, slide.shape[1] * us), order=order)
            slide = (slide * 255).astype(np.uint8)
            slide_path = os.path.join(out_dir, 'slide_%02i.jpg' % i)
            io.imsave(slide_path, slide)

        draw_slides(self, preview)
        preview = np.array(preview)
        preview = resize(preview, (preview.shape[0] * us, preview.shape[1] * us), order=order)
        preview = (preview * 255).astype(np.uint8)
        preview_path = os.path.join(out_dir, 'preview.jpg')
        io.imsave(preview_path, preview)

        msg = f'The slides have been exported to "{out_dir}"'
        messagebox.showinfo('Export finished', msg)
Beispiel #5
0
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):

        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1200, 640)
        # self.showMaximized()

        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        MainWindow.setCentralWidget(self.centralwidget)

        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 640, 25))
        self.menubar.setObjectName("menubar")

        MainWindow.setMenuBar(self.menubar)

        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.menuFile = QtWidgets.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        MainWindow.setMenuBar(self.menubar)

        self.menuCapture = QtWidgets.QMenu(self.menubar)
        self.menuCapture.setObjectName("menuCapture")
        MainWindow.setMenuBar(self.menubar)

        self.menuSettings = QtWidgets.QMenu(self.menubar)
        self.menuSettings.setObjectName("menuSettings")
        MainWindow.setMenuBar(self.menubar)

        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.viewStatAct = QAction('Emg Emulation', self, checkable=True)
        self.viewStatAct.setStatusTip('Emg Emulation')
        self.viewStatAct.setChecked(self.checkableStatus())
        self.viewStatAct.triggered.connect(self.toggleMenu)

        self.actionLoadcapture = QtWidgets.QAction(MainWindow)
        self.actionLoadcapture.setObjectName("actionLoadcapture")
        self.actionSavecapture = QtWidgets.QAction(MainWindow)
        self.actionSavecapture.setObjectName("actionSavecapture")
        self.actionLoademgsignal = QtWidgets.QAction(MainWindow)
        self.actionLoademgsignal.setObjectName("actionLoademgsignal")

        self.actionStartCapture = QtWidgets.QAction(MainWindow)
        self.actionStartCapture.setObjectName("actionStartCapture")
        self.actionStopCapture = QtWidgets.QAction(MainWindow)
        self.actionStopCapture.setObjectName("actionStopCapture")
        self.actionShowCapture = QtWidgets.QAction(MainWindow)
        self.actionShowCapture.setObjectName("actionShowCapture")

        self.actionLoadSettings = QtWidgets.QAction(MainWindow)
        self.actionLoadSettings.setObjectName("actionLoadSettings")
        self.actionSaveSettings = QtWidgets.QAction(MainWindow)
        self.actionSaveSettings.setObjectName("actionSaveSettings")

        self.actionEmgCaptureSettings = QtWidgets.QAction(MainWindow)
        self.actionEmgCaptureSettings.setObjectName("actionEmgCaptureSettings")
        self.actionEmgDisplaySettings = QtWidgets.QAction(MainWindow)
        self.actionEmgDisplaySettings.setObjectName("actionEmgDisplaySettings")
        self.actionGestureCaptureSettings = QtWidgets.QAction(MainWindow)
        self.actionGestureCaptureSettings.setObjectName(
            "GestureCaptureSettings")

        self.menuFile.addAction(self.actionLoadcapture)
        self.menuFile.addAction(self.actionSavecapture)
        self.menuFile.addAction(self.actionLoademgsignal)

        self.menuCapture.addAction(self.actionStartCapture)
        self.menuCapture.addAction(self.actionStopCapture)
        self.menuCapture.addAction(self.actionShowCapture)

        self.menuSettings.addAction(self.actionLoadSettings)
        self.menuSettings.addAction(self.actionSaveSettings)
        self.menuSettings.addSeparator()
        self.menuSettings.addAction(self.actionEmgCaptureSettings)
        self.menuSettings.addAction(self.actionEmgDisplaySettings)
        self.menuSettings.addAction(self.viewStatAct)
        self.menuSettings.addAction(self.actionGestureCaptureSettings)

        self.menubar.addAction(self.menuFile.menuAction())
        MainWindow.setCentralWidget(self.centralwidget)

        self.menubar.addAction(self.menuCapture.menuAction())
        MainWindow.setCentralWidget(self.centralwidget)

        self.menubar.addAction(self.menuSettings.menuAction())
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)

        self.actionLoadcapture.triggered.connect(self.loadCapture)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.actionSavecapture.triggered.connect(self.saveCapture)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.actionLoademgsignal.triggered.connect(self.loadEmgsignal)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.actionStartCapture.triggered.connect(self.startCapture)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.actionStopCapture.triggered.connect(self.stopCapture)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.actionShowCapture.triggered.connect(self.showCapture)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.actionLoadSettings.triggered.connect(self.loadSettings)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.actionSaveSettings.triggered.connect(self.saveSettings)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.actionEmgCaptureSettings.triggered.connect(
            self.emgCaptureSettings)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.actionEmgDisplaySettings.triggered.connect(
            self.emgDisplaySettings)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.actionGestureCaptureSettings.triggered.connect(
            self.gestureCaptureSettings)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.defaultCapPadrao = '../routine/default.txt'
        # self.defaultCapPadrao = routine

        f = open(self.defaultCapPadrao, 'r')
        self.linesCap = f.read().splitlines()

        self.emgCapPadrao = TEST_LOG
        f = open(self.emgCapPadrao, 'r')
        self.linesEmg = f.read().splitlines()

    def checkableStatus(self):
        settings = open('settingsEE', 'r')
        setCurrent = settings.read().splitlines()
        if setCurrent[0] == "True":
            return True
        else:
            return False

    def toggleMenu(self, state):

        self.defaultEmgPadrao = TEST_LOG
        if state:
            # fileNames = QFileDialog.getOpenFileNames(None, 'Open file', '.', 'Log (*.log)')[0]
            # for endfile in fileNames: self.defaultCapPadrao = endfile
            settings = open('settingsEE', 'w')
            settings.writelines("True")
            ##MENSAGEM SE ARQUIOVO N CARREGADO
            self.statusbar.show()
        else:
            settings = open('settingsEE', 'w')
            settings.writelines("False")
            self.statusbar.hide()

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate

        self.menuFile.setTitle(_translate("MainWindow", "File", None))
        self.actionLoadcapture.setText(
            _translate("MainWindow", "Load capture", None))
        self.actionSavecapture.setText(
            _translate("MainWindow", "Save capture", None))
        self.actionLoademgsignal.setText(
            _translate("MainWindow", "Load EMG signal", None))

        self.menuCapture.setTitle(_translate("MainWindow", "Capture", None))
        self.actionStartCapture.setText(
            _translate("MainWindow", "Start Capture", None))
        self.actionStopCapture.setText(
            _translate("MainWindow", "Stop Capture", None))
        self.actionShowCapture.setText(
            _translate("MainWindow", "Show Capture", None))

        self.menuSettings.setTitle(_translate("MainWindow", "Settings", None))
        self.actionLoadSettings.setText(
            _translate("MainWindow", "Load settings", None))
        self.actionSaveSettings.setText(
            _translate("MainWindow", "Save settings", None))

        self.actionEmgCaptureSettings.setText(
            _translate("MainWindow", "EMG capture settings", None))
        self.actionEmgDisplaySettings.setText(
            _translate("MainWindow", "EMG display settings", None))
        self.actionGestureCaptureSettings.setText(
            _translate("MainWindow", "Gesture capture settings", None))

    def loadCapture(self):
        fileNames = QFileDialog.getOpenFileNames(None, 'Open file', '.',
                                                 'Log (*.log)')[0]
        for endfile in fileNames:
            self.defaultCapPadrao = endfile
        f = open(str(self.defaultCapPadrao), 'r')
        self.linesCap = f.read().splitlines()
        f.close()

    def saveCapture(self):
        fileName = QtGui.QFileDialog.getSaveFileName(self, 'Save File', '.',
                                                     'CSV (*.csv)')[0]
        self.tiva.textfile.save(str(fileName))
        # file = open(self.fileName, 'w')
        # text = self.textEdit.toPlainText()
        # file.write(text)
        # file.close()

    def loadEmgsignal(self):
        fileNames = QFileDialog.getOpenFileNames(None, 'Open file', '.',
                                                 'Log (*.log)')[0]
        for endfile in fileNames:
            self.emgCapPadrao = endfile
        f = open(str(self.emgCapPadrao), 'r')
        self.linesEmg = f.read().splitlines()
        f.close()

    def startCapture(self):

        self.tiva = Main(self)

        settingsGCS = open('settingsGCS', 'r')
        setCurrent = settingsGCS.read().splitlines()
        self.device = setCurrent[0]
        self.routine = setCurrent[1]
        self.hand = setCurrent[2]

        try:
            self.defaultCapPadrao = self.routine
            f = open(self.defaultCapPadrao, 'r')
            self.linesCap = f.read().splitlines()
        except:
            print("ERRO")

        ##########################################################

        settingsEE = open('settingsEE', 'r')
        setCurrent = settingsEE.read().splitlines()
        enable = setCurrent[0]

        # self.tiva = Main(self)
        # self.tiva.showMainWindow()

        self.serialPorts = SerialPorts()

        if setCurrent[0] == 'True':

            #self.tiva.showMainWindow()
            try:
                self.tiva.loadData(setCurrent[1])
                tk = tTiva(self.tiva, 'show')
                tk.start()
                self.startDevice()
            except:
                self.tiva.loadData(TEST_LOG)
                tk = tTiva(self.tiva, 'show')
                tk.start()
                self.startDevice()
        else:
            if self.serialPorts.list():  # CHECA A PORTA SERIAL

                #self.tiva.showMainWindow()
                tk = tTiva(self.tiva, 'start')
                tk.start()
                self.startDevice()
            else:
                self.startDevice()

    def stopCapture(self):
        print "StopCapture"

    def saveSettings(self):
        print "SaveSettings"

    def loadSettings(self):
        print "LoadSettings"

    def emgCaptureSettings(self):
        self.win_capture = CaptureSettings(self)
        self.stopCapture()
        self.win_capture.show()

    def emgDisplaySettings(self):
        self.win_display = DisplaySettings(self)
        self.stopCapture()
        self.win_display.show()

    def gestureCaptureSettings(self):
        self.win_GCS = Class_GCS(self)
        self.stopCapture()
        self.win_GCS.show()

    def showCapture(self):
        global sequence
        for line in self.linesCap:
            if len(line) != 0 and line[0] != '#':
                atributo = line.split(';')
                d = 0
                k = 5
                while d <= 4:
                    self.deviceDat[d] = int(atributo[d])
                while k <= 9:
                    keyDat[k] = int(atributo[k])

                self.deviceSequence.append(self.deviceDat)
                self.keySequence.append(keyDat)

    def readCapture(self):
        global sequence
        for line in self.linesCap:
            if len(line) != 0 and line[0] != '#':
                atributo = line.split(';')
                imagem = str(atributo[0])
                temp = float(atributo[1])

                l = Infor()
                Infor.set_img(l, imagem)

                # converter.pattern("../images/"+imagem+".png","../images/"+imagem+".png")
                # converter.gray_scale("../images/"+imagem+".png","../images/"+imagem+"EC.png")

                Infor.set_temp(l, temp)
                sequence.append(l)

    def startDevice(self):
        if (self.device != 'None'):
            self.readCapture()
            global sequence
            modules.start(self, self.tiva, sequence, self.linesEmg,
                          self.device)
        else:
            self.tiva = Main(self)
            self.tiva.showMainWindow()
Beispiel #6
0
 def emgDisplaySettings(self):
     self.win_display = DisplaySettings(self)
     self.stopCapture()
     self.win_display.show()
Beispiel #7
0
    def __init__(self):
        self.cfg = Configuration()
        self.sts = DisplaySettings()

        self.generate_all()