Problems with Depth Map

I am using ZED 2i camera (both 2.1mm and 4mm). I tried to save the depth map but I got alot of 0 values in it. I am using neural_plus mode but still got such results. What could be the potential reasons for such inaccuracies?

I remember when I was taking pictures at 5mtr height so the platform I was on was little wobbly( not so stable). Can this be the reason for such zereos? If there are other reasons please tell. The code with with I am capturing the data is:

import cv2
import pyzed.sl as sl
import math
from datetime import datetime
import os
import numpy as np
from SetupLogger import setup_logging

# Setup logging
logger = setup_logging('ZED_Data_acquisition/camera_application.log')

def create_folder(path):
    try:
        if not os.path.exists(path):
            os.makedirs(path)
            logger.info(f"Created folder: {path}")
        else:
            logger.info(f"Folder already exists: {path}")
    except Exception as e:
        logger.error(f"Failed to create folder: {path}, Error: {e}")

if __name__ == "__main__":
    try:
        
        folder_path="Test_Dataset_08Nov24/Narrow_Angle"
        create_folder(folder_path)

        # Create a Camera object
        cam = sl.Camera()

        # Create an InitParameters object and set configuration parameters
        cam_init_params = sl.InitParameters()
        cam_init_params.camera_resolution = sl.RESOLUTION.HD2K  
        cam_init_params.camera_fps = 15
        # Depth Modes Available: NEURAL_PLUS (latest 4.1 SDK),  NEURAL, ULTRA, QUALITY, PERFORMANCE(default)
        cam_init_params.depth_mode = sl.DEPTH_MODE.NEURAL_PLUS
        cam_init_params.depth_stabilization = 100 # It is True by default and stablizes the image 
        cam_init_params.coordinate_units = sl.UNIT.MILLIMETER
        cam_init_params.depth_minimum_distance = 600 # min possible 15 cm/ 150 mm/ 0.15 mtrs   - Set to 60cm
        cam_init_params.depth_maximum_distance = 35000 # Setting maximum depth perception distance to 35m

        # Open the camera
        status = cam.open(cam_init_params)
        if status != sl.ERROR_CODE.SUCCESS:
            logger.error(f"Failed to open camera: {status}")
            raise Exception(f"Failed to open camera: {status}")

        # Set the selected sensor for retrieving the image: from the left sensor
        view = sl.VIEW.LEFT
        measure_depth = sl.MEASURE.DEPTH
        cam_runtime_parameters = sl.RuntimeParameters()

        logger.info("Stream View. Press 's' to save image and cloud points")
        logger.info("Stream View. Press 'q' to exit")
        frame_time_ms = int(1000 / 30)

        while True:
            try:
                zed_image = sl.Mat()
                zed_point_cloud = sl.Mat()
                zed_depth_map = sl.Mat()

                if cam.grab(cam_runtime_parameters) == sl.ERROR_CODE.SUCCESS:
                    cam.retrieve_image(zed_image, view)
                    cam.retrieve_measure(zed_point_cloud, point_cloud_mode)
                    cam.retrieve_measure(zed_depth_map, measure_depth)

                    image = zed_image.get_data()
                    points_cloud = zed_point_cloud.get_data()
                    depth = zed_depth_map.get_data()

                    x = int(zed_image.get_width() / 2)
                    y = int(zed_image.get_height() / 2)
                    cv2.circle(image, (x, y), 5, (0, 255, 0), thickness=1)
                    cv2.imshow("Image1", image)

                key = cv2.waitKey(5)

                if key == ord('s'):
                    file_name = datetime.now().strftime("%Y%m%d_%H%M%S")
                    cv2.imwrite(folder_path + file_name + ".png", image)
                    zed_depth_map.write(folder_path + file_name + ".pgm")
                    logger.info(f"Saved Image and Depth Map as {file_name}")

                if key == ord('q'):
                    break
            except Exception as e:
                logger.error(f"Runtime error: {e}")

    except Exception as e:
        logger.critical(f"Critical error in main: {e}")
    finally:
        status = cam.close()
        logger.info(f"Camera closed with status: {status}")

Hi @aakashgoyal,

Depending on the parameters used and the situation, the depth map is not always full of values, and when this is the case, the default value when there is no information is 0.

Values of zero can happen in the following cases: