예제 #1
0
 def findFace(self, detect, img):
     if detect == 'mtcnn':
         return mtcnn_findFace(img)
     elif detect == 'cv':
         return cv_findFace(img)
     elif detect == 'dlib_cnn':
         return dlib_findFace(img, mode="cnn", image_size=160)
     elif detect == 'dlib':
         return dlib_findFace(img, mode="normal", image_size=160)
     else:
         return [], []
            shape = sp(img, convert_to_rect(rect))

            # 把特征点画出来,检验程序是否正确
            for pt in shape.parts():
                pt_pos = (pt.x, pt.y)
                cv2.circle(show_img, pt_pos, 2, (0, 255, 0), 1)

            # 将原图像和特征点传入人脸识别模型,得到人脸特征
            face_descriptor = facerec.compute_face_descriptor(img, shape)
            feature.append(face_descriptor)

        feature = np.array(feature)
        # 结果保存到本地文件
        misc.imsave("./dlib_feature_extraction_{}.png".format(mode), show_img)

    # 返回人脸特征
    return feature


if __name__ == '__main__':
    # 先通过MTCNN取得人脸框位置
    image_path = "./frame_tmp.jpg"
    img = misc.imread(os.path.expanduser(image_path), mode='RGB')
    images, rects = mtcnn_findFace(img)

    img = misc.imread(os.path.expanduser(image_path), mode='RGB')
    feature_extraction(img, rects, "68")

    img = misc.imread(os.path.expanduser(image_path), mode='RGB')
    feature_extraction(img, rects, "5")