11
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

vuforiaでオートフォーカスを効かせる

Last updated at Posted at 2017-01-30

手順

大体の手順は以下のスレッドの通り。
https://developer.vuforia.com/forum/unity-extension-technical-discussion/camera-focus-mode-android-unity

  • ARCameraゲームオブジェクトに上記のCameraFocusController.csをアタッチ。

それでも実行されない

  • Assets>Plugins>Android>AndroidManifest.xmlに 、android.hardware.camera.autofocusを追加。
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus"/>

それでも実行されない

問題発生状況

  • Vuforia 6.2
  • Unity 5.4.4f1 64bit (windows10)
  • Sumsung GalaxyS7

以上でVuforiaアプリを起動すると、カメラのオートフォーカスが実行されない。
調べるにGalaxySシリーズで発生している様子。
https://developer.vuforia.com/forum/android/focus-problems-android

対応

上記のCameraFocusController.csに、タップ時にフォーカスを手動実行させる記述を追加。

using UnityEngine;
using System.Collections;
using Vuforia;

public class CameraFocusController : MonoBehaviour {

    private bool mVuforiaStarted = false;

    void Start () 
    {
        VuforiaARController vuforia = VuforiaARController.Instance;

        if (vuforia != null)
            vuforia.RegisterVuforiaStartedCallback(StartAfterVuforia);
    }

    private void StartAfterVuforia()
    {
        mVuforiaStarted = true;
        SetAutofocus();
    }

    void OnApplicationPause(bool pause)
    {
        if (!pause)
        {
            // App resumed
            if (mVuforiaStarted)
            {
                SetAutofocus();
            }
        }
    }

    private void SetAutofocus()
    {
        if (CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO))
        {
            Debug.Log("Autofocus set");
        }
        else
        {
            Debug.Log("this device doesn't support auto focus");
        }
    }

    void Update()
    {
        foreach (Touch touch in Input.touches)
        {
            if (touch.phase == TouchPhase.Began)
            {
                CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_TRIGGERAUTO);
                Debug.Log("focus");
            }
        }
    }
}
11
8
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?