How to calculate distance_from_center using zed2i ros2 object centroid position


I have a AGX orin + ZED2i + ros2 setup.

I’m subscribing to this topic /zed2i/zed_node/body_trk/skeletons. And I’m trying to calculate the distance between body centroid position and camera view center, see Python code below:
(obj_x and obj_z if from position array: position[0], position[2])

def calculate_camera_width(obj_depth):
    HFOV_deg = 104 # HD720P
    HFOV_rad = math.radians(HFOV_deg)

    # Calculate the width at the specified depth
    camera_width = 2 * obj_depth * math.tan(HFOV_rad / 2)

    return abs(camera_width)

distance_from_center = obj_x - calculate_camera_width(obj_z) / 2

However the obj_x seems much bigger than camera_width at specific depth. Can you spot anything I’m doing wrong?



Have you checked that the values you get for position are changing as you would expect? While the default coordinate frame uses Z as depth, I believe that most messages are converted into the ROS frame which uses X as depth instead.

I’m not an expert but its something worth checking. Besides that, your calculations look sound to me so I can’t be of much more help.

hi, thank you for the reply.

I can see ROS is indeed using a different coord frames
Right handed, z-up, x-forward (ROS)

I’ll test it out.