Ejemplo n.º 1
0
class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow,self).__init__()
        self.ui = loadUi(os.path.join(THIS_DIR, 'mainwindow.ui'), self)
        self.thread = QThread()
        try:
            self.camera = CameraDevice()
        except ValueError:
            self.ui.video.setText("Device not found!\n\nIs FFMPEG available?")
        else:
            self.camera.frame_ready.connect(self.update_video_label)
            self.ui.video.setMinimumSize(*self.camera.size)
            self.camera.moveToThread(self.thread)

    @pyqtSlot()
    def start_recog(self):
        self.camera.set_recog(self.recognizer)

    @pyqtSlot()
    def stop_recog(self):
        self.camera.remove_recog()

    @pyqtSlot()
    def train_start(self):
        self.recognizer = FaceRec()
        self.recognizer.learn()

    @pyqtSlot()
    def make_data(self):
        name = str(self.ui.nameText.toPlainText())
        if len(name) == 0:
            self.ui.nameText.setText("enter name!")
            return;
        print("train btn pushed.")
        train = FaceTrain(name)
        self.camera.set_train(train)

    @pyqtSlot(QImage)
    def update_video_label(self, image):
        pixmap = QPixmap.fromImage(image)
        self.ui.video.setPixmap(pixmap)
        self.ui.video.update()
Ejemplo n.º 2
0
class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = loadUi(os.path.join(THIS_DIR, 'mainwindow.ui'), self)
        self.thread = QThread()
        try:
            self.camera = CameraDevice()
        except ValueError:
            self.ui.video.setText("Device not found!\n\nIs FFMPEG available?")
        else:
            self.camera.frame_ready.connect(self.update_video_label)
            self.ui.video.setMinimumSize(640 * 2, 480)
            self.camera.moveToThread(self.thread)
        self.ui.t_max.setValue(0)
        self.ui.t_min.setValue(255)
        self.ui.s_max.setValue(200)
        self.ui.s_min.setValue(3)
        self.update_values()

    @pyqtSlot()
    def start_recog(self):
        if self.recognizer is not None:
            self.camera.set_recog(self.recognizer)
        else:
            print("plz do load recogi")

    @pyqtSlot()
    def stop_recog(self):
        self.camera.remove_recog()

    @pyqtSlot()
    def train_start(self):
        self.recognizer = DigitRecognizer()
        self.recognizer.learn()

    @pyqtSlot()
    def make_data(self):
        print("Not supported.")

    @pyqtSlot(int)
    def t_max_changed(self, val):
        if val < self.ui.t_min.value():
            self.ui.t_min.setValue(val)
        self.update_values()

    @pyqtSlot(int)
    def t_min_changed(self, val):
        if val > self.ui.t_max.value():
            self.ui.t_max.setValue(val)
        self.update_values()

    @pyqtSlot(int)
    def s_max_changed(self, val):
        if val < self.ui.s_min.value():
            self.ui.s_min.setValue(val)
        self.update_values()

    @pyqtSlot(int)
    def s_min_changed(self, val):
        if val > self.ui.s_max.value():
            self.ui.s_max.setValue(val)
        self.update_values()

    @pyqtSlot(QImage)
    def update_video_label(self, image):
        pixmap = QPixmap.fromImage(image)
        self.ui.video.setPixmap(pixmap)
        self.ui.video.update()

    def update_values(self):
        self.camera.set_values(self.ui.t_max.value(), self.ui.t_min.value(),
                               self.ui.s_max.value(), self.ui.s_min.value())