fix: pre-set camera aperture on USD prim before Camera init
Camera.__init__() checks aperture consistency against resolution before we can call set_horizontal_aperture(). Pre-set the aperture values directly on the USD prim via UsdGeom.Camera API to eliminate the mismatch warnings. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -32,16 +32,7 @@ class CustomCamera(Camera):
|
|||||||
reference_path: Reference prim path for camera mounting
|
reference_path: Reference prim path for camera mounting
|
||||||
name: Camera name
|
name: Camera name
|
||||||
"""
|
"""
|
||||||
# ===== Initialize camera =====
|
# ===== Pre-compute camera parameters =====
|
||||||
super().__init__(
|
|
||||||
prim_path=prim_path,
|
|
||||||
name=name,
|
|
||||||
resolution=(cfg["params"]["resolution_width"], cfg["params"]["resolution_height"]),
|
|
||||||
*args,
|
|
||||||
**kwargs,
|
|
||||||
)
|
|
||||||
|
|
||||||
# ===== From cfg =====
|
|
||||||
pixel_size = cfg["params"].get("pixel_size")
|
pixel_size = cfg["params"].get("pixel_size")
|
||||||
f_number = cfg["params"].get("f_number")
|
f_number = cfg["params"].get("f_number")
|
||||||
focus_distance = cfg["params"].get("focus_distance")
|
focus_distance = cfg["params"].get("focus_distance")
|
||||||
@@ -50,18 +41,38 @@ class CustomCamera(Camera):
|
|||||||
height = cfg["params"].get("resolution_height")
|
height = cfg["params"].get("resolution_height")
|
||||||
self.output_mode = cfg.get("output_mode", "rgb")
|
self.output_mode = cfg.get("output_mode", "rgb")
|
||||||
|
|
||||||
# ===== Compute and set camera parameters (before initialize to avoid aperture mismatch warnings) =====
|
horizontal_aperture = pixel_size * 1e-3 * width / 10.0
|
||||||
horizontal_aperture = pixel_size * 1e-3 * width
|
vertical_aperture = pixel_size * 1e-3 * height / 10.0
|
||||||
vertical_aperture = pixel_size * 1e-3 * height
|
|
||||||
focal_length_x = fx * pixel_size * 1e-3
|
focal_length_x = fx * pixel_size * 1e-3
|
||||||
focal_length_y = fy * pixel_size * 1e-3
|
focal_length_y = fy * pixel_size * 1e-3
|
||||||
focal_length = (focal_length_x + focal_length_y) / 2
|
focal_length = (focal_length_x + focal_length_y) / 2 / 10.0
|
||||||
|
|
||||||
self.set_focal_length(focal_length / 10.0)
|
# Pre-set aperture on USD prim before Camera.__init__ to avoid mismatch warnings
|
||||||
|
from pxr import UsdGeom
|
||||||
|
import omni.usd
|
||||||
|
stage = omni.usd.get_context().get_stage()
|
||||||
|
cam_prim = stage.GetPrimAtPath(prim_path)
|
||||||
|
if cam_prim.IsValid():
|
||||||
|
cam = UsdGeom.Camera(cam_prim)
|
||||||
|
cam.GetHorizontalApertureAttr().Set(horizontal_aperture * 10.0) # USD uses mm
|
||||||
|
cam.GetVerticalApertureAttr().Set(vertical_aperture * 10.0)
|
||||||
|
cam.GetFocalLengthAttr().Set(focal_length * 10.0)
|
||||||
|
|
||||||
|
# ===== Initialize camera =====
|
||||||
|
super().__init__(
|
||||||
|
prim_path=prim_path,
|
||||||
|
name=name,
|
||||||
|
resolution=(width, height),
|
||||||
|
*args,
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
|
# ===== Set camera parameters =====
|
||||||
|
self.set_focal_length(focal_length)
|
||||||
self.set_focus_distance(focus_distance)
|
self.set_focus_distance(focus_distance)
|
||||||
self.set_lens_aperture(f_number * 100.0)
|
self.set_lens_aperture(f_number * 100.0)
|
||||||
self.set_horizontal_aperture(horizontal_aperture / 10.0)
|
self.set_horizontal_aperture(horizontal_aperture)
|
||||||
self.set_vertical_aperture(vertical_aperture / 10.0)
|
self.set_vertical_aperture(vertical_aperture)
|
||||||
self.set_clipping_range(0.05, 1.0e5)
|
self.set_clipping_range(0.05, 1.0e5)
|
||||||
try:
|
try:
|
||||||
self.set_lens_distortion_model("pinhole")
|
self.set_lens_distortion_model("pinhole")
|
||||||
|
|||||||
Reference in New Issue
Block a user