face3d
face3d copied to clipboard
how to render fitted model for IBUG image?
Hello all,
I found an image examples/Data/IBUG_image_008_1_0.jpg
and its fitted params examples/Data/IBUG_image_008_1_0.mat
. I tried following to render the fitted model
# --- 1. load model
bfm = MorphabelModel('../examples/Data/BFM/Out/BFM.mat')
print('init bfm model success')
# --- 2. load fitted face
pic_name = 'IBUG_image_008_1_0'
mat_filename = '../examples/Data/{0}.mat'.format(pic_name)
mat_data = sio.loadmat(mat_filename)
image_filename = '../examples/Data/{0}.jpg'.format(pic_name)
with open(image_filename, 'rb') as file:
img = Image.open(file)
print('image size: {0}'.format(img.size))
sp = mat_data['Shape_Para']
ep = mat_data['Exp_Para']
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
pp = mat_data['Pose_Para']
s = pp[0, 6]
# angles = [np.rad2deg(pp[0, 0]), np.rad2deg(pp[0, 1]), np.rad2deg(pp[0, 2])]
angles = pp[0, 0:3]
t = pp[0, 3:6]
# set prop of rendering
h = w = 450
c = 3
# s = 8e-04
# angles = [10, 30, 20]
# t = [0, 0, 0]
transformed_vertices = bfm.transform_3ddfa(vertices, s, angles, t)
projected_vertices = transformed_vertices.copy() # using stantard camera & orth projection
# projected_vertices[:,1] = h - projected_vertices[:,1] - 1
# --- 4. render(3d obj --> 2d image)
image_vertices = mesh.transform.to_image(projected_vertices, h, w)
image = mesh.render.render_colors(image_vertices, bfm.triangles, colors, h, w)
io.imsave('./generated.jpg', image)
however, only a part of the rendered face can be seen in the image. If I increase the image size from 450 to 1024, then I see the full rendered face. Is there something wrong with how I handled the translation params?
I have the same problem as you. Have you solved it?