microsoft / Deep3DFaceReconstruction

Accurate 3D Face Reconstruction with Weakly-Supervised Learning: From Single Image to Image Set (CVPRW 2019)
MIT License
2.18k stars 443 forks source link

How to get UV texture? #145

Open heury opened 3 years ago

heury commented 3 years ago

I modified BFM_UV.mat using select_vertex_id.mat and save it as "BFM_UV_mod.mat" I tried to get UV map using following source code, but I got black image. This source code come from face3d - https://github.com/YadiraF/face3d/blob/master/examples/7_generate_uv_map.py I guess I made mistake in colors variable. Would you guide me how to get UV texture map? I attached source code and BFM_UV_mod.mat file

gentexture.zip

# --load mesh data
C = sio.loadmat('output/000002.mat')

triangles = C['face_shape']
colors = C['face_texture']
colors = colors/np.max(colors)
# --load uv coords
uv_coords = face3d.morphable_model.load.load_uv_coords('BFM_UV_mod.mat') 
uv_h = uv_w = 256
image_h = image_w = 256
uv_coords = process_uv(uv_coords, uv_h, uv_w)

#-- 1. uv texture map
attribute = colors
uv_texture_map = mesh.render.render_colors(uv_coords, triangles, attribute, uv_h, uv_w, c=3)
io.imsave('{}/uv_texture_map.jpg'.format(save_folder), np.squeeze(uv_texture_map))