Camera Focus Modes

Continuous Autofocus and Other Focus Modes

This article describes the different focus modes available in Vuforia (since v1.5 and above).

The behavior of the focus modes in Vuforia (since v1.5) is described below:

  1. FOCUS_MODE_NORMAL - the default focus mode provided by the device
  2. FOCUS_MODE_TRIGGERAUTO - setting this focus mode will trigger a single autofocus operation.
  3. FOCUS_MODE_CONTINUOUSAUTO - starting in Android 2.3 and iOS devices this focus mode allows to switch-on driver level continuous autofocus for cameras. This is the optimal focus mode for AR apps, since it guarantees that the camera is focused on the target, thus yielding the best tracking results.
  4. FOCUS_MODE_INFINITY - sets the camera to "infinity", as provided by the camera driver implementation. (Not supported on iOS).
  5. FOCUS_MODE_MACRO - sets the camera to "macro" mode, as provided by the camera driver implementation. This provides a sharp camera image for distances of close-ups (appx. 15 cm), rarely used in AR set-ups. (Not supported on iOS).

We encourage using FOCUS_MODE_CONTINUOUSAUTO in your applications whenever it is available on the device. When setting this mode, if the return value of setFocusMode() is TRUE your application will provide sharp camera images for both superior rendering, as well as for robust tracking performance.

If the FOCUS_MODE_CONTINUOUSAUTO is not available, the next best option is to implement a 'touch to focus' behavior in your app. To do this, trigger setFocusMode() with FOCUS_MODE_TRIGGERAUTO value each time the user touches the screen. The disadvantage of this behavior is that most camera drivers pick a random direction to focus (near or far), so you have a 50% chance that the image will defocus and then focus on the target. Under certain conditions due this focus logic the tracking can be lost for a moment until a sharp image is provided again by the camera.

FOCUS_MODE_INFINITY and FOCUS_MODE_MACRO are usable in certain application scenarios, as described above.

FOCUS_MODE_NORMAL sets the camera into the default mode as defined by the camera driver.

Setting Focus Mode with the Vuforia C++ API
 

bool focusModeSet = Vuforia::CameraDevice::getInstance().setFocusMode(
  Vuforia::CameraDevice::FOCUS_MODE_CONTINUOUSAUTO);

if (!focusModeSet) {
    LOG("Failed to set focus mode (unsupported mode).");
}
 

Setting Focus Mode with the Vuforia Java API
 

boolean focusModeSet = CameraDevice.getInstance().setFocusMode(
  CameraDevice.FOCUS_MODE.FOCUS_MODE_CONTINUOUSAUTO);

if (!focusModeSet) {
    Log.d("Sample Log Tag", "Failed to set focus mode (unsupported mode).");
}

Setting Focus Mode with the Vuforia Unity Extension C# API
 

bool focusModeSet = CameraDevice.Instance.SetFocusMode( 
    CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);

if (!focusModeSet) {
    Debug.Log("Failed to set focus mode (unsupported mode).");
 
You can configure autofocus when Vuforia initializes by adding the following code to a script that inherits from Monobehaviour. This registers a callback with the VuforiaBehaviour that will set a focus mode when the Vuforia process has started.
 
void Start () 
{
    var vuforia = VuforiaARController.Instance;
    vuforia.RegisterVuforiaStartedCallback(OnVuforiaStarted);
    vuforia.RegisterOnPauseCallback(OnPaused);
}
 
private void OnVuforiaStarted()
{
    CameraDevice.Instance.SetFocusMode(
        CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
}
 
private void OnPaused(bool paused)
{
    if (!paused) // resumed
    {
        // Set again autofocus mode when app is resumed
        CameraDevice.Instance.SetFocusMode(
            CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
    }
}