How to change Vuforia AR camera focus mode?

你离开我真会死。 提交于 2019-12-08 00:37:25

问题


I am using Vuforia 6.2 AR SDK for in Unity. But while I test the application in Android phone the camera seems like blurry. I searched in Vuforia's developer website and found some camera focus mode but I can't implement because that guideline was for older Vuforia SDK, I can't find the script they mentioned in their website. Here is their code sample but it's not working. I created different script and run this line on Start() function, but still not working.

CameraDevice.Instance.SetFocusMode(
        CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);

回答1:


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);
    }
}



回答2:


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();
}


来源:https://stackoverflow.com/questions/41607773/how-to-change-vuforia-ar-camera-focus-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!