lipeize commited on
Commit
89f63de
·
verified ·
1 Parent(s): 8245141

GraspNet-1Billion example scene (scene_0000 RealSense, 256 views, 9 models) + reconstruction script

Browse files
graspnet_example/README.md ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # GraspNet-1Billion example scene (scene_0000, RealSense, all 256 views)
2
+
3
+ One complete scene of [GraspNet-1Billion](https://graspnet.net/) (Fang et al., CVPR 2020) with everything needed to
4
+ reconstruct it: the 9 object meshes, every per-view object pose, the camera trajectory, and the RGB-D images with
5
+ segmentation labels. It is included as the reference for rendering multi-object scenes in the GraspNet style.
6
+
7
+ **Licence: this folder is CC BY-NC-SA 4.0** (GraspNet team, MVIG, SJTU: free for non-commercial use, redistribution
8
+ under the same conditions, https://graspnet.net/about), separate from the CC-BY / CC0 objects in `objects/`. Cite:
9
+
10
+ ```
11
+ @inproceedings{fang2020graspnet, title={GraspNet-1Billion: A Large-Scale Benchmark for General Object Grasping},
12
+ author={Fang, Hao-Shu and Wang, Chenxi and Gou, Minghao and Lu, Cewu}, booktitle={CVPR}, year={2020}}
13
+ ```
14
+
15
+ ## Files
16
+
17
+ ```
18
+ scene_0000_realsense.zip
19
+ scene_0000/object_id_list.txt the 9 GraspNet object ids in this scene (14 0 5 15 20 48 66 70 46)
20
+ scene_0000/rs_wrt_kn.npy RealSense pose with respect to the Kinect (not needed here)
21
+ scene_0000/realsense/camK.npy 3x3 intrinsics (also inside every meta file)
22
+ scene_0000/realsense/camera_poses.npy (256,4,4) pose of camera v with respect to camera 0 (view 0)
23
+ scene_0000/realsense/cam0_wrt_table.npy (4,4) pose of camera 0 with respect to the table frame (z up)
24
+ scene_0000/realsense/rgb/VVVV.png 1280x720 colour
25
+ scene_0000/realsense/depth/VVVV.png 16-bit depth in millimetres (divide by factor_depth = 1000)
26
+ scene_0000/realsense/label/VVVV.png per-pixel GraspNet object id + 1, 0 = background
27
+ scene_0000/realsense/meta/VVVV.mat poses (3,4,N) object->camera transforms in metres, cls_indexes (N,) = object id + 1,
28
+ intrinsic_matrix (3,3), factor_depth
29
+ scene_0000/realsense/annotations/VVVV.xml the same poses as position + quaternion in the camera frame (graspnetAPI's XML form)
30
+ models_scene_0000.zip
31
+ models/OID/textured.obj + .mtl + texture image, nontextured.ply, nontextured_simplified.ply (metres, object frame)
32
+ reconstruct_scene.py standalone reconstruction and check (numpy, scipy, Pillow, trimesh)
33
+ ```
34
+
35
+ Views are indexed 0..255 along the recorded camera trajectory; object poses are given per view in that view's camera
36
+ frame, so the same scene can be reconstructed from any view. `camera_poses.npy` and `cam0_wrt_table.npy` put all views
37
+ in one table frame: `cam_v_wrt_table = cam0_wrt_table @ camera_poses[v]`.
38
+
39
+ ## Reconstruct
40
+
41
+ ```
42
+ unzip scene_0000_realsense.zip; unzip models_scene_0000.zip
43
+ python reconstruct_scene.py --scene scene_0000 --models models --view 0 --out out # camera frame of view 0
44
+ python reconstruct_scene.py --scene scene_0000 --models models --view 137 --table-frame --out out
45
+ ```
46
+
47
+ The script prints each object's pose, writes `out/scene_VVVV.glb` (the textured meshes at their poses; add `--no-texture`
48
+ for a small file) and `out/depth_VVVV.ply` (the back-projected depth of the object pixels, coloured), and reports the
49
+ distance between those depth points and the reconstructed surfaces as a check (a few millimetres for a correct pose
50
+ convention). The pose logic follows graspnetAPI's `loadSceneModel` / `generate_scene_model` as used in GraspFormer.
51
+
52
+ Not included: the grasp labels (`grasp_label/`, per object) and the per-scene collision labels (`collision_label/`,
53
+ 184 MB for this scene); both are in the original GraspNet-1Billion release.
graspnet_example/models_scene_0000.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d4f557c4d03e96037055c44ba952f96e37b7253b74bada3a0ae8d1471b41cea0
3
+ size 585692112
graspnet_example/reconstruct_scene.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Reconstruct a GraspNet-1Billion scene from its stored object poses, and check it against the depth image.
2
+
3
+ Adapted from graspnetAPI (Fang et al., CVPR 2020; `GraspNet.loadSceneModel` / `generate_scene_model`) as vendored in
4
+ GraspFormer (graspformer/data/graspnet_api). Standalone: numpy, scipy, Pillow, trimesh.
5
+
6
+ GraspNet conventions used here
7
+ scene_XXXX/<camera>/meta/VVVV.mat poses (3,4,N): object -> camera transforms (metres) for view VVVV;
8
+ cls_indexes (N,): GraspNet object id + 1; intrinsic_matrix (3,3); factor_depth (1000)
9
+ scene_XXXX/<camera>/depth/VVVV.png 16-bit depth in millimetres (divide by factor_depth)
10
+ scene_XXXX/<camera>/label/VVVV.png object id + 1 per pixel, 0 = background
11
+ scene_XXXX/<camera>/camera_poses.npy (256,4,4): pose of camera VVVV with respect to camera 0 (view 0)
12
+ scene_XXXX/<camera>/cam0_wrt_table.npy (4,4): pose of camera 0 with respect to the table frame (z up)
13
+ models/OID/textured.obj (+ .mtl, texture_map.png), nontextured.ply : object meshes in metres, object frame
14
+
15
+ Usage:
16
+ python reconstruct_scene.py --scene scene_0000 --models models --view 0 --out out/ # camera frame of view 0
17
+ python reconstruct_scene.py ... --table-frame # table frame (z up)
18
+ Writes out/scene_<view>.glb (textured meshes at their poses), out/depth_<view>.ply (back-projected depth, coloured),
19
+ prints the pose table and the median distance between depth points on objects and the reconstructed surfaces.
20
+ """
21
+ import argparse, os
22
+ import numpy as np, scipy.io as sio, trimesh
23
+ from PIL import Image
24
+
25
+
26
+ def load_view(scene_dir, camera, view):
27
+ cam = os.path.join(scene_dir, camera)
28
+ meta = sio.loadmat(os.path.join(cam, "meta", f"{view:04d}.mat"))
29
+ poses = meta["poses"].transpose(2, 0, 1).astype(np.float64) # (N,3,4) object -> camera, metres
30
+ ids = meta["cls_indexes"].ravel().astype(int) - 1 # GraspNet object ids 0..87
31
+ K = meta["intrinsic_matrix"].astype(np.float64); depth_scale = float(meta["factor_depth"].ravel()[0])
32
+ depth = np.array(Image.open(os.path.join(cam, "depth", f"{view:04d}.png")), dtype=np.float32) / depth_scale # metres
33
+ rgb = np.array(Image.open(os.path.join(cam, "rgb", f"{view:04d}.png")).convert("RGB"))
34
+ label = np.array(Image.open(os.path.join(cam, "label", f"{view:04d}.png")))
35
+ cam_wrt_cam0 = np.load(os.path.join(cam, "camera_poses.npy"))[view]
36
+ cam0_wrt_table = np.load(os.path.join(cam, "cam0_wrt_table.npy"))
37
+ return dict(poses=poses, ids=ids, K=K, depth=depth, rgb=rgb, label=label, cam_wrt_table=cam0_wrt_table @ cam_wrt_cam0)
38
+
39
+
40
+ def backproject(depth, K, rgb=None, mask=None):
41
+ """Pixels -> camera-frame points (metres); returns (points, colours)."""
42
+ h, w = depth.shape; u, v = np.meshgrid(np.arange(w), np.arange(h))
43
+ z = depth; x = (u - K[0, 2]) * z / K[0, 0]; y = (v - K[1, 2]) * z / K[1, 1]
44
+ pts = np.stack([x, y, z], -1).reshape(-1, 3); keep = z.reshape(-1) > 0
45
+ if mask is not None: keep &= mask.reshape(-1)
46
+ return pts[keep], (rgb.reshape(-1, 3)[keep] if rgb is not None else None)
47
+
48
+
49
+ def compose(models_dir, view, textured=True, table_frame=False):
50
+ """trimesh.Scene of the scene's objects at their poses (camera frame of this view, or the table frame)."""
51
+ scene = trimesh.Scene(); T_frame = view["cam_wrt_table"] if table_frame else np.eye(4)
52
+ for oid, P in zip(view["ids"], view["poses"]):
53
+ T = np.eye(4); T[:3] = P; T = T_frame @ T
54
+ m = trimesh.load(os.path.join(models_dir, f"{oid:03d}", "textured.obj" if textured else "nontextured.ply"), force="mesh")
55
+ m.apply_transform(T); scene.add_geometry(m, node_name=f"obj_{oid:03d}")
56
+ return scene
57
+
58
+
59
+ def main():
60
+ ap = argparse.ArgumentParser()
61
+ ap.add_argument("--scene", required=True); ap.add_argument("--models", required=True); ap.add_argument("--camera", default="realsense")
62
+ ap.add_argument("--view", type=int, default=0); ap.add_argument("--out", default="out"); ap.add_argument("--table-frame", action="store_true")
63
+ ap.add_argument("--no-texture", action="store_true")
64
+ a = ap.parse_args(); os.makedirs(a.out, exist_ok=True)
65
+ v = load_view(a.scene, a.camera, a.view)
66
+ T_frame = v["cam_wrt_table"] if a.table_frame else np.eye(4)
67
+ print(f"{os.path.basename(a.scene)} {a.camera} view {a.view}: {len(v['ids'])} objects; frame = {'table' if a.table_frame else 'camera'}")
68
+ for oid, P in zip(v["ids"], v["poses"]):
69
+ T = T_frame @ np.vstack([P, [0, 0, 0, 1]])
70
+ print(f" object {oid:03d}: position {np.round(T[:3, 3], 4).tolist()} rotation rows {np.round(T[:3, :3], 3).tolist()}")
71
+ scene = compose(a.models, v, textured=not a.no_texture, table_frame=a.table_frame)
72
+ glb = os.path.join(a.out, f"scene_{a.view:04d}.glb"); scene.export(glb)
73
+ pts, cols = backproject(v["depth"], v["K"], v["rgb"], mask=v["label"] > 0)
74
+ pts = trimesh.transform_points(pts, T_frame)
75
+ ply = os.path.join(a.out, f"depth_{a.view:04d}.ply"); trimesh.PointCloud(pts, colors=cols).export(ply)
76
+ # sanity: depth points on labelled objects should lie on the reconstructed surfaces
77
+ from scipy.spatial import cKDTree
78
+ surface = scene.dump(concatenate=True).sample(300_000) # dense surface sample of the reconstruction
79
+ sample = pts[np.random.default_rng(0).choice(len(pts), min(5000, len(pts)), replace=False)]
80
+ d = cKDTree(surface).query(sample)[0]
81
+ print(f"depth points on objects: {len(pts)}; distance to reconstructed surfaces: median {1e3 * np.median(d):.1f} mm, 90th pct {1e3 * np.percentile(d, 90):.1f} mm")
82
+ print(f"wrote {glb} and {ply}")
83
+
84
+
85
+ if __name__ == "__main__":
86
+ main()
graspnet_example/scene_0000_realsense.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:86e743e9b93d8eb35aad55a4d90c3cedd62db68ee28e9afd859fe3aefb1f9dcc
3
+ size 372919595