Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about "I first use the tool to generate the mesh_hand and mesh_obj folders. " #24

Open
lpy523 opened this issue Oct 16, 2024 · 2 comments

Comments

@lpy523
Copy link

lpy523 commented Oct 16, 2024

In tool, I can't seem to find the code that generates mesh_hand and mesh_obj folders directly, can anyone help me find it?

@zerchen
Copy link
Owner

zerchen commented Oct 23, 2024

Hi,

I use the following code to generate meshes.

Best,
Zerui

import argparse
import os
from tqdm import tqdm
import numpy as np
import open3d

from obman.obman import ObMan

MANO_WATERTIGHT_OBJ_PATH = './MANO_WATERTIGHT.obj'


def generate_open3d_mesh(vertices, faces, category = 'hand'):
    mesh = open3d.geometry.TriangleMesh()
    mesh.vertices = open3d.utility.Vector3dVector(np.copy(vertices))

    if category == 'hand':
        # mano_watertight_mesh = open3d.io.read_triangle_mesh(MANO_WATERTIGHT_OBJ_PATH)
        # mesh.triangles = open3d.utility.Vector3iVector(np.copy(np.asarray(mano_watertight_mesh.triangles)))
        mesh.triangles = open3d.utility.Vector3iVector(np.copy(faces))
    elif category == 'obj':
        mesh.triangles = open3d.utility.Vector3iVector(np.copy(faces))
    
    return mesh


parser = argparse.ArgumentParser()
parser.add_argument('--root', default="/home2/zerui/dataset/obman/obman", required=False, help="Path to dataset root")
parser.add_argument(
    '--shapenet_root', default="/home2/zerui/dataset/ShapeNetCore.v2", required=False, help="Path to root of ShapeNetCore.v2")
parser.add_argument(
    '--split', type=str, default='train', help='Usually [train|test]')
parser.add_argument('--sides', type=str, default='left')
args = parser.parse_args()

pose_dataset = ObMan(args.root, args.shapenet_root, split=args.split, use_cache=False)
os.makedirs(os.path.join(args.root, args.split, 'mesh_hand'), exist_ok=True)
os.makedirs(os.path.join(args.root, args.split, 'mesh_obj'), exist_ok=True)

for i in tqdm(range(len(pose_dataset.image_names))):
    filename = pose_dataset.image_names[i].split('/')[-1].split('.')[0]
    hand_verts3d = pose_dataset.get_verts3d(i)
    hand_faces = np.load('closed_fmano.npy')
    obj_verts3d, obj_faces = pose_dataset.get_obj_verts_faces(i)

    hand_mesh = generate_open3d_mesh(hand_verts3d, hand_faces, 'hand')
    obj_mesh = generate_open3d_mesh(obj_verts3d, obj_faces, 'obj')

    open3d.io.write_triangle_mesh(os.path.join(args.root, args.split, 'mesh_hand', filename +'.obj'), hand_mesh)
    open3d.io.write_triangle_mesh(os.path.join(args.root, args.split, 'mesh_obj', filename +'.obj'), obj_mesh)(base)

@lpy523
Copy link
Author

lpy523 commented Oct 31, 2024

Thank you for your reply! I will try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants