Log in or register to post comments

FOCUS_MODE_CONTINUOURAUTO

May 4, 2016 - 7:01am #1
Hey guys, been a while since I have worked on an AR project but it seems that the below script doesn't AutoFocus android camera's anymore? The camera will focus one time on start and once OnResume, but will not auto focus while running. I have searched high and low and can't seem to find anyone else having the same issue.

Tested on Android 4.4 and Android 6.0
Unity 5.3.4f1
Vuforia 5-5-9


using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
using Vuforia;

public class CameraDeviceMode : MonoBehaviour
{
	public bool StartFocus = false;
	public bool autofocus = false;

void Start () 
{
    VuforiaBehaviour.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted);
    VuforiaBehaviour.Instance.RegisterOnPauseCallback(OnPaused);
}

void Update ()
{
    CameraDevice.Instance.SetFocusMode(
    CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
}
  
private void OnVuforiaStarted()
    {
        autofocus = 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);
        }
    }
}

Any insight would be greatly appreciated!

FOCUS_MODE_CONTINUOURAUTO

August 18, 2016 - 12:16pm #8

Hello,

Please report back with your findings.

Thanks

FOCUS_MODE_CONTINUOURAUTO

August 17, 2016 - 1:41pm #7

The camera works just fine in my native Camera app. I have tested 4 Samsung Galaxy S7s now and none of them focus correctly within my app. I tested the ImageTargets sample app with my personal S7 and got mixed results. The first time the app was launched it focused correctly. The next few attempts wouldn't focus. Weird issue.



EDIT: After playing around with it more it focuses correctly after tapping the screen. Gonna dive into your scripts and see what I am missing.



Samples tested: 6.0.112

FOCUS_MODE_CONTINUOURAUTO

May 12, 2016 - 8:17am #6

Thanks for the info.

Could you:

- test the Unity Vuforia Image Targets sample app (you just need to import the sample app package, set the License Key in the ARCamera, build and run)

- test your device Native Camera app and see if the continuous autofocus is working correctly in that App.

?

 

FOCUS_MODE_CONTINUOURAUTO

May 12, 2016 - 6:20am #5

I haven't had time to test the sample app. But I tried it on a galaxy note 4 running android 6.0 and it works fine on that as well. It looks to be specific to the S7. Still not working on 6.1 for S7.

FOCUS_MODE_CONTINUOURAUTO

May 12, 2016 - 3:56am #4

Have you tested the Image Targets sample app (without any modification) on the S7 ?  Does the continuous autofocus work with the samples ?

I wonder if the issue relates to the script below (which seems correct) or it might be a more general condition on that specific device ..

 

FOCUS_MODE_CONTINUOURAUTO

May 5, 2016 - 3:37pm #3

I got it working using a modified script for your answer on another thread, it works on android 4.4, but I tested it on 2 S7s running android 6.0 and it doesn't work on those.

 

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

public class CameraDeviceMode : MonoBehaviour 
{
    private bool mVuforiaStarted = false;

    // Use this for initialization
    void Start ()
    {
        VuforiaBehaviour vuf = (VuforiaBehaviour)FindObjectOfType(typeof(VuforiaBehaviour));
        vuf.RegisterVuforiaStartedCallback(OnVuforiaStarted);
    }

    private void OnVuforiaStarted()
    {
        Debug.Log(" OnVuforiaStarted ");
        mVuforiaStarted = true;
        SetAutofocus();
    }

    void OnApplicationPause(bool pause)
    {
        if (!pause)
        {
            // App resumed
            Debug.Log("App resumed");
            if (mVuforiaStarted)
            {
                // App resumed, and Vuforia already started previously
                SetAutofocus();
            }
        }
    }

    private void SetAutofocus()
    {
        CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
    }
}

 

FOCUS_MODE_CONTINUOURAUTO

May 5, 2016 - 12:21pm #2

Is there a reason why you are calling this in the Update method ? The Update method is executed at every frame, but you should not need it:

void Update ()
{
    CameraDevice.Instance.SetFocusMode(
    CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
}

 

You can just set the focus mode once; the continuous autofocus adjustment will then run in the background. 

Log in or register to post comments