1313More information about RingNet is available at https://ringnet.is.tue.mpg.de.
1414"""
1515
16- ## A function to load the dynamic contour on a template mesh
16+ ## A function to load the dynamic contour and the static landmarks on a template mesh
1717## Please cite the updated citaion from https://ringnet.is.tue.mpg.de if you use the dynamic contour for FLAME
18+ ## The use of static and dynamic contours for any project follows the liscencing from FLAME (http://flame.is.tue.mpg.de/)
1819
1920import numpy as np
2021import pyrender
2122import trimesh
2223from smpl_webuser .serialization import load_model
2324from psbody .mesh import Mesh
25+ import cPickle as pickle
26+
27+ def load_static_embedding (static_embedding_path ):
28+ with open (static_embedding_path , 'rb' ) as f :
29+ lmk_indexes_dict = pickle .load (f )
30+ lmk_face_idx = lmk_indexes_dict [ 'lmk_face_idx' ].astype ( np .uint32 )
31+ lmk_b_coords = lmk_indexes_dict [ 'lmk_b_coords' ]
32+ return lmk_face_idx , lmk_b_coords
2433
2534def mesh_points_by_barycentric_coordinates (mesh_verts , mesh_faces , lmk_face_idx , lmk_b_coords ):
2635 # function: evaluation 3d points given mesh and landmark embedding
@@ -30,13 +39,16 @@ def mesh_points_by_barycentric_coordinates(mesh_verts, mesh_faces, lmk_face_idx,
3039 (mesh_verts [mesh_faces [lmk_face_idx ], 2 ] * lmk_b_coords ).sum (axis = 1 )]).T
3140 return dif1
3241
33- def load_dynamic_contour (template_flame_path = 'None' , contour_embeddings_path = 'None' , angle = 0 ):
42+ def load_dynamic_contour (template_flame_path = 'None' , contour_embeddings_path = 'None' , static_embedding_path = 'None' , angle = 0 ):
3443 template_mesh = Mesh (filename = template_flame_path )
3544 contour_embeddings_path = contour_embeddings_path
3645 dynamic_lmks_embeddings = np .load (contour_embeddings_path , allow_pickle = True ).item ()
37- lmk_face_idx = dynamic_lmks_embeddings ['lmk_face_idx' ][angle ]
38- lmk_b_coords = dynamic_lmks_embeddings ['lmk_b_coords' ][angle ]
39- dynamic_lmks = mesh_points_by_barycentric_coordinates (template_mesh .v , template_mesh .f , lmk_face_idx , lmk_b_coords )
46+ lmk_face_idx_static , lmk_b_coords_static = load_static_embedding (static_embedding_path )
47+ lmk_face_idx_dynamic = dynamic_lmks_embeddings ['lmk_face_idx' ][angle ]
48+ lmk_b_coords_dynamic = dynamic_lmks_embeddings ['lmk_b_coords' ][angle ]
49+ dynamic_lmks = mesh_points_by_barycentric_coordinates (template_mesh .v , template_mesh .f , lmk_face_idx_dynamic , lmk_b_coords_dynamic )
50+ static_lmks = mesh_points_by_barycentric_coordinates (template_mesh .v , template_mesh .f , lmk_face_idx_static , lmk_b_coords_static )
51+ total_lmks = np .vstack ([dynamic_lmks , static_lmks ])
4052
4153 # Visualization of the pose dependent contour on the template mesh
4254 vertex_colors = np .ones ([template_mesh .v .shape [0 ], 4 ]) * [0.3 , 0.3 , 0.3 , 0.8 ]
@@ -47,8 +59,8 @@ def load_dynamic_contour(template_flame_path='None', contour_embeddings_path='No
4759 scene .add (mesh )
4860 sm = trimesh .creation .uv_sphere (radius = 0.005 )
4961 sm .visual .vertex_colors = [0.9 , 0.1 , 0.1 , 1.0 ]
50- tfs = np .tile (np .eye (4 ), (len (dynamic_lmks ), 1 , 1 ))
51- tfs [:, :3 , 3 ] = dynamic_lmks
62+ tfs = np .tile (np .eye (4 ), (len (total_lmks ), 1 , 1 ))
63+ tfs [:, :3 , 3 ] = total_lmks
5264 joints_pcl = pyrender .Mesh .from_trimesh (sm , poses = tfs )
5365 scene .add (joints_pcl )
5466 pyrender .Viewer (scene , use_raymond_lighting = True )
@@ -57,5 +69,8 @@ def load_dynamic_contour(template_flame_path='None', contour_embeddings_path='No
5769 # angle = 35.0 #in degrees
5870 angle = 0.0 #in degrees
5971 # angle = -16.0 #in degrees
72+ if angle < 0 :
73+ angle = 39 - angle
6074 contour_embeddings_path = './flame_model/flame_dynamic_embedding.npy'
61- load_dynamic_contour (template_flame_path = './flame_model/FLAME_sample.ply' , contour_embeddings_path = contour_embeddings_path , angle = int (angle ))
75+ static_embedding_path = './flame_model/flame_static_embedding.pkl'
76+ load_dynamic_contour (template_flame_path = './flame_model/FLAME_sample.ply' , contour_embeddings_path = contour_embeddings_path , static_embedding_path = static_embedding_path , angle = int (angle ))
0 commit comments