Configuring the camera

CameraConfig describes the properties of the underlying camera sensor, including:

  • The camera ID
  • If available, whether a depth sensor will be used
  • The direction the camera is facing:
    • front-facing (selfie)
    • rear-facing (world)
  • FPS (frames per second) range
  • CPU image dimensions
  • GPU texture dimension
  • If present, whether the device's stereo multi-camera will be used

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.

Common use cases for filtering include:

  • 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.

    Java

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

    Kotlin

    // Return only camera configs that target 30 FPS camera capture frame rate.
    filter.targetFps = 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.

    Java

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

    Kotlin

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

  • Selecting an alternate GPU texture resolution. On supported devices, ARCore may provide additional GPU texture resolutions. Selecting a lower resolution GPU texture may help improve app performance by reducing GPU load and lowering memory bandwidth requirements, although is not guaranteed to improve performance in all cases.

Using camera config filters

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

Java

// 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.
List<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.get(0));

Kotlin

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

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

// Return only camera configs that will not use the depth sensor.
filter.depthSensorUsage = 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.
val 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.cameraConfig = cameraConfigList[0]

Focus mode

You can also set the focus mode in the session configuration. Fixed focus is generally better for tracking (and is the ARCore default on most devices). Auto focus is required for recording, photography, videography, and when nearby objects need to be in focus.

See Config.FocusMode for details.