How to change Vuforia AR camera focus mode?

时光总嘲笑我的痴心妄想 提交于 2019-12-06 13:16:47

try this

void Start () 
{
    VuforiaBehaviour.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted);
    VuforiaBehaviour.Instance.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);
    }
}

This code is the right code.

bool cameramode = false;
public void OnCameraChangeMode()
{
    Vuforia.CameraDevice.CameraDirection currentDir = Vuforia.CameraDevice.Instance.GetCameraDirection();
    if (!cameramode) {
        RestartCamera(Vuforia.CameraDevice.CameraDirection.CAMERA_FRONT);
        camBtnTxt.text = "Back Camera";
    } else {
        RestartCamera(Vuforia.CameraDevice.CameraDirection.CAMERA_BACK);
        camBtnTxt.text = "Front Camera";
    }
}

private void RestartCamera(Vuforia.CameraDevice.CameraDirection newDir)
{
    Vuforia.CameraDevice.Instance.Stop();
    Vuforia.CameraDevice.Instance.Deinit();
    Vuforia.CameraDevice.Instance.Init(newDir);
    Vuforia.CameraDevice.Instance.Start();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!