Skip to content

Add CameraRecorder: posed onboard camera sequences - #103

Open
vishwagw wants to merge 6 commits into
jjshoots:masterfrom
vishwagw:camera-recorder
Open

vishwagw wants to merge 6 commits into
jjshoots:masterfrom
vishwagw:camera-recorder

Conversation

@vishwagw

@vishwagw vishwagw commented Nov 19, 2026 •

Copy link
Copy Markdown

What

PyFlyt/core/utils/camera_recorder.py (exported as PyFlyt.core.CameraRecorder) saves a drone's existing Camera as a posed image sequence:

<output_dir>/
    images/000000.png, ...
    depth/000000.npy, ...   (optional, metric z-depth in m)
    poses.csv               timestamp,tx,ty,tz,qx,qy,qz,qw   (camera-to-world, OpenCV camera axes)
    intrinsics.txt          fx fy cx cy
env = Aviary(..., drone_options=dict(use_camera=True))
with CameraRecorder(env, "flight_0", save_depth=True) as rec:
    for i in range(1200):
        env.step()
        if i % 12 == 0:
            rec.capture()

Also: examples/core/11_camera_recording.py, tests/test_camera_recorder.py, and a docs page under Core.

Why

Posed RGB(-D) sequences are the standard input for visual odometry / SLAM evaluation, NeRF / Gaussian splatting and action-conditioned world-model training. This lets PyFlyt produce them directly.

Design notes

  • Uses the drone's own Camera. The pose is recovered by inverting camera.view_mat, so it follows every camera option (gimbal, tilt, position offset, tracking camera) with no duplicated logic. Camera itself is unchanged.
  • Pixel convention. PyBullet's TinyRenderer puts the principal point at (W/2, H/2 - 1) rather than ((W-1)/2, (H-1)/2) (measured). The recorder always renders with ER_TINY_RENDERER, so intrinsics are identical with render=True/False, and the shift is corrected in intrinsics.txt.
  • No new dependencies. PNGs are written with zlib/struct from the standard library.

Tests

tests/test_camera_recorder.py (7 tests):

  • view-matrix ↔ pose and rotation ↔ quaternion round trips;
  • for a default camera, a tilted camera on a rolled/pitched/yawed drone, an offset camera, and a gimballed camera: a sphere at a known world point, projected with the pose and intrinsics re-read from disk, lands on its rendered segmentation centroid within 0.3 px; metric depth matches the sphere's near surface within 1 cm; the gimballed camera keeps a level horizon;
  • a drone without use_camera is rejected; a short flight yields one valid PNG per pose with increasing timestamps.

pytest tests/test_core.py tests/test_camera_recorder.py: 18 passed. black / isort / flake8 / pydocstyle / codespell / pyright (1.1.347) clean on the new files.

Two things I noticed (not changed here, happy to open issues)

  1. In non-gimballed mode, a positive camera_angle_degrees tilts the camera down (optical-axis z-component is −0.342 at +20°), while the Camera docstring describes it as an up-tilt.
  2. In mode 7 the yaw setpoint isn't wrapped against the measured yaw (which is in [−π, π]), so a setpoint that crosses ±π makes the drone spin the long way round. The example works around it by commanding yaw relative to the current yaw.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant