-
Notifications
You must be signed in to change notification settings - Fork 47
/
camera_streaming.py
51 lines (38 loc) · 1.79 KB
/
camera_streaming.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
from beamngpy import BeamNGpy, Scenario, Vehicle
from beamngpy.sensors import Camera
if __name__ == '__main__':
beamng = BeamNGpy('localhost', 64256)
beamng.open()
scenario = Scenario('italy', 'camera_streaming')
ego = Vehicle('ego', model='etk800', color='White')
scenario.add_vehicle(ego, pos=(237.90, -894.42, 246.10), rot_quat=(0.0173, -0.0019, -0.6354, 0.7720))
scenario.make(beamng)
beamng.settings.set_deterministic(60)
beamng.scenario.load(scenario)
beamng.control.pause()
beamng.scenario.start()
ego.ai.set_mode('span')
camera = Camera('camera1', beamng, ego,
requested_update_time=0.01, is_using_shared_memory=True,
pos=(-0.3, 1, 2), dir=(0, -1, 0), field_of_view_y=70,
near_far_planes=(0.1, 1000), resolution=(1024, 1024),
is_streaming=True, is_render_annotations=True, is_render_instance=True,
is_render_depth=True)
for i in range(1000000):
beamng.control.step(10)
# Getting raw bytes from the simulator -> the fastest you can get
raw_readings = camera.stream_raw()
# if you don't want to use streaming, then use this instead
# raw_readings = camera.poll_raw()
if i % 100 == 0:
print('Showing images from the stream...')
# Getting PIL.Image images created from the raw bytes -> slower
images = camera.stream()
# if you don't want to use streaming, then use this instead
# raw_readings = camera.poll()
if camera.is_render_colours:
images['colour'].show()
if camera.is_render_annotations:
images['annotation'].show()
if camera.is_render_depth:
images['depth'].show()