Repository navigation
Add native OpenCV lens-distortion cameras for OVRTX - #6608
kellyguo11 merged 19 commits into
Conversation
Add OpenCvPinholeDistortionCfg and OpenCvFisheyeDistortionCfg and a distortion field on PinholeCameraCfg so a real camera calibration (fx/fy/cx/cy plus distortion coefficients) can be reproduced in sim. The model is authored at spawn as the omni:lensdistortion USD API, which the RTX/OVRTX renderer honors natively. Make the intrinsics readback distortion-aware so camera.data.intrinsic_matrices reflects a non-square or off-center calibration instead of assuming fx == fy and a centered principal point. The Newton renderer does not yet apply the model and is left as a documented no-op with a warning.
Propagate OpenCvDistortionCfg, OpenCvPinholeDistortionCfg and OpenCvFisheyeDistortionCfg through the isaaclab.sim.spawners and isaaclab.sim lazy-export stubs, so they are importable as isaaclab.sim.<Cfg> like the sibling PinholeCameraCfg and FisheyeCameraCfg.
| f_x = float(raw_prim.GetAttribute(f"{prefix}:fx").Get()) | ||
| f_y = float(raw_prim.GetAttribute(f"{prefix}:fy").Get()) | ||
| c_x = float(raw_prim.GetAttribute(f"{prefix}:cx").Get()) | ||
| c_y = float(raw_prim.GetAttribute(f"{prefix}:cy").Get()) |
There was a problem hiding this comment.
Unguarded
None from missing distortion intrinsic attrs
GetAttribute(...).Get() returns None when the attribute is not authored on the prim; float(None) then raises TypeError on every subsequent update step. The imageSize read two lines below is already None-checked, but fx/fy/cx/cy are not. A USD scene that carries omni:lensdistortion:model without the matching intrinsic attributes (e.g., a hand-authored prim or a third-party export that only writes the schema token) will crash the camera sensor continuously from the first update call.
| if not self._warned_distortion_image_size: | ||
| logger.warning( | ||
| "Camera lens-distortion 'imageSize' %s does not match the render resolution" | ||
| " (%d, %d). The reported intrinsic matrix is in the calibrated pixel space.", | ||
| (int(image_size[0]), int(image_size[1])), | ||
| width, | ||
| height, | ||
| ) | ||
| self._warned_distortion_image_size = True |
There was a problem hiding this comment.
Single warning flag covers all N environment cameras
_warned_distortion_image_size is a per-Camera-instance flag, but one Camera object manages N sensor prims (one per environment). Once any single env's prim triggers the warning, the flag is set and all subsequent per-prim mismatches in the same instance — including those in different environments with different calibration sizes — are silently dropped. In a large multi-env setup a user would see one warning and have no indication that the mismatch also affects all other envs. Consider including the env index in the message, or emitting the warning per prim the first time it fires.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Fall back to the focal-length/aperture projection when a camera prim carries the omni:lensdistortion:model token without the fx/fy/cx/cy intrinsics, instead of dereferencing a None attribute value on every update step and raising TypeError continuously. Key the image-size mismatch warning on the authored size and include the prim path and environment index, so a genuinely different calibration in another environment is surfaced rather than masked by the first prim's one-time flag. Add regression tests covering the missing-intrinsics fallback and the per-size warning behavior.
|
greptile issues rexsolved |
Extract the authored OpenCV lens-distortion readback out of the per-camera loop in Camera._update_intrinsic_matrices into a dedicated _read_authored_opencv_intrinsics helper. The loop body drops from four levels of nesting to a single authored-vs-fallback branch, keeping the warn-once guards and behavior unchanged. Also refresh the method docstring, which still claimed intrinsics always assume square pixels, and tidy the warning-guard comment.
The distortion field is defined on PinholeCameraCfg and inherited by FisheyeCameraCfg, the two cfg types spawn_camera accepts, so the defensive getattr lookup is unnecessary and inconsistent with the direct attribute access used elsewhere in the function.
The kit-less test_opencv_distortion.py carried only a skipif and no level marker, unlike every sibling in test/sensors/ (kit-less unit tests use pytest.mark.unit). Without the level marker the file is not categorized as a unit test in the JUnit report nor selected by '-m unit', so CI's unit lane skips it. Add pytest.mark.unit to the module-level pytestmark to match the convention.
The (height, width) viewport read is constant across the per-env loop in _update_intrinsic_matrices; compute it once before the loop rather than on every iteration.
Describe the Camera.data intrinsics change in the changelog without cross-referencing a private method. Add reciprocal See Also notes between FisheyeCameraCfg and OpenCvFisheyeDistortionCfg, and mention the optional OpenCV calibration in the sensors spawner module docstring. Broaden the Newton renderer warning to state that a non-square fx, the principal point, and the distortion coefficients are all dropped (Newton derives one field of view from fy), not only the distortion.
A camera with an authored OpenCV lens-distortion model owns its fx/fy/cx/cy through the omni:lensdistortion:* calibration, which the readback prefers; set_intrinsic_matrices only writes the square-pixel, centered focal-length/ aperture attributes and cannot express it. Skip such cameras per entry (with a warning) and leave their calibration untouched, while still updating any ordinary cameras selected in the same call. Regression-tested with a mixed distortion/plain batch.
Render the OpenCV fisheye model and an undistorted pinhole through OVRTX and assert the frames differ well beyond render noise, guarding that the renderer honors the OmniLensDistortionOpenCvFisheyeAPI schema.
…orin/opencv-lens-distortion-cameras
|
Nice work — the RTX/OVRTX authoring path here is a reasonable way to get calibrated OpenCV cameras rendering natively, and the renderer-agnostic cfg is the right shape. One thought for the roadmap: we'd likely want lens distortion supported in Newton directly too, not only on the RTX side, so a calibrated camera behaves the same across backends. To see what that looks like, I prototyped the Newton consumption path as a stacked follow-up — Newton's tiled camera traces an explicit per-pixel ray field, so the distortion can be applied at ray-generation time (inverting the OpenCV forward model per pixel) with no Newton-package change:
The Isaac Lab-side implementation works and is GPU-validated today; longer term a native Newton API (per-camera intrinsics + distortion, or a distortion-aware ray util) would be the cleaner home for it. |
StafaH
left a comment
There was a problem hiding this comment.
LGTM, let's implement the newton path as well and get parity?
| intrinsics = tuple(prim.GetAttribute(f"{prefix}:{name}").Get() for name in ("fx", "fy", "cx", "cy")) | ||
| if None in intrinsics: | ||
| # a model token without intrinsics falls back to the focal-length/aperture projection | ||
| if not self._warned_distortion_missing_intrinsics: |
There was a problem hiding this comment.
Why do we need to supress repeated warning? Are there truly going to be that many?
Even if there are, let's not create new variables like this, it could easily be inlined:
require_warning=False
do some loop:
return warning=True
if require_warning:
warn
But even that might not be necessary if there are not that many warnings, so either or
There was a problem hiding this comment.
For now removed the suppression
| if image_size is not None: | ||
| authored_size = (int(image_size[0]), int(image_size[1])) | ||
| if authored_size != (width, height) and authored_size not in self._warned_distortion_image_sizes: | ||
| logger.warning( |
There was a problem hiding this comment.
Similar comment about the warn guard
…v-lens-distortion-cameras # Conflicts: # source/isaaclab_newton/isaaclab_newton/renderers/newton_warp_renderer.py
The intrinsics readback suppressed its two warnings, for a distortion model missing fx/fy/cx/cy and for an authored image size that differs from the render resolution, through attributes that lived for the lifetime of the sensor. Logging bookkeeping does not belong in per-camera state, and the readback runs only from _create_buffers() and set_intrinsic_matrices() rather than per step, so the warnings cannot repeat every frame. Let each offending prim warn instead. The test that asserted on the removed set now reads the emitted log messages. Addresses review feedback on isaac-sim#6608.
## Description Isaac Lab's stock camera cfgs (PinholeCameraCfg, FisheyeCameraCfg) can only express a focal-length + aperture projection. They cannot represent an OpenCV fx/fy/cx/cy + distortion-coefficient intrinsic model — the format real-camera and LeRobot calibrations come in — so a calibrated real camera (non-square pixels, off-center principal point, lens distortion) cannot be reproduced in simulation. ## This PR adds first-class support for OpenCV lens-distortion cameras, rendered natively through the RTX/OVRTX renderer: - Config: new OpenCvDistortionCfg base with OpenCvPinholeDistortionCfg (k1..k6, p1, p2, s1..s4) and OpenCvFisheyeDistortionCfg (k1..k4) sub-configs, plus a distortion field on PinholeCameraCfg. The model is renderer-agnostic — it lives on the camera cfg, and each renderer decides how to consume it. - Authoring: spawn_camera authors the model on the camera prim as the omni:lensdistortion:* USD API (schema + model token + fx/fy/cx/cy + imageSize + coefficients). OVRTX honors this natively — no renderer-package change is required. - Intrinsics readback: Camera._update_intrinsic_matrices now reads the authored fx/fy/cx/cy when a distortion model is present, so camera.data.intrinsic_matrices reflects a real calibration instead of assuming fx == fy and a centered principal point. - Scope: the RTX/OVRTX path is implemented. The Newton distortion path is intentionally out of scope; it is left as a documented no-op that logs a warning and renders undistorted, and the cfg is designed so Newton can consume the same model later. This upstreams a capability that has been proven out-of-tree in the SO-101 sim-to-real workshop; once merged, that workshop can delete its private OpenCV-pinhole spawner and use these APIs directly. ## Dependencies: none (no new required or optional dependencies). ## Fixes # (N/A — new feature) ## Type of change - New feature (non-breaking change which adds functionality) ## Screenshots ## Rendering the grid-textured ground plane - Coefficients exaggerated (--k_scale 15) for visibility. <img width="1665" height="554" alt="Screenshot 2026-07-19 135849" src="https://github.com/user-attachments/assets/1139d5b9-429d-47b7-9870-a6396ef32127" /> ## Checklist - [x] I have read and understood the contr (https://isaac-sim.github.io/IsaacLab/mainl) - [x] I have run the pre-commit checks (ht/isaaclab.sh --format - [x] I have made corresponding changes to - [x] My changes generate no new warnings - [x] I have added tests that prove my fixure works - [x] I have updated the changelog and the extension's config/extension.toml file - [x] I have added my name to the CONTRIBUists there --------- Co-authored-by: Kelly Guo <[email protected]>
## Description PR #6608 introduced renderer-agnostic OpenCV camera calibration configs and native RTX/OVRTX rendering. The Newton path was intentionally left as a documented no-op that emitted a warning and rendered using a centered, square-pixel pinhole projection. This PR completes backend parity by making `NewtonWarpRenderer` consume the same OpenCV calibration and generate distorted per-pixel camera rays. ## This PR adds native OpenCV lens-distortion rendering to Newton: - **OpenCV pinhole:** Adds a Warp kernel that inverts the OpenCV forward model per pixel using fixed-point iteration. It supports rational radial (`k1..k6`), tangential (`p1`, `p2`), and thin-prism (`s1..s4`) distortion - conritbuted by @AntoineRichard in liorbenhorin#1 - **OpenCV fisheye:** Uses Newton’s native `compute_camera_rays_fisheye_opencv` helper rather than maintaining a duplicate Isaac Lab implementation. - **Calibrated intrinsics:** Both paths honor `fx/fy/cx/cy`, including non-square focal lengths and an off-center principal point. - **Disabled distortion:** `apply_lens_distortion=False` mutes the coefficients while retaining the calibrated intrinsics, matching RTX/OVRTX behavior. - **Renderer behavior:** Replaces the previous Newton warning/no-op path with distortion-aware ray generation. - **Tests:** Adds CPU unit tests for pinhole ray generation and CUDA integration tests for pinhole rendering, fisheye rendering, and intrinsic-matrix readback. This is a stacked follow-up to #6608. It does not change the public camera configuration or USD authoring path introduced there; it only adds Newton renderer consumption of the existing model. ## Release backport - [x] <!-- backport-active-release --> Backport this pull request to the active release branch after it merges into `develop` ## Images <img width="1920" height="2146" alt="image222" src="https://github.com/user-attachments/assets/57764c1a-3be9-4c75-8609-62534834a465" /> ## Checklist - [x] I have read and understood the [contribution guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html) - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have added a changelog fragment under `source/<pkg>/changelog.d/` for every touched package (do **not** edit `CHANGELOG.rst` or bump `extension.toml` — CI handles that) - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there --------- Co-authored-by: Kelly Guo <[email protected]> Co-authored-by: Mustafa H <[email protected]>
## Description PR #6608 introduced renderer-agnostic OpenCV camera calibration configs and native RTX/OVRTX rendering. The Newton path was intentionally left as a documented no-op that emitted a warning and rendered using a centered, square-pixel pinhole projection. This PR completes backend parity by making `NewtonWarpRenderer` consume the same OpenCV calibration and generate distorted per-pixel camera rays. ## This PR adds native OpenCV lens-distortion rendering to Newton: - **OpenCV pinhole:** Adds a Warp kernel that inverts the OpenCV forward model per pixel using fixed-point iteration. It supports rational radial (`k1..k6`), tangential (`p1`, `p2`), and thin-prism (`s1..s4`) distortion - conritbuted by @AntoineRichard in liorbenhorin#1 - **OpenCV fisheye:** Uses Newton’s native `compute_camera_rays_fisheye_opencv` helper rather than maintaining a duplicate Isaac Lab implementation. - **Calibrated intrinsics:** Both paths honor `fx/fy/cx/cy`, including non-square focal lengths and an off-center principal point. - **Disabled distortion:** `apply_lens_distortion=False` mutes the coefficients while retaining the calibrated intrinsics, matching RTX/OVRTX behavior. - **Renderer behavior:** Replaces the previous Newton warning/no-op path with distortion-aware ray generation. - **Tests:** Adds CPU unit tests for pinhole ray generation and CUDA integration tests for pinhole rendering, fisheye rendering, and intrinsic-matrix readback. This is a stacked follow-up to #6608. It does not change the public camera configuration or USD authoring path introduced there; it only adds Newton renderer consumption of the existing model. ## Release backport - [x] <!-- backport-active-release --> Backport this pull request to the active release branch after it merges into `develop` ## Images <img width="1920" height="2146" alt="image222" src="https://github.com/user-attachments/assets/57764c1a-3be9-4c75-8609-62534834a465" /> ## Checklist - [x] I have read and understood the [contribution guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html) - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have added a changelog fragment under `source/<pkg>/changelog.d/` for every touched package (do **not** edit `CHANGELOG.rst` or bump `extension.toml` — CI handles that) - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there --------- Co-authored-by: Kelly Guo <[email protected]> Co-authored-by: Mustafa H <[email protected]> (cherry picked from commit a68caff)
Description
Isaac Lab's stock camera cfgs (PinholeCameraCfg, FisheyeCameraCfg) can only express a focal-length + aperture projection. They cannot represent an OpenCV fx/fy/cx/cy + distortion-coefficient intrinsic model — the format real-camera and LeRobot calibrations come in — so a calibrated real camera (non-square pixels, off-center principal point, lens distortion) cannot be reproduced in simulation.
This PR adds first-class support for OpenCV lens-distortion cameras, rendered natively through the RTX/OVRTX renderer:
This upstreams a capability that has been proven out-of-tree in the SO-101 sim-to-real workshop; once merged, that workshop can delete its private OpenCV-pinhole spawner and use these APIs directly.
Dependencies: none (no new required or optional dependencies).
Fixes # (N/A — new feature)
Type of change
Screenshots
Rendering the grid-textured ground plane - Coefficients exaggerated (--k_scale 15) for visibility.
Checklist
(https://isaac-sim.github.io/IsaacLab/mainl)