1 Star 0 Fork 0

sesepp/face-frontalization

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
demo.py 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
Douglas 提交于 2016-03-19 19:27 . Removing redundant code in demo.py
import frontalize
import facial_feature_detector as feature_detection
import camera_calibration as calib
import scipy.io as io
import cv2
import numpy as np
import os
import check_resources as check
import matplotlib.pyplot as plt
this_path = os.path.dirname(os.path.abspath(__file__))
def demo():
# check for dlib saved weights for face landmark detection
# if it fails, dowload and extract it manually from
# http://sourceforge.net/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2
check.check_dlib_landmark_weights()
# load detections performed by dlib library on 3D model and Reference Image
model3D = frontalize.ThreeD_Model(this_path + "/frontalization_models/model3Ddlib.mat", 'model_dlib')
# load query image
img = cv2.imread("test.jpg", 1)
plt.title('Query Image')
plt.imshow(img[:, :, ::-1])
# extract landmarks from the query image
# list containing a 2D array with points (x, y) for each face detected in the query image
lmarks = feature_detection.get_landmarks(img)
plt.figure()
plt.title('Landmarks Detected')
plt.imshow(img[:, :, ::-1])
plt.scatter(lmarks[0][:, 0], lmarks[0][:, 1])
# perform camera calibration according to the first face detected
proj_matrix, camera_matrix, rmat, tvec = calib.estimate_camera(model3D, lmarks[0])
# load mask to exclude eyes from symmetry
eyemask = np.asarray(io.loadmat('frontalization_models/eyemask.mat')['eyemask'])
# perform frontalization
frontal_raw, frontal_sym = frontalize.frontalize(img, proj_matrix, model3D.ref_U, eyemask)
plt.figure()
plt.title('Frontalized no symmetry')
plt.imshow(frontal_raw[:, :, ::-1])
plt.figure()
plt.title('Frontalized with soft symmetry')
plt.imshow(frontal_sym[:, :, ::-1])
plt.show()
if __name__ == "__main__":
demo()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/sesepp/face-frontalization.git
git@gitee.com:sesepp/face-frontalization.git
sesepp
face-frontalization
face-frontalization
master

搜索帮助