示例#1
0
    def run(self):
        state = ['s', '1', '5', '8']
        ind = random.randint(0, 11)
        self.order_value.emit(str(state[ind % 4]))
        if str(state[ind % 4]) == 's':
            speech.say("请保持沉默。")
        else:
            speech.say("请说" + str(state[ind % 4]))
        print('请说 ' + str(state[ind % 4]))
        while True:
            m = 0
            frames = []
            speech.say(3)
            speech.say(2)
            speech.say(1)
            while m < 3:
                ret, img = self.cap.read()
                cv2.waitKey(33)
                if ret:  # 如果摄像头读取图像成功
                    frame = np.array(img)
                    frames.append(frame)
                    # cv2.waitKey(60)
                    m += 1

            mouth_points = get_frames_mouth(self.detector, self.predictor, frames)
            print(np.shape(mouth_points))
            if np.shape(mouth_points) != (np.shape(mouth_points)[0], 2, 12):
                continue
            mouth_points_mean = np.mean(mouth_points, axis=0)
            mouth_points_mean_re = np.reshape(mouth_points_mean, newshape=[1, 24])

            pred = self.svmmodel.predict(mouth_points_mean_re)
            self.pre_value.emit(pred[0])
            print('我认为你说了 ' + pred[0])
            if pred == state[ind % 4]:
                true = True
            else:
                true = False
            time.sleep(2)
            self.order_value.emit('')
            self.pre_value.emit('')

            if true:
                print('正确!\n')
                speech.say("正确。")
                ind = random.randint(0, 11)
                self.order_value.emit(str(state[ind % 4]))
                if str(state[ind % 4]) == 's':
                    speech.say("请保持沉默。")
                else:
                    speech.say("请说" + str(state[ind % 4]))
                print('请说 ' + str(state[ind % 4]))
            else:
                speech.say("我认为你说错了,请继续说" + str(state[ind % 4]))
                print('错误!请继续说 ' + str(state[ind % 4]))
                self.order_value.emit(str(state[ind % 4]))
示例#2
0
    def run(self):
        cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
        FACE_PREDICTOR_PATH = r'D:\LipNum\shape_predictor_68_face_landmarks.dat'
        detector = dlib.get_frontal_face_detector()
        predictor = dlib.shape_predictor(FACE_PREDICTOR_PATH)
        modelpath = os.path.join(os.path.abspath('..'), 'model', 'svm_model.m')
        self.svmmodel = joblib.load(modelpath)

        true = True
        state = ['s', '1', '5', '8']
        ind = random.randint(0, 11)
        self.order_value.emit(str(state[ind % 4]))
        print('请说 ' + str(state[ind % 4]))
        while cap.isOpened():  # isOpened()  检测摄像头是否处于打开状态
            m = 0
            frames = []

            if true:
                print('正确!\n')
                ind = random.randint(0, 11)
                self.order_value.emit(str(state[ind % 4]))
                print('请说 ' + str(state[ind % 4]))
            else:
                print('错误!请继续说 ' + str(state[ind % 4]))
                self.order_value.emit(str(state[ind % 4]))

            # if k == 107:  # ASCLL(k)==127 keep
            time.sleep(1)
            while m < 10:
                ret, img = cap.read()  # 把摄像头获取的图像信息保存之img变量
                if ret:  # 如果摄像头读取图像成功
                    cv2.imwrite(r'image\image{}.jpg'.format(m), img)
                    frame = np.array(img)
                    frames.append(frame)
                    cv2.waitKey(60)
                    m += 1

            mouth_points = get_frames_mouth(detector, predictor, frames)
            mouth_points_mean = np.mean(mouth_points, axis=0)
            # print(mouth_points_mean.shape)
            mouth_points_mean_re = np.reshape(mouth_points_mean,
                                              newshape=[1, 24])
            # print(mouth_points_mean_re.shape)
            # mouth_points_mean_re.reshape(-1, 1)
            # print(mouth_points_mean_re.shape)

            pred = self.svmmodel.predict(mouth_points_mean_re)
            self.pre_value.emit(pred[0])
            print('我认为你说了 ' + pred[0])
            if pred == state[ind % 4]:
                true = True
            else:
                true = False
            time.sleep(2)
            self.order_value.emit('')
            self.pre_value.emit('')
示例#3
0
    def run(self):
        while self.cap.isOpened():  # isOpened()  检测摄像头是否处于打开状态
            m = 0
            frames = []
            while m < 2:
                ret, img = self.cap.read()  # 把摄像头获取的图像信息保存之img变量
                cv2.waitKey(33)
                if ret:  # 如果摄像头读取图像成功
                    frame = np.array(img)
                    frames.append(frame)
                    m += 1

            mouth_points = get_frames_mouth(self.detector, self.predictor, frames)
            print(np.shape(mouth_points))
            if np.shape(mouth_points) != (np.shape(mouth_points)[0], 2, 12):
                continue
            mouth_points_mean = np.mean(mouth_points, axis=0)
            mouth_points_mean_re = np.reshape(mouth_points_mean, newshape=[1, 24])

            pred = self.svmmodel.predict(mouth_points_mean_re)
            self.predict.emit(pred[0])
            print('我认为你现在说了 ' + pred[0])
示例#4
0
    ret, img = cap.read()  # 把摄像头获取的图像信息保存之img变量
    if ret:  # 如果摄像头读取图像成功
        print(np.shape(img))
        cv2.imshow('Image', img)

    while m < 10:
        ret, img = cap.read()  # 把摄像头获取的图像信息保存之img变量
        if ret:  # 如果摄像头读取图像成功
            cv2.imshow('Image', img)
            cv2.imwrite(r'image\image{}.jpg'.format(m), img)
            frame = np.array(img)
            frames.append(frame)
            k = cv2.waitKey(5)
            m += 1

    mouth_points = get_frames_mouth(detector, predictor, frames)
    if np.shape(mouth_points) != (np.shape(mouth_points)[0], 2, 12):
        continue
    mouth_points_mean = np.mean(mouth_points, axis=0)
    # print(mouth_points_mean.shape)
    mouth_points_mean_re = np.reshape(mouth_points_mean, newshape=[1, 24])
    # print(mouth_points_mean_re.shape)
    # mouth_points_mean_re.reshape(-1, 1)
    # print(mouth_points_mean_re.shape)

    pred = svmmodel.predict(mouth_points_mean_re)
    print('我认为你现在说了 ' + pred)

    # plt.figure(1)
    # for m in range(np.shape(X_re)[0]):
    #     if Y[m] == '1':