笔记6:Carla官方文档阅读 -- 4th【Sensor and Data】/【(1)Sensors step-by-step】

import sys
try:
    sys.path.append('D:\work_software\Carla\Carla_0.9.10\CARLA_0.9.10\WindowsNoEditor\PythonAPI\carla\dist\carla-0.9.10-py3.7-win-amd64.egg')
except IndexError:
    pass




import carla
import random
import time

client = carla.Client("localhost", 2000)
client.set_timeout(5.0)
world = client.get_world()
vehicle_actor_blueprint = world.get_blueprint_library().filter("vehicle.*.*")[0]
vehicle_actor_transform = carla.Transform(carla.Location(-88.5, -65.0, 0.1), carla.Rotation(yaw=90))
vehicle = world.spawn_actor(vehicle_actor_blueprint, vehicle_actor_transform)




# Find the blueprint of the sensor
camera_bp = world.get_blueprint_library().find('sensor.camera.rgb')
# Modify the attributes of the blueprint to set image resolution and field of view
camera_bp.set_attribute('image_size_x', '1920')
camera_bp.set_attribute('image_size_y', '1080')
camera_bp.set_attribute('fov', '110')
# Set the time in seconds between sensor captures
camera_bp.set_attribute('sensor_tick', '1.0')

camera_transform = carla.Transform(carla.Location(x=0.8, z=1.7))
sensor = world.spawn_actor(camera_bp, camera_transform, attach_to=vehicle)

# do_something() will be call each time a new image is generated by the camera
# sensor.listen(lambda data: do_something(date))
sensor.listen(lambda image: image.save_to_disk('./output/%06d.png' % image.frame))

# This collision sensor would print everytime a collision is detected
# def callback(event):
#     for actor_id in event:
#         vehicle = world_ref().get_actor(actor_id)
#         print('Vehicle too close: %s' % vehicle.type_id)
# sensor02.listen(callback)

# Main loop
while True:
    # Tick the server
    world.tick()
    w_frame = world.get_snapshot().frame
    print("World's frame: %d" % w_frame)
    time.sleep(1)

注:my_script_test_11.py

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值