Camera parameter unit conversion from cm to mm

Hi, I am doing some grasp estimation on Issac Sim 2022.2.0 using a camera to retrieve rgb, depth, etc.

I noticed that the depth map was not accurate, and I found that the camera’s parameters has some weird conversions at setting/getting (from cm to mm and vice-versa). It took me a long time to figure this out as there was no instructions inside the functions.

For example, let’s look at the implementation of get_ and set_focal_length() :

    def get_focal_length(self) -> float:
        """
        Returns:
            float: Longer Lens Lengths Narrower FOV, Shorter Lens Lengths Wider FOV
        """
        return self.prim.GetAttribute("focalLength").Get() / 10.0

    def set_focal_length(self, value: float):
        """
        Args:
            value (float): Longer Lens Lengths Narrower FOV, Shorter Lens Lengths Wider FOV
        """
        self.prim.GetAttribute("focalLength").Set(value * 10.0)
        return

This seems that the unit conversion factor should be 10 for the actual prim attributes to work (e.g., 1 cm should be converted to 10 mm, as per set_focal_length()).
According to the camera documentation: https://docs.omniverse.nvidia.com/isaacsim/latest/features/sensors_simulation/isaac_sim_sensors_camera.html?highlight=rational#calibrated-camera-sensors, the unit of input parameter for focal length should be indeed cm (see the division by 10 in line 20 below).

# OpenCV camera matrix and width and height of the camera sensor, from the calibration file
width, height = 1920, 1200
camera_matrix = [[958.8, 0.0, 957.8], [0.0, 956.7, 589.5], [0.0, 0.0, 1.0]]

# Pixel size in microns, aperture and focus distance from the camera sensor specification
# Note: to disable the depth of field effect, set the f_stop to 0.0. This is useful for debugging.
pixel_size = 3 * 1e-3   # in mm, 3 microns is a common pixel size for high resolution cameras
f_stop = 1.8            # f-number, the ratio of the lens focal length to the diameter of the entrance pupil
focus_distance = 0.6    # in meters, the distance from the camera to the object plane

# Calculate the focal length and aperture size from the camera matrix
((fx,_,cx),(_,fy,cy),(_,_,_)) = camera_matrix
horizontal_aperture =  pixel_size * width                   # The aperture size in mm
vertical_aperture =  pixel_size * height
focal_length_x  = fx * pixel_size
focal_length_y  = fy * pixel_size
focal_length = (focal_length_x + focal_length_y) / 2         # The focal length in mm

# Set the camera parameters, note the unit conversion between Isaac Sim sensor and Kit
camera.set_focal_length(focal_length / 10.0)                # Convert from mm to cm (or 1/10th of a world unit)
camera.set_focus_distance(focus_distance)                   # The focus distance in meters
camera.set_lens_aperture(f_stop * 100.0)                    # Convert the f-stop to Isaac Sim units
camera.set_horizontal_aperture(horizontal_aperture / 10.0)  # Convert from mm to cm (or 1/10th of a world unit)
camera.set_vertical_aperture(vertical_aperture / 10.0)

camera.set_clipping_range(0.05, 1.0e5)

Now my question is, since all the internal mechanisms uses mm as unit of measurement, why you are doing all these conversions? Is there any particular reason?

For example, if all the conversions were removed, you can easily call set_focal_length(value_in_mm) to set the focal length in mm. Same applies for apertures.

Also, as a suggestion for the Replicator class’s team, there should be an easier way to get/set the parameters of camera created using Replicator (should Inherit from Camera?).

1 Like

Hi @wenqianglai - Is there any particular reason you are using 2022.2.0?

The latest release is 2023.1.1 which was made available in December mid. Can you try using that? Also, the document that you linked is also for that latest release.

Hello, I believe this question is still relevant, even on 2023.1.1. Bouncing off of wenquianglai, in the second code snippet, if cm is 1/10th of a world unit, does that mean in this example, a dm is a world unit? If so, why is the focus distance in meters (which should be in terms of world units). Also, could you explain why f_stop is multiplied by 100? From what I understand, f_stop is the ratio between focal_length and aperture diameter, so if those two are in terms of the same units, then f_stop should not have to be scaled.