def get_image(): image_response = client.simGetImages( [ImageRequest(0, AirSimImageType.Scene, False, False)])[0] image1d = np.fromstring(image_response.image_data_uint8, dtype=np.uint8) image_rgba = image1d.reshape(image_response.height, image_response.width, 4) return image_rgba[76:135, 0:255, 0:3].astype(float)
# TensorFlow initialization boilerplate sess = tf.Session() init_op = tf.global_variables_initializer() sess.run(init_op) # Once the brakes come on, we need to keep them on for a while before exiting; otherwise, # the vehicle will resume moving. brakingCount = 0 # Loop until we detect a collision while True: # Get RGBA camera images from the car responses = client.simGetImages( [ImageRequest(1, AirSimImageType.Scene)]) # Save it to a temporary file image = responses[0].image_data_uint8 AirSimClientBase.write_file(os.path.normpath(TMPFILE), image) # Read-load the image as a grayscale array image = loadgray(TMPFILE) # Run the image through our inference engine. # Engine returns a softmax output inside a list, so we grab the first # element of the list (the actual softmax vector), whose second element # is the absence of an obstacle. safety = sess.run(output, feed_dict={x: [image]})[0][1] # Slam on the brakes if it ain't safe!
# connect to the AirSim simulator print('Connected') # go forward client.takeoffAsync().join() vx = 2 vy = 0 client.moveByVelocityAsync(vx, vy, 0, 1, airsim.DrivetrainType.ForwardOnly, airsim.YawMode(False, 0)).join() imagequeue = [] while True: client.moveByVelocityAsync(vx, vy, 0, 1, airsim.DrivetrainType.ForwardOnly, airsim.YawMode(False, 0)).join() # get RGBA camera images from the car responses = client.simGetImages([ImageRequest(1, AirSimImageType.Scene)]) # add image to queue imagequeue.append(responses[0].image_data_uint8) # dump queue when it gets full if len(imagequeue) == QUEUESIZE: for i in range(QUEUESIZE): AirSimClientBase.write_file( os.path.normpath(IMAGEDIR + '/image%03d.png' % i), imagequeue[i]) imagequeue.pop(0) collision_info = client.simGetCollisionInfo() if collision_info.has_collided:
client = CarClient() client.confirmConnection() print('Connected') #client.enableApiControl(True) car_controls = CarControls() #client.reset() ## go forward #car_controls.throttle = 1.0 #car_controls.steering = 0 #client.setCarControls(car_controls) cnt = 0 while True: # get RGBA camera images from the car responses = client.simGetImages( [ImageRequest(1, AirSimImageType.Segmentation)]) image = responses[0].image_data_uint8 AirSimClientBase.write_file( os.path.normpath(IMAGEDIR + '/image%03d.png' % cnt), image) print('save image%03d' % cnt) cnt += 1 time.sleep(0.1)