Skip to content

Commit

Permalink
option to save output meshes as obj files
Browse files Browse the repository at this point in the history
  • Loading branch information
mkocabas committed Dec 17, 2019
1 parent 1147b97 commit c787361
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,19 @@ def main(args):

mc = mesh_color[person_id]

mesh_filename = None

if args.save_obj:
mesh_folder = os.path.join(output_path, 'meshes', f'{person_id:04d}')
os.makedirs(mesh_folder, exist_ok=True)
mesh_filename = os.path.join(mesh_folder, f'{frame_idx:06d}.obj')

img = renderer.render(
img,
frame_verts,
cam=frame_cam,
color=mc,
mesh_filename=mesh_filename,
)

if args.sideview:
Expand Down Expand Up @@ -361,6 +369,9 @@ def main(args):
parser.add_argument('--sideview', action='store_true',
help='render meshes from alternate viewpoint.')

parser.add_argument('--save_obj', action='store_true',
help='save results as .obj files.')

args = parser.parse_args()

main(args)
2 changes: 2 additions & 0 deletions doc/demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ For this option, you have to set `--tracking_method` option to `pose`.
- `--sideview`: Render the output meshes from an alternate viewpoint. Default alternate viewpoint is -90 degrees in y axis.
Note that this option doubles the rendering time.

- `--save_obj`: Save output meshes as .obj files.

## Examples
- Run VIBE on a video file using bbox tracker and visualize the results with wireframe meshes:
```bash
Expand Down
5 changes: 4 additions & 1 deletion lib/utils/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ def __init__(self, resolution=(224,224), orig_img=False, wireframe=False):
light_pose[:3, 3] = [1, 1, 2]
self.scene.add(light, pose=light_pose)

def render(self, img, verts, cam, angle=None, axis=None, color=[1.0, 1.0, 0.9]):
def render(self, img, verts, cam, angle=None, axis=None, mesh_filename=None, color=[1.0, 1.0, 0.9]):

mesh = trimesh.Trimesh(vertices=verts, faces=self.faces)

Rx = trimesh.transformations.rotation_matrix(math.radians(180), [1, 0, 0])
mesh.apply_transform(Rx)

if mesh_filename is not None:
mesh.export(mesh_filename)

if angle and axis:
R = trimesh.transformations.rotation_matrix(math.radians(angle), axis)
mesh.apply_transform(R)
Expand Down

0 comments on commit c787361

Please sign in to comment.