carla tutorials

import carla
import time
import numpy as np

def process_image(image):
    # Convert the image from a carla.Image to a numpy array
    image_data = np.frombuffer(image.raw_data, dtype=np.dtype("uint8"))
    image_data = np.reshape(image_data, (image.height, image.width, 4))
    
    # Do something with the image data (e.g. save it to disk)
    # ...


actor_list = []
try:
    client = carla.Client('172.16.183.208', 2000)
    world = client.get_world()

    blueprint_library = world.get_blueprint_library()
    model_3 = blueprint_library.filter('model3')[0]

    # Define the vehicle's location and orientation
    location = carla.Location(x=230, y=195, z=40)
    rotation = carla.Rotation(yaw=180)
    
    transform = carla.Transform(location, rotation)
    
    vehicle = world.spawn_actor(model_3, transform)
    
    actor_list.append(vehicle)

    # Add a camera sensor to the vehicle
    camera_bp = blueprint_library.find('sensor.camera.rgb')
    camera_transform = carla.Transform(carla.Location(x=1.5, z=2.4))
    camera = world.spawn_actor(camera_bp, camera_transform, attach_to=vehicle)

    actor_list.append(camera)

    # Register the callback function to process the camera data
    camera.listen(process_image)
# 获取观察者actor
    spectator = world.get_spectator()

    # 计算观察者位置
    location = vehicle.get_location()
    location += carla.Location(x=-5.5, z=2.8)
    rotation = vehicle.get_transform().rotation
    rotation.yaw += 180

    # 更新观察者位置和方向
    spectator.set_transform(carla.Transform(location, rotation))
    # Turn left 90 degrees
    vehicle.apply_control(carla.VehicleControl(throttle=0.5 , steer=-1.0))
    time.sleep(1.2)

    # Turn right 90 degrees
    vehicle.apply_control(carla.VehicleControl(throttle=0.5 , steer=1.0))
    time.sleep(1.2)
finally:
   for actor in actor_list:
       actor.destroy()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值