本笔记翻译于Carla官方文档
设置高级传感器
脚本tutorial_replay.py包含了更多传感器的定义。它们的工作原理和基本的一样,但理解起来可能有点难。
深度相机
深度相机生成场景的图片,在灰度深度图中映射每个像素。然而,输出并不简单。相机的深度缓冲器使用RGB颜色空间进行映射。为了便于理解,必须将其转换为灰度。为了做到这一点,简单地保存图像与RGB相机,但应用carla.ColorConverter。深度相机有两种转换:
Carla.ColorConverter.Depth 以毫米精度转换原始深度
Carla.ColorConverter.LogarithmicDepth 同样也是毫米粒度,在近距离时能提供更好的结果,但是在较远的距离的时候表现没有以上的好
深度相机的属性只设置了之前在RGB相机中声明的元素:fov, image_size_x, image_size_y和sensor_tick。脚本将这个传感器设置为与之前使用的RGB相机匹配。
depth_cam = None
depth_bp = world.get_blueprint_library().find(‘sensor.camera.depth’)
depth_location = carla.Location(2,0,1)
depth_rotation = carla.Rotation(0,180,0)
depth_transform = carla.Transform(depth_location,depth_rotation)
depth_cam = world.spawn_actor(depth_bp,depth_transform,attach_to=ego_vehicle, attachment_type=carla.AttachmentType.Rigid)
depth_cam.listen(lambda ima