Accessing camera or sensor data

We can retrieve the sensor data at any given time step using the returned sensor_data object's data property. To retrieve the RGB camera frames, input the following code:

rgb_image = sensor_data['CameraRGB'].data

rgb_image is a NumPy n-d array, which you can access and manipulate as you would usually access and manipulate a NumPy n-d array.

For example, to access the pixel value of the RGB camera image at the (x, y) image plane coordinates, you can do so using the following line:

pixel_value_at_x_y = rgb_image[X, Y]

To retrieve the depth camera frames, input the following code:

depth_image = sensor_data['CameraDepth'].data

Get Hands-On Intelligent Agents with OpenAI Gym now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.