将 ARCore 与 Vuforia 结合使用时相机没有聚焦?

Camera not focused when using ARCore with Vuforia?

当我将 ARCore 与 vuforia 库一起使用时,相机总是失焦,我该如何让相机对焦?

ARCamera 控件由 ARCore 接管,我们必须手动将相机设置为自动对焦模式。将此脚本添加到相机对象可以实现连续自动对焦模式。 脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;

public class CameraFocusController : MonoBehaviour
{
    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);
        }
    }
}


这是焦点的新方法

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;

public class CameraFocusController : MonoBehaviour
{
    void Start()
    {
        var vuforia = VuforiaApplication.Instance;
        vuforia.OnVuforiaStarted += OnVuforiaStarted;
        vuforia.OnVuforiaPaused += OnPaused;
    }

    private void OnVuforiaStarted()
    {
        VuforiaBehaviour.Instance.CameraDevice.SetFocusMode(
        Vuforia.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
    }

    private void OnPaused(bool paused)
    {
        if (!paused) // resumed
        {
            // Set again autofocus mode when app is resumed
            VuforiaBehaviour.Instance.CameraDevice.SetFocusMode(
            Vuforia.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
        }
    }
}