def generate_bfm_base_obj(): bfm = MorphabelModel('../Data/BFM/Out/BFM.mat') sp = bfm.get_shape_para('zero') ep = bfm.get_exp_para('zero') tp = bfm.get_tex_para('random') vertices = bfm.generate_vertices(sp, ep) colors = bfm.generate_colors(tp) colors = np.minimum(np.maximum(colors, 0), 255) write_obj_with_colors('head_fit.obj', vertices, bfm.triangles, colors)
from time import time import matplotlib.pyplot as plt sys.path.append('..') import face3d from face3d import mesh from face3d.morphable_model import MorphabelModel # --------------------- Forward: parameters(shape, expression, pose) --> 3D obj --> 2D image --------------- # --- 1. load model bfm = MorphabelModel('Data/BFM/Out/BFM.mat') print('init bfm model success') # --- 2. generate face mesh: vertices(represent shape) & colors(represent texture) sp = bfm.get_shape_para('random') ep = bfm.get_exp_para('random') vertices = bfm.generate_vertices(sp, ep) tp = bfm.get_tex_para('random') colors = bfm.generate_colors(tp) colors = np.minimum(np.maximum(colors, 0), 1) # --- 3. transform vertices to proper position s = 8e-04 angles = [10, 30, 20] t = [0, 0, 0] transformed_vertices = bfm.transform(vertices, s, angles, t) projected_vertices = transformed_vertices.copy( ) # using stantard camera & orth projection # --- 4. render(3d obj --> 2d image)
import matplotlib.pyplot as plt sys.path.append('..') import face3d from face3d import mesh from face3d import mesh_cython from face3d.morphable_model import MorphabelModel # --------------------- Forward: parameters(shape, expression, pose) --> 3D obj --> 2D image --------------- # --- 1. load model bfm = MorphabelModel('Data/BFM/Out/BFM.mat') print('init bfm model success') # --- 2. generate face mesh: vertices(represent shape) & colors(represent texture) sp = bfm.get_shape_para('random') ep = bfm.get_exp_para('random') vertices = bfm.generate_vertices(sp, ep) tp = bfm.get_tex_para('random') colors = bfm.generate_colors(tp) colors = np.minimum(np.maximum(colors, 0), 1) # --- 3. transform vertices to proper position s = 8e-04 angles = [10, 30, 20] t = [0, 0, 0] transformed_vertices = bfm.transform(vertices, s, angles, t) projected_vertices = transformed_vertices.copy() # using stantard camera & orth projection # --- 4. render(3d obj --> 2d image) # set prop of rendering
from time import time import matplotlib.pyplot as plt sys.path.append('..') import face3d from face3d import mesh from face3d.morphable_model import MorphabelModel # --------------------- Forward: parameters(shape, expression, pose) --> 3D obj --> 2D image --------------- # --- 1. load model 【载入3D参数,即BFM参数,用于生成mesh数据,从而进一步地生成2D人脸图像】 bfm = MorphabelModel('Data/BFM/Out/BFM.mat') print('init bfm model success') # --- 2. generate face mesh: vertices(represent shape) & colors(represent texture) sp = bfm.get_shape_para('random') # shape参数 ep = bfm.get_exp_para('random') # expression参数 vertices = bfm.generate_vertices(sp, ep) tp = bfm.get_tex_para('random') # texture参数,也即colors——颜色 colors = bfm.generate_colors(tp) colors = np.minimum(np.maximum(colors, 0), 1) # --- 3. transform vertices to proper position # 转换坐标系 s = 8e-04 angles = [10, 30, 20] t = [0, 0, 0] transformed_vertices = bfm.transform(vertices, s, angles, t) projected_vertices = transformed_vertices.copy() # using stantard camera & orth projection # --- 4. render(3d obj --> 2d image) # 渲染,将3d转变为颜色正常的2d # set prop of rendering
sys.path.append('..') from face3d import mesh from face3d.morphable_model import MorphabelModel # --------------------- Forward: parameters(shape, expression, pose) --> 3D obj --> 2D image --------------- # --- 1. load model bfm = MorphabelModel('Data/BFM/Out/BFM.mat') print('init bfm model success') # print(bfm.n_tex_para) # --- 2. generate face mesh: vertices(represent shape) & colors(represent texture) # sp = bfm.get_shape_para('random') sp = bfm.get_shape_para('zero') # print(sp_sigma) # print(sp_sigma.shape) ep = bfm.get_exp_para('zero') print(ep.shape) ep[:10] = np.array([[-2.4658144 ], [ 1.5232908 ], [-0.58274204], [ 1.1200945 ], [ 0.35412225], [-1.2616647 ], [-1.0544292 ], [-1.6552277 ], [-0.41645545], [-1.2801003 ]]) exp_sigma = bfm.get_exp_sigma()