【python代码】Kittle数据集的ground truth生成深度图攻略|彩色深度图|代码无恼运行

 目录

1.明确KITTLE数据集特性

2.选择groundtruth

3.转换深度图

4.转换彩色深度图


1.明确KITTLE数据集特性

KITTI数据集包含了来自车载传感器的多模态数据,包括激光雷达、摄像头和GPS/惯性测量单元(IMU)等。该数据集主要采集于城市环境中,涵盖了驾驶场景中的各种复杂情况,如城市街道、高速公路和乡村道路等。

2.选择groundtruth

选择KITTLE数据集中的proj_depth/groundtruth,选择需要的grouth truth。(细看懂的都懂)

3.转换深度图

 代码可直接执行:

  • 加载图像,将其转换为NumPy数组,并除以256。
  • 获取有效像素点的位置(xy)。
  • 获取有效像素点的深度值。
  • 生成一个大小为N×3的数组。

  • Load image, convert to numpy array and divide by 256
  • Get location (xy) for valid pixeles
  • Get depth values for valid pixeles
  • Generate an array Nx3
import PIL.Image as Image
from scipy.interpolate import LinearNDInterpolator
import numpy as np
import cv2

# 稀疏-插值-稠密
def lin_interp(shape, xyd):
    # taken from https://github.com/hunse/kitti
    m, n = shape
    ij, d = xyd[:, 1::-1], xyd[:, 2]
    f = LinearNDInterpolator(ij, d, fill_value=0)
    J, I = np.meshgrid(np.arange(n), np.arange(m))
    IJ = np.vstack([I.flatten(), J.flatten()]).T
    disparity = f(IJ).reshape(shape)
    return disparity

image_path = "groundtruth.png"
# Load image, convert to numpy array and divide by 256
depth_map = np.asarray(Image.open(image_path)) / 256
#  Get location (xy) for valid pixeles
x, y = np.where(depth_map > 0)
# Get depth values for valid pixeles
d = depth_map[depth_map != 0]
# Generate an array Nx3,
# x, y may swap(交换)
xyd = np.stack((y,x,d)).T
gt = lin_interp(depth_map.shape, xyd)
cv2.imwrite("groundtruth_depth.png", gt)

4.转换彩色深度图

  •  这里的颜色选择为:hot,可自行修改
  • 也实现对图像做了normalize,使得映射规范,可自行考虑!
import numpy as np
import PIL.Image as pil
import matplotlib as mpl
import matplotlib.cm as cm
import os
from tqdm import tqdm
from PIL import Image

img= np.asarray(Image.open('depth.png'), dtype='float32')
img[img==0]=img.max()
normalizer = mpl.colors.Normalize(vmin=img.min(), vmax=img.max())
mapper = cm.ScalarMappable(norm=normalizer, cmap='hot')
colormapped_im = (mapper.to_rgba(img)[:, :, :3] *255).astype(np.uint8)
save_path = os.path.join("color" + ".png")
pil.fromarray(colormapped_im).save(save_path)

正常记录,欢迎交流~

猜你喜欢

转载自blog.csdn.net/MengYa_Dream/article/details/130978085
今日推荐