Vuforia专题:设置AR摄像头自动对焦
一,前言
在之前使用的时候,如果没有设置自动对焦可以发现,摄像头画面极其模糊。并导致识别的结果不是很理想
加上自动对焦后的效果如下:
二、具体步骤
1、ARCamera添加脚本CameraSetting.cs
下面是具体代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
namespace Vuforia
{
public class CameraSetting : MonoBehaviour
{
void Start()
{
VuforiaApplication.Instance.OnVuforiaStarted += OnVuforiaStarted;
VuforiaApplication.Instance.OnVuforiaPaused += OnPaused;
bool focusModeSet = VuforiaBehaviour.Instance.CameraDevice.SetFocusMode(FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
if (!focusModeSet)
{
Debug.Log("Failed to set focus mode" + focusModeSet);
}
}
private void OnVuforiaStarted()
{
VuforiaBehaviour.Instance.CameraDevice.SetFocusMode(
FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
VuforiaBehaviour.Instance.CameraDevice.SetCameraMode(Vuforia.CameraMode.MODE_DEFAULT);
}
private void OnPaused(bool paused)
{
if (!paused) // Resumed
{
// Set again autofocus mode when app is resumed
VuforiaBehaviour.Instance.CameraDevice.SetFocusMode(
FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
}
}
}
}
2,设置到自动对焦模式