# Accurate Surface Area Calculation with ZED 2i Stereo Camera

Hello,

I am trying to find the length of the edges of the tables as shown in the image:

I have saved the depth map using the below code:

``````cam_init_params.depth_mode = sl.DEPTH_MODE.NEURAL
zed_depth_map= sl.Mat()
if cam.grab(cam_runtime_parameters) == sl.ERROR_CODE.SUCCESS:
cam.retrieve_measure(zed_depth_map, measure_depth)

if key == ord('s'):
zed_depth_map.write(folder_path+file_name+".pgm")
``````

Now, i am trying to read the depth value on the respective coordinates as shown in the marked segmented image and converting these coordinates into 3-d world coordinates with the code:

``````# Extract the intrinsic parameters for 2K resolution : Hard coded for the time being
fx = 1929.147094
fy = 1929.14709472
cx = 1131.6126
cy = 605.3469

# rectangle_points all the 4 fours coordinates
X = [((u - cx) * image_depth_map[v, u]) / fx for u, v in rectangle_points]
Y = [((v - cy) * image_depth_map[v, u]) / fy for u, v in rectangle_points]
Z = [image_depth_map[v, u] for u, v in rectangle_points]
``````

and later I am calculating euclidean distance to get the actual length of the edges.

The above mask image is the ground truth mask image and I am trying to calculate its area just to be sure that original mask have accurate measurements. But, my length of edges are not correct and they suffer error in the range of 2% -30% ? Why so?

Is it possible that depth map is not accurate?
Is there any issue in the saving depth map, reading depth map, format of depth map or any other issue?
Do I need to correct the depth map for lens distortion using the camera parameters?

Any solution or guidance @mattrouss ?

Any solution or guidance @mattrouss @Myzhar ?