Configuring the camera

ArCameraConfig 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 ArSession_setCameraConfig() to set the camera config that best matches the list of available configs returned by ArSession_getSupportedCameraConfigsWithFilter(). Your app can use ArCameraConfigFilter 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 ArCameraConfigFilter_setTargetFps() using AR_CAMERA_CONFIG_TARGET_FPS_30.

    // Return only camera configs that target 30 FPS camera capture frame
    // rate.
    ArCameraConfigFilter_setTargetFps(session, filter,
                                      AR_CAMERA_CONFIG_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 ArCameraConfigFilter_setDepthSensorUsage() filter using AR_CAMERA_CONFIG_DEPTH_SENSOR_USAGE_DO_NOT_USE.

    ArCameraConfigFilter_setDepthSensorUsage(
        session, filter, AR_CAMERA_CONFIG_DEPTH_SENSOR_USAGE_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.

// Create an ARCore session.
ArSession* session;
ArSession_create(env, context, &session);

// Create a camera config list and filter for the session.
ArCameraConfig* selected_config;
ArCameraConfigList* configs;
ArCameraConfigFilter* filter;
ArCameraConfig_create(session, &selected_config);
ArCameraConfigList_create(session, &configs);
ArCameraConfigFilter_create(session, &filter);

// Return only camera configs that target 30 fps camera capture frame rate.
ArCameraConfigFilter_setTargetFps(session, filter,
                                  AR_CAMERA_CONFIG_TARGET_FPS_30);

// Return only camera configs that will not use the depth sensor.
ArCameraConfigFilter_setDepthSensorUsage(
    session, filter, AR_CAMERA_CONFIG_DEPTH_SENSOR_USAGE_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.
ArSession_getSupportedCameraConfigsWithFilter(session, filter, configs);

// 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.
ArCameraConfigList_getItem(session, configs, 0, selected_config);

// Set the camera config to use selected_config.
ArSession_setCameraConfig(session, selected_config);

// Free memory.
ArCameraConfigFilter_destroy(filter);
ArCameraConfigList_destroy(configs);

Focus mode

You can also set the focus mode in the session config. 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 ArConfig_setFocusMode() for details.