Google is committed to advancing racial equity for Black communities. See how.

Use Raw Depth in your Unity app

The Raw Depth API provides depth data for a camera image that has higher accuracy than full Depth API data, but does not always cover every pixel. Raw depth images, along with their matching confidence images, can also be further processed, allowing apps to use only the depth data that has sufficient accuracy for their individual use case.

Device compatibility

Raw Depth is available on all devices that support the Depth API. The Raw Depth API, like the full Depth API, does not require a supported hardware depth sensor, such as a time-of-flight (ToF) sensor. However, both the Raw Depth API and the full Depth API make use of any supported hardware sensors that a device may have.

Raw Depth API vs full Depth API

The Raw Depth API provides depth estimates with higher accuracy, but raw depth images may not include depth estimates for all pixels in the camera image. In contrast, the full Depth API provides estimated depth for every pixel, but per-pixel depth data may be less accurate due to smoothing and interpolation of depth estimates. The format and size of depth images are the same across both APIs. Only the content differs.

The following table illustrates the differences between the Raw Depth API and the full Depth API using an image of a chair and a table in a kitchen.

API Returns Camera image Depth image Confidence image
Raw Depth API
  • A raw depth image that contains a very accurate depth estimate for some, but not all, pixels in the camera image.
  • A confidence image that gives the confidence for every raw depth image pixel. Camera image pixels that do not have a depth estimate have a confidence of zero.
Full Depth API
  • A single "smoothed" depth image that contains a depth estimate for every pixel.
  • No confidence image is provided with this API.
N/A

Confidence images

In confidence images returned by the Raw Depth API, lighter pixels have higher confidence values, with white pixels representing full confidence and black pixels representing no confidence. In general, regions in the camera image that have more texture, such as a tree, will have higher raw depth confidence than regions that don’t, such as a blank wall. Surfaces with no texture usually yield a confidence of zero.

If the target device has a supported hardware depth sensor, confidence in areas of the image close enough to the camera will likely be higher, even on textureless surfaces.

Use cases

With the Raw Depth API, you can obtain depth images that provide a more detailed representation of the geometry of the objects in the scene. Raw depth data can be useful when creating AR experiences where increased depth accuracy and detail are needed for geometry-understanding tasks. Some use cases include:

  • 3D reconstruction
  • Measurement
  • Shape detection

Prerequisites

Make sure that you understand fundamental AR concepts and how to configure an ARCore session before proceeding.

Enable Depth

In a new ARCore session, check whether a user's device supports Depth. Not all ARCore-compatible devices support the Depth API due to processing power constraints. To save resources, depth is disabled by default on ARCore. Enable depth mode to have your app use the Depth API.

// Create the ARCore session.
var session = new Session();
session.GetCameraConfig();

// Check whether the user's device supports the Depth API.
if (Session.IsDepthModeSupported(DepthMode.Automatic))
{
  // If depth mode is available on the user's device, perform
  // the steps you want here.
}

Acquire the latest raw depth image

Call UpdateRawDepthTexture() to acquire the latest raw depth image.

Texture2D depthTexture = new Texture2D(2,2);
DepthStatus status = Frame.CameraImage.UpdateRawDepthTexture(ref depthTexture);
if (status == DepthStatus.Success)
{
    // Use depth texture.
}

Acquire the latest raw depth confidence image

Call UpdateRawDepthConfidenceTexture() to acquire the confidence image. You can use the confidence image to check the accuracy of each raw depth pixel.

Texture2D depthTexture = new Texture2D(2,2);
DepthStatus status = Frame.CameraImage.UpdateRawDepthConfidenceTexture(ref depthTexture);
if (status == DepthStatus.Success)
{
    // Use depth texture.
}