Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve colmap example #1008

Merged
merged 12 commits into from
Jan 31, 2023
26 changes: 15 additions & 11 deletions examples/colmap/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
DATASET_URL_BASE: Final = "https://storage.googleapis.com/rerun-example-datasets/colmap"
DATASET_NAME: Final = "colmap_rusty_car"
DATASET_URL: Final = f"{DATASET_URL_BASE}/{DATASET_NAME}.zip"
# When dataset filtering is turned on, drop views with less than this many valid points.
FILTER_MIN_VISIBLE: Final = 500
nikolausWest marked this conversation as resolved.
Show resolved Hide resolved


def intrinsics_for_camera(camera: Camera) -> npt.NDArray[Any]:
Expand Down Expand Up @@ -92,37 +94,39 @@ def read_and_log_sparse_reconstruction(dataset_path: Path, filter_output: bool)
camera = cameras[image.camera_id]
intrinsics = intrinsics_for_camera(camera)

unique_valid_3d_ids = set(id for id in image.point3D_ids if id != -1 and points3D.get(id) is not None)
sorted_3d_ids = sorted(unique_valid_3d_ids)
visible = [id != -1 and points3D.get(id) is not None for id in image.point3D_ids]
visible_ids = image.point3D_ids[visible]

visible_points = [points3D[id] for id in sorted_3d_ids]

if filter_output and len(visible_points) < 500:
if filter_output and len(visible_ids) < FILTER_MIN_VISIBLE:
continue

visible_xyzs = [points3D[id] for id in visible_ids]
visible_xys = image.xys[visible]

rr.set_time_sequence("frame", frame_idx)

points = [point.xyz for point in visible_points] # type: ignore[union-attr]
point_colors = [point.rgb for point in visible_points] # type: ignore[union-attr]
rr.log_points(f"world/points", points, identifiers=sorted_3d_ids, colors=point_colors)
points = [point.xyz for point in visible_xyzs]
point_colors = [point.rgb for point in visible_xyzs]

rr.log_points("world/points", points, colors=point_colors)

rr.log_rigid3(
f"world/camera",
"world/camera",
child_from_parent=camera_from_world,
xyz="RDF", # X=Right, Y=Down, Z=Forward
)

# Log camera intrinsics
rr.log_pinhole(
f"world/camera/image",
"world/camera/image",
child_from_parent=intrinsics,
width=camera.width,
height=camera.height,
)

rr.log_image_file(f"world/camera/image/rgb", dataset_path / "images" / image.name)

rr.log_points(f"world/camera/image/keypoints", image.xys)
rr.log_points(f"world/camera/image/keypoints", visible_xys, colors=point_colors)


def main() -> None:
Expand Down
5 changes: 2 additions & 3 deletions rerun_py/rerun/log/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,9 @@ def log_points(
keypoint_ids = _normalize_ids(keypoint_ids)

identifiers_np = np.array((), dtype="int64")
if identifiers:
if identifiers is not None:
try:
identifiers = [int(id) for id in identifiers]
identifiers_np = np.array(identifiers, dtype="int64")
identifiers_np = np.require(identifiers, dtype="int64")
nikolausWest marked this conversation as resolved.
Show resolved Hide resolved
except ValueError:
_send_warning("Only integer identifies supported", 1)

Expand Down