How to use the airsim.ImageRequest function in airsim

To help you get started, we’ve selected a few airsim examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / AirSim / PythonClient / computer_vision / cv_mode.py View on Github external
for camera_name in range(5):
    camera_info = client.simGetCameraInfo(str(camera_name))
    print("CameraInfo %d: %s" % (camera_name, pp.pprint(camera_info)))

airsim.wait_key('Press any key to get images')
for x in range(3): # do few times
    z = x * -20 - 5 # some random number
    client.simSetVehiclePose(airsim.Pose(airsim.Vector3r(z, z, z), airsim.to_quaternion(x / 3.0, 0, x / 3.0)), True)

    responses = client.simGetImages([
        airsim.ImageRequest("0", airsim.ImageType.DepthVis),
        airsim.ImageRequest("1", airsim.ImageType.DepthPerspective, True),
        airsim.ImageRequest("2", airsim.ImageType.Segmentation),
        airsim.ImageRequest("3", airsim.ImageType.Scene),
        airsim.ImageRequest("4", airsim.ImageType.DisparityNormalized),
        airsim.ImageRequest("4", airsim.ImageType.SurfaceNormals)])

    for i, response in enumerate(responses):
        if response.pixels_as_float:
            print("Type %d, size %d, pos %s" % (response.image_type, len(response.image_data_float), pprint.pformat(response.camera_position)))
            airsim.write_pfm(os.path.normpath('/temp/cv_mode_' + str(x) + "_" + str(i) + '.pfm'), airsim.get_pfm_array(response))
        else:
            print("Type %d, size %d, pos %s" % (response.image_type, len(response.image_data_uint8), pprint.pformat(response.camera_position)))
            airsim.write_file(os.path.normpath('/temp/cv_mode_' + str(x) + "_" + str(i) + '.png'), response.image_data_uint8)

    pose = client.simGetVehiclePose()
    pp.pprint(pose)

    time.sleep(3)

# currently reset() doesn't work in CV mode. Below is the workaround
client.simSetPose(airsim.Pose(airsim.Vector3r(0, 0, 0), airsim.to_quaternion(0, 0, 0)), True)
github microsoft / AirSim / PythonClient / car / multi_agent_car.py View on Github external
print("Car1: Apply break")
    car_controls1.brake = 0 #remove break

    car_controls2.brake = 1
    client.setCarControls(car_controls2, "Car2")
    print("Car2: Apply break")
    car_controls2.brake = 0 #remove break
    time.sleep(3)   # let car drive a bit
    
    # get camera images from the car
    responses1 = client.simGetImages([
        airsim.ImageRequest("0", airsim.ImageType.DepthVis),  #depth visualization image
        airsim.ImageRequest("1", airsim.ImageType.Scene, False, False)], "Car1")  #scene vision image in uncompressed RGBA array
    print('Car1: Retrieved images: %d' % (len(responses1)))
    responses2 = client.simGetImages([
        airsim.ImageRequest("0", airsim.ImageType.Segmentation),  #depth visualization image
        airsim.ImageRequest("1", airsim.ImageType.Scene, False, False)], "Car2")  #scene vision image in uncompressed RGBA array
    print('Car2: Retrieved images: %d' % (len(responses2)))

    for response in responses1 + responses2:
        filename = 'c:/temp/car_multi_py' + str(idx)

        if response.pixels_as_float:
            print("Type %d, size %d" % (response.image_type, len(response.image_data_float)))
            airsim.write_pfm(os.path.normpath(filename + '.pfm'), airsim.get_pfm_array(response))
        elif response.compress: #png format
            print("Type %d, size %d" % (response.image_type, len(response.image_data_uint8)))
            airsim.write_file(os.path.normpath(filename + '.png'), response.image_data_uint8)
        else: #uncompressed array
            print("Type %d, size %d" % (response.image_type, len(response.image_data_uint8)))
            img1d = np.fromstring(response.image_data_uint8, dtype=np.uint8) #get numpy array
            img_rgba = img1d.reshape(response.height, response.width, 4) #reshape array to 4 channel image array H X W X 4
github harvard-edge / airlearning-rl / gym_airsim / envs / airlearningclient.py View on Github external
def getScreenDepthVis(self, track):

        responses = self.client.simGetImages([airsim.ImageRequest(0, airsim.ImageType.DepthPerspective, True, False)])
        #responses = self.client.simGetImages([airsim.ImageRequest("0", airsim.ImageType.DepthVis,True, False)])

        if(responses == None):
            print("Camera is not returning image!")
            print("Image size:"+str(responses[0].height)+","+str(responses[0].width))
        else:
            img1d = np.array(responses[0].image_data_float, dtype=np.float)

        img1d = 255 / np.maximum(np.ones(img1d.size), img1d)
        if((responses[0].width!=0 or responses[0].height!=0)):
            img2d = np.reshape(img1d, (responses[0].height, responses[0].width))

        else:
            print("Something bad happened! Restting AirSim!")
            self.AirSim_reset()
            img2d = np.ones((144, 256))
github nesl / UnrealAirSimDRL / Util / PointCloud.py View on Github external
orien = Vector3r(0, 0, 0)
client.simSetCameraOrientation("3", orien) #radians
orien = Vector3r(0, 0, -np.pi/2)
client.simSetCameraOrientation("1", orien)
orien = Vector3r(0, 0, np.pi/2)
client.simSetCameraOrientation("2", orien)
orien = Vector3r(0, 0, np.pi/2)
# Reset Collion Flags
print("Setting Camera Views DONE!")



while True:
    print("Making a Point Cloud!")
    images = client.simGetImages([airsim.ImageRequest("0", airsim.ImageType.DepthPlanner, False, False), # Front Center
            airsim.ImageRequest("1", airsim.ImageType.DepthPlanner, False, False), # Front Right
            airsim.ImageRequest("2", airsim.ImageType.DepthPlanner, False, False)]) # Front Left
    img1d_FC = np.fromstring(images[0].image_data_uint8, dtype=np.uint8) 
    img_depth_FC = np.array(img1d_FC.reshape(images[0].height, images[0].width, 4), dtype = np.uint8)
    img_depth_FC = img_depth_FC[:,:,0:3]
    
    img1d_FR = np.fromstring(images[1].image_data_uint8, dtype=np.uint8) 
    img_depth_FR = np.array(img1d_FR.reshape(images[1].height, images[1].width, 4), dtype = np.uint8)
    img_depth_FR = img_depth_FR[:,:,0:3]
    
    img1d_FL = np.fromstring(images[2].image_data_uint8, dtype=np.uint8) 
    img_depth_FL = np.array(img1d_FL.reshape(images[2].height, images[2].width, 4), dtype = np.uint8)
    img_depth_FL = img_depth_FL[:,:,0:3]
                    
    #img_rgb_FC = img_rgba_FC[:,:,0:3]
    #noIdea = client.simGetImage("0", airsim.ImageType.DepthPlanner)`
github harvard-edge / airlearning-rl / gym_airsim / envs / airlearningclient.py View on Github external
def getScreenRGB(self):
        responses = self.client.simGetImages([airsim.ImageRequest("1", airsim.ImageType.Scene, False, False)])
        response = responses[0]
        img1d = np.fromstring(response.image_data_uint8, dtype=np.uint8)
        if ((responses[0].width != 0 or responses[0].height != 0)):
            img_rgba = img1d.reshape(response.height, response.width, 4)
            rgb = cv2.cvtColor(img_rgba, cv2.COLOR_BGRA2BGR)
        else:
            print("Something bad happened! Restting AirSim!")
            self.AirSim_reset()
            rgb = np.ones(144, 256, 3)
        return rgb
github microsoft / AirSim / PythonClient / computer_vision / segmentation.py View on Github external
print("Done: %r" % (found))

##for neighborhood environment

#set object ID for sky
found = client.simSetSegmentationObjectID("SkySphere", 42, True);
print("Done: %r" % (found))

#below doesn't work yet. You must set CustomDepthStencilValue in Unreal Editor for now
airsim.wait_key('Press any key to set Landscape object ID to 128')
found = client.simSetSegmentationObjectID("[\w]*", 128, True);
print("Done: %r" % (found))

#get segmentation image in various formats
responses = client.simGetImages([
    airsim.ImageRequest("0", airsim.ImageType.Segmentation, True), #depth in perspective projection
    airsim.ImageRequest("0", airsim.ImageType.Segmentation, False, False)])  #scene vision image in uncompressed RGBA array
print('Retrieved images: %d', len(responses))

#save segmentation images in various formats
for idx, response in enumerate(responses):
    filename = 'c:/temp/py_seg_' + str(idx)

    if response.pixels_as_float:
        print("Type %d, size %d" % (response.image_type, len(response.image_data_float)))
        #airsim.write_pfm(os.path.normpath(filename + '.pfm'), airsim.get_pfm_array(response))
    elif response.compress: #png format
        print("Type %d, size %d" % (response.image_type, len(response.image_data_uint8)))
        #airsim.write_file(os.path.normpath(filename + '.png'), response.image_data_uint8)
    else: #uncompressed array - numpy demo
        print("Type %d, size %d" % (response.image_type, len(response.image_data_uint8)))
        img1d = np.fromstring(response.image_data_uint8, dtype=np.uint8) #get numpy array