This document describes the full pipeline for collecting real-world object manipulation data and converting it into task trajectories for DexToolBench.
Clone and set up the FoundationPose fork in a separate conda environment (foundationpose). See its README for full installation instructions, including model weight downloads and ROS setup.
This environment is used for Steps 1, 3, and live inference.
From the FoundationPose repo, record an RGB-D video with a ZED camera:
conda activate foundationpose
python record_video.py \
--save_dir recordings/ \
--serial_number <ZED_SERIAL> \
--fps 30Press Ctrl+C to stop. This creates:
recordings/<timestamp>/
├── rgb/frame_0000.png, frame_0001.png, ...
├── depth/frame_0000.png, frame_0001.png, ...
├── cam_K.txt
└── rgb.mp4
Use the SimToolReal branches of the SAM2 and SAM3D repos:
- SAM2: https://github.com/tylerlum/segment-anything-2-real-time/tree/SimToolReal
- SAM3D: https://github.com/tylerlum/sam-3d-objects/tree/SimToolReal
Follow the installation instructions in those repos and create separate uv virtual environments for SAM2 and SAM3D. Do not try to share one environment across both repos.
The main entrypoint for this step is run_mesh_pipeline.sh in the SAM2 repo. Before running it, open that script and update the configuration at the top for your machine:
SAM2_REPOSAM3_REPODEMO_DIROUTPUT_DIR- any environment activation assumptions in the
sam2()andsam3()helper functions if your local setup differs
In particular, make sure:
SAM2_REPOpoints to your localsegment-anything-2-real-timecheckoutSAM3_REPOpoints to your localsam-3d-objectscheckoutDEMO_DIRpoints to the recorded data directory containingrgb/,depth/, andcam_K.txtOUTPUT_DIRpoints to where you want the reconstruction and processed mesh artifacts written
Then run the pipeline from the SAM2 repo root:
cd /path/to/segment-anything-2-real-time
bash run_mesh_pipeline.shAt a high level, the script will:
- run SAM2 on the recorded RGB frames to create object masks
- run SAM3D to reconstruct the object mesh from the RGB-D data and masks
- render the reconstructed mesh into RGB/depth views
- run SAM2 on those rendered views to create handle and head masks
- run the final mesh postprocessing step to compute the canonical handle frame and export the final mesh
One small detail: the SAM2 stage writes masks for all frames in the original video, but the current SAM3D reconstruction step only strictly uses the first RGB image, first depth image, and first mask image. We still run SAM2 over the full sequence because it is useful to have all masks available.
The script prints step banners as it runs, and depending on how the prompt arguments are configured, it may ask you to click points on the first frame to initialize SAM2.
For more detail, read run_mesh_pipeline.sh directly. That script is the source of truth for the exact command sequence and the environment assumptions.
The final result should be a metric-scale .obj mesh ready for downstream use in FoundationPose and SimToolReal. The main exported artifact is:
${OUTPUT_DIR}/mesh_handle_frame/mesh_handle_frame.objRun FoundationPose on the recorded video:
conda activate foundationpose
python extract_poses.py \
--video_dir recordings/<timestamp>/ \
--mesh_path /path/to/object.obj \
--calibration /path/to/T_RC.txt \
--output_path recordings/<timestamp>/poses.json \
--debug 1An interactive window opens on the first frame -- click 4 corners of a bounding box around the object for SAM segmentation. FoundationPose then tracks through all frames.
Output (poses.json):
{
"poses_cam": [[x, y, z, qx, qy, qz, qw], ...],
"poses_robot": [[x, y, z, qx, qy, qz, qw], ...]
}From the SimToolReal repo, process the raw poses into a DexToolBench task trajectory:
conda activate simtoolreal
python dextoolbench/process_poses.py \
--poses_path recordings/<timestamp>/poses.json \
--object_category hammer \
--object_name claw_hammer \
--task_name swing_downThis outputs a trajectory JSON to dextoolbench/trajectories/<object_category>/<object_name>/<task_name>.json with poses in world frame, ready for use in training and evaluation.
To run live tracking at inference time, install FoundationPose as described above, then run:
conda activate foundationpose
cd /path/to/FoundationPose
python live_tracking_with_ros.py \
--mesh_path /path/to/object.obj \
--calibration calibration/T_RC_example.txtThis publishes object poses to robot_frame/current_object_pose as a ROS PoseStamped topic, which is consumed by the RL Policy Node. See the main README for the full deployment flowchart.