code: def generate_depth_map(
      calib_dir, velo_filename, cam=2, vel_depth=False
  ):
      """Generate a depth map from velodyne data"""
      # pylint: disable=unsupported-assignment-operation
      # load calibration files
      cam2cam = read_calib_file(
          os.path.join(calib_dir, "calib_cam_to_cam.txt")
      )
      velo2cam = read_calib_file(
          os.path.join(calib_dir, "calib_velo_to_cam.txt")
      )
      velo2cam = np.hstack(
          (velo2cam["R"].reshape(3, 3), velo2cam["T"][..., np.newaxis])
      )
      velo2cam = np.vstack((velo2cam, np.array([0, 0, 0, 1.0])))
  
      # get image shape
      im_shape = cam2cam["S_rect_02"][::-1].astype(np.int32)
  
      # compute projection matrix velodyne->image plane
      R_cam2rect = np.eye(4)
      R_cam2rect[:3, :3] = cam2cam["R_rect_00"].reshape(3, 3)
      P_rect = cam2cam["P_rect_0" + str(cam)].reshape(3, 4)
      P_velo2im = np.dot(np.dot(P_rect, R_cam2rect), velo2cam)
  
      # load velodyne points and remove all behind image plane (approximation)
      # each row of the velodyne data is forward, left, up, reflectance
      velo = load_velodyne_points(velo_filename)
      velo = velo[velo[:, 0] >= 0, :]
  
      # project the points to the camera
      velo_pts_im = np.dot(P_velo2im, velo.T).T
      velo_pts_im[:, :2] = (
          velo_pts_im[:, :2] / velo_pts_im[:, 2][..., np.newaxis]
      )
  
      if vel_depth:
          velo_pts_im[:, 2] = velo[:, 0]
  
      # check if in bounds
      # use minus 1 to get the exact same value as KITTI matlab code
      velo_pts_im[:, 0] = np.round(velo_pts_im[:, 0]) - 1
      velo_pts_im[:, 1] = np.round(velo_pts_im[:, 1]) - 1
      val_inds = (velo_pts_im[:, 0] >= 0) & (velo_pts_im[:, 1] >= 0)
      val_inds = (
          val_inds
          & (velo_pts_im[:, 0] < im_shape[1])
          & (velo_pts_im[:, 1] < im_shape[0])
      )
      velo_pts_im = velo_pts_im[val_inds, :]
  
      # project to image
      depth = np.zeros((im_shape[:2]))
      depth[
          velo_pts_im[:, 1].astype(np.int),
          velo_pts_im[:, 0].astype(np.int),
      ] = velo_pts_im[:, 2]
  
      # find the duplicate points and choose the closest depth
      inds = sub2ind(depth.shape, velo_pts_im[:, 1], velo_pts_im[:, 0])
      dupe_inds = [
          item for item, count in Counter(inds).items() if count > 1
      ]
      for dd in dupe_inds:
          pts = np.where(inds == dd)[0]
          x_loc = int(velo_pts_im[pts[0], 0])
          y_loc = int(velo_pts_im[pts[0], 1])
          depth[y_loc, x_loc] = velo_pts_im[pts, 2].min()
      depth[depth < 0] = 0
  
      return depth
  
file_path: gluon-cv/gluoncv/data/kitti/kitti_utils.py
imports: from __future__ import absolute_import, division, print_function
  import os
  from collections import Counter
  import numpy
  import mxnet
label_desc: Use image node_id 4 for calling a global function with example usage: generate_depth_map(calib_dir, velo_filename, cam, vel_depth) and returns: depth