forked from microsoft/AirSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cv_mode.py
35 lines (27 loc) · 1.44 KB
/
cv_mode.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
# In settings.json first activate computer vision mode:
# https://github.com/Microsoft/AirSim/blob/master/docs/image_apis.md#computer-vision-mode
from AirSimClient import *
import pprint
pp = pprint.PrettyPrinter(indent=4)
client = CarClient()
client.confirmConnection()
for x in range(3): # do few times
z = x * -20 - 5 # some random number
client.simSetPose(Pose(Vector3r(z, z, z), AirSimClientBase.toQuaternion(x / 3.0, 0, x / 3.0)), True)
responses = client.simGetImages([
ImageRequest(0, AirSimImageType.DepthVis),
ImageRequest(1, AirSimImageType.DepthPerspective, True),
ImageRequest(0, AirSimImageType.Segmentation),
ImageRequest(0, AirSimImageType.Scene),
ImageRequest(0, AirSimImageType.DisparityNormalized),
ImageRequest(0, AirSimImageType.SurfaceNormals)])
for i, response in enumerate(responses):
if response.pixels_as_float:
print("Type %d, size %d" % (response.image_type, len(response.image_data_float)))
AirSimClientBase.write_pfm(os.path.normpath('/temp/cv_mode_' + str(x) + "_" + str(i) + '.pfm'), AirSimClientBase.getPfmArray(response))
else:
print("Type %d, size %d" % (response.image_type, len(response.image_data_uint8)))
AirSimClientBase.write_file(os.path.normpath('/temp/cv_mode_' + str(x) + "_" + str(i) + '.png'), response.image_data_uint8)
pose = client.simGetPose()
pp.pprint(pose)
time.sleep(3)