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 skimage import io 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
from time import time 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)
for filename in glob.glob('{}/predicted_*.npy'.format(save_folder)): i = os.path.splitext(os.path.basename(filename))[0].split('_')[-1] params = np.load(filename) params = np.float32(params) # sp = params[: bfm.n_shape_para][:, np.newaxis] # tp = params[bfm.n_shape_para : bfm.n_shape_para + bfm.n_tex_para][:, np.newaxis] # pose = params[bfm.n_shape_para + bfm.n_tex_para:] ep = params[:bfm.n_exp_para][:, np.newaxis] pose = params[bfm.n_exp_para:] # --- 2. generate face mesh: vertices(represent shape) & colors(represent texture) sp = bfm.get_shape_para('zero') #ep = bfm.get_exp_para('zero') tp = bfm.get_tex_para('zero') colors = bfm.generate_colors(tp) colors = np.minimum(np.maximum(colors, 0), 1) # --- 3. transform vertices to proper position s = pose[-1] angles = pose[:3] t = np.r_[pose[3:5], [0]] vertices = bfm.generate_vertices(sp, ep) transformed_vertices = bfm.transform(vertices, s, angles, t)