Accurate distance measurement at high speed.

Hi Team,
We are building a product for Indian Government. We have purchased Zed2i Camera. We are trying to measure distance of pole from moving vehicle. Zed2i is placed on a moving vehicle. We are using object detection model to first detect pole and we are doing great at it. We are getting perfect bounding boxes for poles. Here are the setting we are using for Depth:

zed = sl.Camera()
    zed.set_camera_settings(sl.VIDEO_SETTINGS.EXPOSURE, -1)
    zed.set_camera_settings(sl.VIDEO_SETTINGS.GAIN, -1)
    init_params = sl.InitParameters(
                depth_mode=sl.DEPTH_MODE.ULTRA,
                coordinate_units=sl.UNIT.INCH,
                camera_resolution=sl.RESOLUTION.HD1080,
                camera_fps=30,
                depth_maximum_distance=780,
                depth_minimum_distance=8,
                depth_stabilization = 1
    )
    init_params.camera_resolution = sl.RESOLUTION.HD1080
    init_params.camera_fps = 30

We are getting distance error in the range 3 to 4 inches always. Weather is sunny and objects is perfectly visible.
Here is how we are getting depth values from bounding box:

 def get_depth_values_in_roi(self, x1, y1, x2, y2):
        with self.device:
            
            depth_array = cp.array(self.depth)

            roi_depth_values = depth_array[y1:y2, x1:x2]

            valid_mask = (roi_depth_values > 0) & (roi_depth_values < self.MAX_DETECTION_DISTANCE)
            valid_depth_values = roi_depth_values[valid_mask]

            return valid_depth_values

We are taking median of those valid depth values to get final distance number:

    def process_depth_values(self, depth_values):
        if len(depth_values) == 0:
            return float('inf')  # Return a large value if no valid depths are found
        return float(cp.median(depth_values))

I am attaching image containing target object.


Please suggest:

  1. Best settings to measure depth correctly. Contraint here is I need to use 30FPS atleast. Might even switch to 60 FPS at 720 due to vehicle speed.
  2. Also, methods to get only target object depths only. Can not use segmentation models here due to system limitation.

Hi @BrainyAI,

Welcome to the forums ! :wave: Thank you for reaching out.

Regarding the parameters to use, I can recommend:

  • using depth_mode = sl.DEPTH_MODE.NEURAL
  • using confidence_threshold at a lower value than the default (95) from the RuntimeParameters. You can try the impact of this parameter in ZED_Depth_Viewer.

For retrieving a single depth for each detected object, I can recommend using our Custom Object Detection module, which seems to align with your use case: Using the Object Detection API with a Custom Detector - Stereolabs