import argparse from datasets import load_dataset import open3d as o3d import numpy as np import random def vis_hit_sample(sample): """ :param sample: HIT dataset sample :return: """ # get point-cloud from sample pc = np.asarray(sample['body_cont_pc']) # create point-cloud pcd = o3d.geometry.PointCloud() pcd.points = o3d.utility.Vector3dVector(pc) pcd.paint_uniform_color([0.6509803922, 0.2901960784, 0.2823529412]) pcd_front = pcd.__copy__() # get mesh and mesh-free-verts from sample mesh_verts = np.asarray(sample['smpl_dict']['verts']) mesh_verts_free = np.asarray(sample['smpl_dict']['verts_free']) mesh_faces = np.asarray(sample['smpl_dict']['faces']) # create mesh mesh = o3d.geometry.TriangleMesh() mesh.vertices = o3d.utility.Vector3dVector(mesh_verts) mesh.triangles = o3d.utility.Vector3iVector(mesh_faces) mesh.paint_uniform_color([0.737254902, 0.7960784314, 0.8196078431]) # create mesh-free-verts mesh_free = o3d.geometry.TriangleMesh() mesh_free.vertices = o3d.utility.Vector3dVector(mesh_verts_free) mesh_free.triangles = o3d.utility.Vector3iVector(mesh_faces) mesh_free.paint_uniform_color([0.737254902, 0.7960784314, 0.8196078431]) # visualize sample vis = o3d.visualization.Visualizer() vis.create_window() # side-view xyz = (-np.pi / 2, 0, 0) R1 = o3d.geometry.get_rotation_matrix_from_xyz(xyz) # vis mesh with pointcloud vis.add_geometry(mesh.rotate(R1, center=(0, 0, 0))) vis.add_geometry(pcd.rotate(R1, center=(0, 0, 0))) # vis mesh-free-verts with pointcloud vis.add_geometry(mesh_free.translate((1.2, 0, 0))) vis.add_geometry(mesh_free.rotate(R1, center=(0, 0, 0))) vis.add_geometry(pcd_front.translate((1.2, 0, 0))) vis.add_geometry(pcd_front.rotate(R1, center=(0, 0, 0))) # render vis.get_render_option().mesh_show_wireframe = True vis.get_render_option().point_size = 2 vis.poll_events() vis.update_renderer() vis.run() return 0 if __name__ == '__main__': parser = argparse.ArgumentParser(description='HIT dataset visualization') parser.add_argument('--gender', type=str, default='male') parser.add_argument('--split', type=str, default='train') parser.add_argument('--idx', type=int, default=None) # get args args = parser.parse_args() assert args.gender in ['male', 'female'] assert args.split in ['train', 'validation', 'test'] # load split hit_dataset = load_dataset("varora/hit", args.gender, split=args.split) # to load specific split, use: # male splits #male_val = load_dataset("varora/hit", "male", split="validation") #male_val = load_dataset("varora/hit", "male", split="validation") #male_test = load_dataset("varora/hit", "male", split="test") # female splits #female_train = load_dataset("varora/hit", "female", split="train") #female_val = load_dataset("varora/hit", "female", split="validation") #female_test = load_dataset("varora/hit", "female", split="test") # len of split N_dataset = hit_dataset.__len__() # get idx for sample if not args.idx: idx = random.randint(0, N_dataset) else: idx = args.idx # get sample hit_sample = hit_dataset[idx] # visualize the sample print(f"Visualizing sample no. {idx} in {args.gender}:{args.split}.") vis_hit_sample(hit_sample)