3D World Coordinates

Custom Object Detection using Ros2 wrapper
Let’s talk about getting 3D world coordinates. I have bounding box coordinates and the depth information of that point. This means I have (u,v) and Z . Using camera info of the zed image compressed from which I have taken (u,v) .I am getting the values of X,Y negatives sometimes ? If this is correct or there is something wrong with my code ? How can I check the values are right ?

# Function to convert image coordinates and depth to 3D world coordinates
def image_depth_to_world(x, y, depth, camera_info):
    # Extract camera parameters from CameraInfo
    fx = camera_info.K[0]
    fy = camera_info.K[4]
    cx = camera_info.K[2]
    cy = camera_info.K[5]

    # Calculate 3D world coordinates
    Z = depth
    X = (x - cx) * Z / fx
    Y = (y - cy) * Z / fy

    return X, Y, Z

Hi @Akshay,

That looks good to me!
I understand from this code that it gives you 3D coordinates in the camera’s reference frame. The camera itself is the origin, so the (0,0,Z) points are in the center of the image (well, at (cx, cy)).
It’s normal to have negative values as well as positive ones.

To check them, you could print them and compare them to ground truth data, or display them like we do with our Python samples for example.

Thanks for the information @Myzhar .
Selecting a Coordinate System
The ZED uses a three-dimensional cartesian coordinate system (X, Y, Z) to specify positions and orientations. The coordinate system can be either right-handed or left-handed. By default, the ZED uses an image coordinate system that is right-handed with the positive Y-axis pointing down, X-axis pointing right and Z-axis pointing away from the camera. Is this correct ?
How can I use these (X,Y,Z) to get the point again on the image so compare with the ground truth ?


Yes this is correct. You can find all the information here: https://www.stereolabs.com/docs/positional-tracking/coordinate-frames

You can convert 3D data to 2D and vice versa using the formula described here: https://support.stereolabs.com/hc/en-us/articles/4554115218711-How-can-I-convert-3D-world-coordinates-to-2D-image-coordinates-and-viceversa-

Best regards,

R&D Engineer
Stereolabs Support