-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect_data.py
65 lines (53 loc) · 1.76 KB
/
collect_data.py
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
63
64
65
from concurrent.futures import process
import glob
import os
import sys
import time
import numpy as np
import cv2
import threading
import queue
import math
import random
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
actor_list = []
def process_image(image):
i = np.array(image.raw_data)
i2 = i.reshape((image.height, image.width, 4))
i3 = i2[:, :, :3]
image.save_to_disk(f"C:\CARLA_0.9.8\WindowsNoEditor\PythonAPI\out_data\{image.frame}.png")
try:
client = carla.Client('localhost', 2000)
client.set_timeout(10.0)
world = client.get_world()
settings = world.get_settings()
settings.fixed_delta_seconds = 0.05
#settings.synchronous_mode = True
world.apply_settings(settings)
spawnpoints = world.get_map().get_spawn_points()
#startpoint = spawnpoints[0]
startpoint = random. choice(spawnpoints)
vehicle_blueprint= world.get_blueprint_library().find('vehicle.tesla.model3')
vehicle = world.spawn_actor(vehicle_blueprint, startpoint)
actor_list.append(vehicle)
cam_bp = world.get_blueprint_library().find('sensor.camera.rgb')
cam_transform = carla.Transform(carla.Location(x=2.5, z=0.7))
cam = world.spawn_actor(cam_bp, cam_transform, attach_to=vehicle)
actor_list.append(cam)
vehicle.set_autopilot(True)
cam.listen(lambda data: process_image(data))
print("Collecting images....")
time.sleep(10)
finally:
print('destroying all actors')
exit = True
for actor in actor_list:
actor.destroy()
print('done')