Skip to content

Segmentation Image API bug when in headless mode of NoDisplay setting #1724

@flyers

Description

@flyers

I found that in the latest master branch, the simGetImages API returns wrong image types if we use "NoDisplay" viewmode in settings.json. I use the Blocks environment and the following python scripts to reproduce this bug. When the viewmode is "NoDisplay", the following code gets the RGB image instead of the segmentation image.

import numpy as np
import cv2
import airsim

def uncompressed_to_cvimage(response):
    '''
    Convert uncompressed RGBA image to cv2 BGR format H x W x Channels
    '''
    assert response.pixels_as_float == False
    img1d = np.fromstring(response.image_data_uint8, dtype=np.uint8)
    img = img1d.reshape(response.height, response.width, 4)[:, :, 0:-1]
    return img[:, :, ::-1]

client = airsim.MultirotorClient()
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)

response = client.simGetImages([airsim.ImageRequest(
    "0", airsim.ImageType.Segmentation, False, False)])[0]
seg = uncompressed_to_cvimage(response)
cv2.imshow('seg', seg)
cv2.waitKey(0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions