Example #1
0
    def __init__(self):
        super(MyDesignerShow, self).__init__()
        self.timer_camera = QtCore.QTimer()  # 本地摄像头定时器
        self.timer_udp_video = QtCore.QTimer()  # UDP获取视频定时器
        self.cap = cv2.VideoCapture()  # 获得摄像头对象
        self.CAM_NUM = 0  # 获取摄像头编号
        self.time = time  # 获取时间对象
        self.PREDICTOR_PATH = './face_lib/shape_predictor_68_face_landmarks.dat'  # 关键点提取模型路径
        self.my_align = align_dlib.AlignDlib(self.PREDICTOR_PATH)  # 获取人脸对齐对象
        self.pix = QtGui.QPixmap()  # 获取QPixmap对象
        self.pic_show = None
        self.face_photo = None  # 人脸图片
        self.face_recog = face_recg.Recognize()  # 获取人脸识别对象

        self.setupUi(self)  # 加载窗体
        self.btn_close.clicked.connect(self.close)  # 关闭程序
        self.btn_local_camera.clicked.connect(self.get_local_camera)  # 打开本地相机
        self.btn_web_camera.clicked.connect(self.get_udp_video)  # 打开UDP视频数据
        self.btn_get_face.clicked.connect(self.get_face)  # 得到人脸图像
        self.btn_debug.clicked.connect(self.debug)  # 报错
        self.btn_new_face.clicked.connect(self.new_face)  # 新建人脸数据
        self.btn_face_recognize.clicked.connect(self.face_recognize)  # 人脸识别

        self.timer_camera.timeout.connect(
            self.show_local_camera)  # 计时结束调用show_camera()方法
        self.timer_udp_video.timeout.connect(
            self.show_udp_video)  # 计时结束调用show_udp_video()方法
Example #2
0
    def photo_read(self, path, num):
        # 使用dlib自带的frontal_face_detector作为我们的特征提取器
        detector = align_dlib.AlignDlib(self.PREDICTOR_PATH)
        path = self.input_dir + '/' + path
        print(path + " 正在处理...")
        name_file = str(num) + '_' + path.split('/')[-1]
        name_file = self.output_dir + '/' + name_file
        # 如果不存在目录 就创造目录
        if not os.path.exists(name_file):
            os.makedirs(name_file)
        index = 1

        for filename in os.listdir(path):
            if filename.endswith('.jpg'):
                img_path = path + '/' + filename
                print(img_path)
                # 从文件读取图片
                img_bgr = cv2.imread(img_path)  # 从文件读取bgr图片
                img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)  # 转为RGB图片
                face_align = detector.align(size, img_rgb)
                if face_align is None:
                    pass
                else:
                    face_align = cv2.cvtColor(face_align,
                                              cv2.COLOR_RGB2BGR)  # 转为BGR图片
                    # 保存图片
                    cv2.imwrite(name_file + '/' + str(index) + '.jpg',
                                face_align)
                    index += 1
Example #3
0
 def get_pair_image(self, pair):
     detector = align_dlib.AlignDlib(self.PREDICTOR_PATH)
     x, y = pair
     path_name_x = self.path + self.path_array[x - 1]
     path_name_y = self.path + self.path_array[y - 1]
     x_img = self.get_one_image(x, detector)
     y_img = self.get_one_image(y, detector)
     return x_img, y_img