carla 传感器
一、Blueprints和Actor之间的关系
Blueprints是carla生成Actor的模板,Actor包括Sensors\Spectator\Traffic signs and traffic lights\Vehicles\Walkers
Actor的操作包括生成、设置、销毁三种
#确定车辆模板 blueprint_library = world.get_blueprint_library() vehicle_bp = random.choice(blueprint_library.filter('vehicle.*.*')) #从地图中获得Actor的生成点 spawn_points = world.get_map().get_spawn_points() spawn_point=random.choice(spawn_points) #生成车辆1 vehicle_1 = world.spawn_actor(vehicle_bp, spawn_point) #自定义生成点 transform = carla.Transform(Location(x=230, y=195, z=40), Rotation(yaw=180)) #生成车辆2 vehicle_2 = world.spawn_actor(vehicle_bp, transform) #对车辆进行操作 location = vehicle_2.get_location() location.z += 10.0 vehicle_2.set_location(location) #销毁Actor destroyed_sucessfully = vehicle_2.destroy() # Returns True if successful
二、传感器
传感器类型包括Cameras、Detectors、Others
三、camera.rgb介绍 ( sensor-reference)
- Blueprint: sensor.camera.rgb
- Output: carla.Image per step (unless
sensor_tick
says otherwise)..
1.camera.rgb 模板属性--基础属性
2.rgb输出属性
camera_bp = blueprint_library.find('sensor.camera.rgb'camera_bp = blueprint_library.find('sensor.camera.rgb') camera_bp.set_attribute('fov', '110') camera_bp.set_attribute('image_size_x','1920') camera_bp.set_attribute('image_size_y','1080') camera_bp.set_attribute('sensor_tick','0.1')#固定采样周期,默认为零,表示尽快采样。单位:秒 relative_transform_1 = carla.Transform(carla.Location(x=1.3, y=-0.5, z=1), carla.Rotation(yaw=0)) relative_transform_2 = carla.Transform(carla.Location(x=1.3, y= 0.5, z=1), carla.Rotation(yaw=0)) self.camera_1 = world.spawn_actor(camera_bp, relative_transform_1, attach_to=self.ego_car) self.camera_2 = world.spawn_actor(camera_bp, relative_transform_2, attach_to=self.ego_car) self.camera_1.listen(lambda image: self.camera_listening_1(image)) self.camera_2.listen(lambda image: self.camera_listening_2(image))
def camera_listening_1(self,carla_image): image.save_to_disk('output/%06d.png' % carla_image.frame)