Depth Map correctness

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

image_depth_map = cv2.imread(depth_map_path, -1)

# 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 using the function to get the actual length of the edges.

def distance_between_points(p1, p2):
     p1 = np.array(p1)
     p2 = np.array(p2)
     distance = np.linalg.norm(p1 - p2)
     return distance

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? Please guide.
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?
Please guide.

Hi @aakashgoyal,

To validate that there are saving issues, you can set the camera in front of an object of known distance, and validate that the pixels depth map provides the correct values, using a pgm file reader.

To validate if the loading with opencv is correct, you can display the image in matplotlib for example and display the pixel values.

There is no need to perform lens distortion as this is performed by the ZED SDK using the intrinsic parameters of the factory calibration.