Skip to content

Commit

Permalink
add texture render
Browse files Browse the repository at this point in the history
  • Loading branch information
yfeng95 committed Jul 19, 2018
1 parent e785a60 commit 4be7c33
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions examples/5_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
C = sio.loadmat('Data/example1.mat')
vertices = C['vertices']; colors = C['colors']; triangles = C['triangles']
colors = colors/np.max(colors)
# move center to [0,0,0]
# transform
vertices = vertices - np.mean(vertices, 0)[np.newaxis, :]
s = 180/(np.max(vertices[:,1]) - np.min(vertices[:,1]))
R = mesh.transform.angle2matrix([0, 0, 0])
Expand All @@ -29,17 +29,7 @@
h = w = 256
image_vertices = mesh.transform.to_image(vertices, h, w)

# -----------------------------------------render
# # render texture python
# st = time()
# rendering_tp = face3d.mesh.render.render_texture(vertices, triangles, texture, texcoord, triangles, h, w)
# print('----------texture python: ', time() - st)

# # render texture c++
# st = time()
# rendering_tc = face3d.mesh_cython.render.render_texture(vertices, triangles, texture, texcoord, triangles, h, w)
# print('----------texture c++: ', time() - st)

# -----------------------------------------render colors
# render colors python
st = time()
rendering_cp = face3d.mesh.render.render_colors(image_vertices, triangles, colors, h, w)
Expand All @@ -53,4 +43,38 @@
# render colors python c++
st = time()
rendering_cc = face3d.mesh_cython.render.render_colors(image_vertices, triangles, colors, h, w)
print('----------colors c++: ', time() - st)
print('----------colors c++: ', time() - st)

# ----------------------------------------- render texture(texture mapping)
# when face texture is saved as texture map, this method is recommended.
# load texture
texture = io.imread('Data/uv_texture_map.jpg')/255.
tex_h, tex_w, _ = texture.shape
# load texcoord(uv coords)
uv_coords = face3d.morphable_model.load.load_uv_coords('Data/BFM/Out/BFM_UV.mat') #
uv_coords[:,0] = uv_coords[:,0]*(tex_h - 1)
uv_coords[:,1] = uv_coords[:,1]*(tex_w - 1)
uv_coords[:,1] = tex_w - uv_coords[:,1] - 1
texcoord = np.hstack((uv_coords, np.zeros((uv_coords.shape[0], 1)))) # add z# render texture python
# tex_triangles
tex_triangles = triangles

# render texture python
st = time()
rendering_tp = face3d.mesh.render.render_texture(image_vertices, triangles, texture, texcoord, tex_triangles, h, w)
print('----------texture python: ', time() - st)

# render texture c++
st = time()
rendering_tc = face3d.mesh_cython.render.render_texture(image_vertices, triangles, texture, texcoord, tex_triangles, h, w)
print('----------texture c++: ', time() - st)
plt.subplot(2,2,1)
plt.imshow(rendering_cp)
plt.subplot(2,2,2)
plt.imshow(rendering_cc)
plt.subplot(2,2,3)
plt.imshow(rendering_tp)
plt.subplot(2,2,4)
plt.imshow(rendering_tc)
plt.show()

0 comments on commit 4be7c33

Please sign in to comment.