zerchen / AlignSDF

AlignSDF: Pose-Aligned Signed Distance Fields for Hand-Object Reconstruction, ECCV 2022
75 stars 10 forks source link

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

Open lpy523 opened 1 month ago

lpy523 commented 1 month ago

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

zerchen commented 1 month ago

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 commented 1 month ago

Thank you for your reply! I will try it.