Camera configs

CameraConfig provides details of the camera configuration that ARCore uses to access the camera sensor for a given session. These details include, for example, the targeted capture frame rate, whether the front or back camera is used, and whether a depth sensor is enabled.

When creating a new ARCore session, ARCore uses setCameraConfig to set the camera config that best matches the list of available configs returned by getSupportedCameraConfigs(CameraConfigFilter). Your app can use CameraConfigFilter to narrow down the available camera configs for a given device at runtime by filtering based on your app's needs.

Two common use cases for filtering are:

  • Limiting camera capture frame rate to 30 fps. On devices that support 60 fps, ARCore will prioritize camera configs that support that frame rate. To filter out all camera configs that support 60 fps, apply a filter with setTargetFps using TargetFps.TARGET_FPS_30.

    // Return only camera configs that target 30fps camera capture frame rate.
    filter.setTargetFps(EnumSet.of(CameraConfig.TargetFps.TARGET_FPS_30));
    
  • Prevent ARCore from using the depth sensor. On devices that have a supported depth sensor, ARCore prioritizes camera configs that use the depth sensor. To filter out all camera configs that use the depth sensor, apply the setDepthSensorUsage filter using DepthSensorUsage.DO_NOT_USE.

    // Return only camera configs that will not use the depth sensor.
    filter.setDepthSensorUsage(EnumSet.of(CameraConfig.DepthSensorUsage.
    DO_NOT_USE));
    

Using camera config filters

Follow these steps to enable your app to filter camera configs.

// Create an ARCore session.
Session session = new Session(applicationContext);

// Create a camera config filter for the session.
CameraConfigFilter filter = new CameraConfigFilter(session);

// Return only camera configs that target 30 fps camera capture frame rate.
filter.setTargetFps(EnumSet.of(CameraConfig.TargetFps.TARGET_FPS_30));

// Return only camera configs that will not use the depth sensor.
filter.setDepthSensorUsage(EnumSet.of(CameraConfig.DepthSensorUsage.
DO_NOT_USE));

// Get list of configs that match filter settings.
// In this case, this list is guaranteed to contain at least one element,
// because both TargetFps.TARGET_FPS_30 and DepthSensorUsage.DO_NOT_USE
// are supported on all ARCore supported devices.
CameraConfig[] cameraConfigList = session.getSupportedCameraConfigs(filter);

// Use element 0 from the list of returned camera configs. This is because
// it contains the camera config that best matches the specified filter
// settings.
session.setCameraConfig(cameraConfigList[0]);