barisgecer / OSTeC

TF implementation of our CVPR 2021 paper: OSTeC: One-Shot Texture Completion
https://openaccess.thecvf.com/content/CVPR2021/html/Gecer_OSTeC_One-Shot_Texture_Completion_CVPR_2021_paper.html
Other
192 stars 28 forks source link

How to render correctly? #16

Closed laolongboy closed 2 years ago

laolongboy commented 2 years ago

input: ffhq

render results after reconstruction: ffhq_render_angle_0 ffhq_render_angle_45

code:

# fitting
fitting = deep3dmodel.recontruct(im_menpo2PIL(img), lms, test=False)

# Prepare Textured Trimesh with visible part of the face
face = operator.get_tmesh(im, fitting)

# Render to specific angle
from utils.image_rasterization import rasterize_image

im, _ = rasterize_image(face.tmesh, operator.img_shape, pose_angle_deg=[0, 0, 0], cam_dist=4.5)
cv2.imwrite(f'./split_test/ffhq_render_angle_0.jpg', np.array(im_menpo2PIL(im))[:, :, ::-1])

im, _ = rasterize_image(face.tmesh, operator.img_shape, pose_angle_deg=[0, 45, 0], cam_dist=4.5)
cv2.imwrite(f'./split_test/ffhq_render_angle_45.jpg', np.array(im_menpo2PIL(im))[:, :, ::-1])
barisgecer commented 2 years ago

In the latest commit, I replaced the topology with full-face topology. Thus this problem should be fixed. Can you try again?

laolongboy commented 2 years ago

I found out that the problem is the index of 'trilist'. The trilist for face.tmesh starts at -1. Adding 1 before rendering gives the correct result.

def create_syn(self, face, trg_angle=[0, 0, 0], include_mask=None):
        view_angle_trg = self.camera_tri_angle(face.tmesh, pose_angle_deg=trg_angle)
        mesh_cp = face.tmesh.copy()
        mesh_cp.trilist = mesh_cp.trilist + 1
        im, projected_mesh = rasterize_image(mesh_cp, self.img_shape, pose_angle_deg=trg_angle, cam_dist=4.5)
barisgecer commented 2 years ago

Thanks, that is weird. Not sure what causes this. Nevertheless, with the latest version (as far as I checked) this shouldn't be an issue if you follow my export script.