-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject-204.py
More file actions
62 lines (54 loc) · 2.12 KB
/
project-204.py
File metadata and controls
62 lines (54 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import glob
import os
import sys
import random
import time
try:
sys.path.append(glob.glob('../carla/dist/carla-*%d.%d-%s.egg' % (
sys.version_info.major,
sys.version_info.minor,
'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0])
except IndexError:
pass
import carla
IM_WIDTH = 1366
IM_HEIGHT = 768
actor_list = []
def image(image):
image.save_to_disk(f'output/frame_{image.frame_number}.jpg')
try:
client = carla.Client('127.0.0.1', 2000)
client.set_timeout(2.0)
world = client.get_world()
get_blueprint_of_world = world.get_blueprint_library()
car_model = get_blueprint_of_world.filter('model3')[0]
spawn_point = random.choice(world.get_map().get_spawn_points())
dropped_vehicle = world.spawn_actor(car_model, spawn_point)
dropped_vehicle.set_autopilot(True) # if you just wanted some NPCs to drive.
simulator_camera_location_rotation = carla.Transform(spawn_point.location, spawn_point.rotation)
simulator_camera_location_rotation.location += spawn_point.get_forward_vector() * 30
simulator_camera_location_rotation.rotation.yaw += 180
simulator_camera_view = world.get_spectator()
simulator_camera_view.set_transform(simulator_camera_location_rotation)
dropped_vehicle.set_transform(spawn_point)
actor_list.append(dropped_vehicle)
## camera sensor
camera_sensor = get_blueprint_of_world.find('sensor.camera.rgb')
# change the dimensions of the image
camera_sensor.set_attribute('image_size_x', f'{IM_WIDTH}')
camera_sensor.set_attribute('image_size_y', f'{IM_HEIGHT}')
camera_sensor.set_attribute('fov', '170')
# Adjust sensor relative to vehicle
sensor_camera_spawn_point = carla.Transform(carla.Location(x=3, z=2))
# spawn the sensor and attach to vehicle.
sensor = world.spawn_actor(camera_sensor, sensor_camera_spawn_point, attach_to=dropped_vehicle)
# add sensor to list of actors
actor_list.append(sensor)
# do something with this sensor
sensor.listen(image)
time.sleep(1000)
finally:
print('destroying actors')
for actor in actor_list:
actor.destroy()
print('done.')