← Back to the animated process

scripts/capture_turntable_dataset.py

Implementation snapshot supporting the published lesson. Only cited line ranges are included; this is not a runnable source file. Configuration and recorded examples describe this project snapshot.

… uncited lines omitted …
71    parser.add_argument("--setup-tag-size-mm", type=float, default=14,72                        help="Temporary box tag edge length, excluding quiet zone (default: 14)")73    parser.add_argument("--permanent-tag-size-mm", type=float, default=28,74                        help="Permanent table tag edge length, excluding quiet zone (default: 28)")75    parser.add_argument("--tag-family", choices=TAG_FAMILIES, default="tagStandard41h12",76                        help="AprilTag family used for every printed tag (default: tagStandard41h12)")77    parser.add_argument("--setup-ids", type=ids_arg, default=(1, 2, 3, 4),78                        help="Four unordered setup tags: three surface corners and one top")79    parser.add_argument("--permanent-ids", type=ids_arg, default=(5, 6, 7, 8, 9, 10),80                        help="All fixed turntable tag IDs; first visible ID defines table frame")81    parser.add_argument("--camera-backend", choices=("orbbec", "realsense", "auto"), default="orbbec",82                        help="RGB-D backend (default: Orbbec Gemini 305)")83    parser.add_argument("--serial", help="Camera serial if more than one is connected")84    parser.add_argument("--depth-min", type=float, default=0.25)85    parser.add_argument("--depth-max", type=float, default=1.5)86    parser.add_argument("--reference", type=Path,87                        help="Use an existing canonical reference.ply instead of requiring an in-session scan")88    parser.add_argument("--scan-seconds", type=float, default=30,89                        help="TSDF reference-scan duration started by P (default: 30)")90    parser.add_argument("--scan-voxel-mm", type=float, default=3,91                        help="TSDF voxel size for the raw reference scan (default: 3)")92    parser.add_argument("--scan-downscale", type=int, choices=(1, 2, 4), default=1,93                        help="Reference-scan RGB-D downscale (default: 1 for CUDA)")94    parser.add_argument("--scan-stall-timeout", type=float, default=60,95                        help="Seconds allowed for one native scan operation (default: 60)")96    parser.add_argument("--scan-device", choices=("cpu", "cuda", "auto"), default="cuda",97                        help="Reference-scan compute device (default: cuda)")98    parser.add_argument("--reference-editor-port", type=int, default=0,… uncited lines omitted …
558            if capture:559                if label is None:560                    status = "Cannot capture: permanent tags or box pose unavailable"561                    continue562                if any(tag_id in detections for tag_id in args.setup_ids):563                    status = "Remove all four setup tags before capturing"564                    continue565                name = str(frame.timestamp_ns or time.time_ns())566                image_path = args.output / "images" / f"{name}.png"567                raw_path = args.output / "raw_images" / f"{name}.png"568                depth_path = args.output / "depths" / f"{name}.png"569                label_path = args.output / "labels" / f"{name}.json"570                if (image_path.exists() or raw_path.exists() or depth_path.exists()571                        or label_path.exists()):572                    status = "Timestamp already saved; try again"573                    continue574                raw_bgr = cv2.cvtColor(frame.color, cv2.COLOR_RGB2BGR)575                model_rgb = remove_tags(frame.color, detections, args.permanent_ids)576                model_bgr = cv2.cvtColor(model_rgb, cv2.COLOR_RGB2BGR)577                if not cv2.imwrite(str(raw_path), raw_bgr):578                    status = "Failed to write raw image"579                    continue580                if not cv2.imwrite(str(image_path), model_bgr):581                    status = "Failed to write image"582                    continue583                if not cv2.imwrite(str(depth_path), frame.depth):584                    status = "Failed to write aligned depth"585                    continue586                label["image"] = str(image_path.relative_to(args.output))587                label["raw_image"] = str(raw_path.relative_to(args.output))588                label["depth"] = str(depth_path.relative_to(args.output))589                label["depth_unit_m"] = 0.001590                label["depth_invalid_value"] = 0591                label["depth_aligned_to"] = "rectified color image"592                label["depth_range_m"] = [args.depth_min, args.depth_max]593                label["permanent_tags_inpainted"] = True594                save_json(label_path, label)595                try:596                    export_centerpose_sample(597                        args.output, label, args.centerpose_category, args.centerpose_split)598                except (ValueError, OSError, KeyError) as exc:599                    status = f"Saved audit label but CenterPose export failed: {exc}"600                    print(status, flush=True)601                    continue602                with (args.output / "samples.jsonl").open("a") as manifest:603                    manifest.write(json.dumps({"image": label["image"],604                                               "depth": label["depth"],605                                               "label": str(label_path.relative_to(args.output))}) + "\n")