Log in or register to post comments

Android Camera continuous autofocus not unsupported

May 21, 2015 - 4:19am #1

Hi! I have problem trying to get the CONTINUOUS AUTOFOCUS to work in Vuforia 4.0. The below code returned false (unsupported) for every android device. 

bool focusModeSet = CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);

if (!focusModeSet
{
     Debug.Log("Failed to set focus mode (unsupported mode).");
}

Can anyone kindly provide a hint or possible explanation behind this issue? Any help is kindly appreciated! Thanks

Android Camera continuous autofocus not unsupported

March 19, 2017 - 3:28am #16

I have similar problems with Focus mode ContinuousAuto:

It works, but is too much slow.. and not much accurate,

there is a way to make it more fast? call the one shot autofocus more fast in time? or more accurate?

Vuforia lates version

Unity  5.4.0

Testing on: Samsung S6

Thanks

Marcello

Android Camera continuous autofocus not unsupported

January 13, 2017 - 2:34am #15

the same problem

Vuforia 6.2.6

unity 5.5.0 3f

 

Assets/Autofocus.cs(15,29): error CS1061: Type `Vuforia.VuforiaBehaviour' does not contain a definition for `RegisterVuforiaStartedCallback' and no extension method `RegisterVuforiaStartedCallback' of type `Vuforia.VuforiaBehaviour' could be found. Are you missing an assembly reference?

Android Camera continuous autofocus not unsupported

December 21, 2016 - 12:15pm #14

Where do I put this script?

Edit:

I attached a new script to the ARCamera and added this code, but it doesn't work. There is no method called RegisterVuforiaStartedCallback.  How do I know when Vuforia has started?

 

Android Camera continuous autofocus not unsupported

October 4, 2016 - 1:44am #13

Hmm I got this to work when I open the app, but despite changing the QCAR bits to Vuforia instead, it still doesn't work if I minimise the app and start it up again. Any ideas? also I put the script on the AR camera which felt best, not sure if that is correct though.

Vuforia 6 and Unity 5.3

Android Camera continuous autofocus not unsupported

May 5, 2016 - 12:18pm #12

Just replace QCARBehaviour with VuforiaBehaviour,   and the RegisterQCARStartedCallback with RegisterVuforiaStartedCallback.

 

Android Camera continuous autofocus not unsupported

May 5, 2016 - 11:43am #11

Hey, when I try to use this script with Vuforia 5-5-9 and Unity 5.3.4 I get the ettor 'QCARBehaviour' could not be found. Are you missing a using directive or assembly reference?

QCARBehaviour.cs doesn't seem to exist in 5-5-9. Is there another script I should be referencing?

Android Camera continuous autofocus not unsupported

June 1, 2015 - 12:23am #10

@duncanx:

the OnVuforisStarted callback approach is correct, but in order to cover the pause/resume case, you also need to make sure to reset the desired focus mode upon app resume, as the android camera focus mode might reset its state when you pause the app; 

this is a code snippet that does the complete check at start as well as on resume:

using UnityEngine;
using System.Collections;
using Vuforia;

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

	// Use this for initialization
	void Start () 
    {
        QCARBehaviour qcar = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));
        qcar.RegisterQCARStartedCallback(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()
    {
        if (CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_TRIGGERAUTO))
        {
            Debug.Log("Autofocus set");
        }
    }
	
}

 

Android Camera continuous autofocus not unsupported

May 31, 2015 - 11:11pm #9

Hi,

Thanks for the helpful information. Will try the advices. One thing i found out is Galaxy Note 3 actually runs the continuous autofocus when autofocus:normal mode is called.

Really appreciate all the helps. Thanks!

Android Camera continuous autofocus not unsupported

May 30, 2015 - 2:23pm #8

Upon further investment...this is a bug afterall.  I could go into detail why, but the smoking gun is this:

If you put the android app into the background, then come back to the foreground...the focus doesn't work anymore. Even if I use your way...it works at the start just fine, but not after background/foregrounding the app.

The hack I wrote to fix it is:  OnApplicationPause, StartCoroutine and using a little bit of delay (the delay is needed) then the original call to the CameraDevice

 

 

Android Camera continuous autofocus not unsupported

May 30, 2015 - 9:01am #7

That works. I didn't try that specific code, but I zero'd in on the concept of "after vuforia" and thought "oooohhh...."

I would recommend you add some notes about this to your docs. What you have isn't "wrong", but it's legitimately easy to bump into. You can solve this in Unity by modifying the script execution order in project settings. Set anything that needs to work with QCAR to exectute after QCAR. It's not used very often and is easily overlooked. Having worked with Unity since the beginning...I've needed to use that feature only a few times, ever...which is why it's easy to miss.

In this case, I actually solved two issues I was having. Another issue was that I needed to audit at startup, the number of ImageTargets and do something with them. The issue was that my code was reporting that there were none active...which didn't any sense to me. It was also a check that never failed in the past versions of Vuforia so I assumed it was an API change...and also I wasn't getting any errors...just a reply from QCAR that couldn't be accurate as far I could tell at the time. Now also fixed.

 

 

Android Camera continuous autofocus not unsupported

May 29, 2015 - 10:27pm #6

The code you use is stil valid; I tried the same code on an S3 and it works as expected; maybe you're not calling it in the right place ?

Make sure to call that code after Vuforia has initialized, for example:

void Start() {
  QCARBehaviour qcar = (QCARBehaviour) FindObjectOfType( typeof (QCARBehaviour ) );
  qcar.RegisterQCARStartedCallback ( MyVuforiaStartedCallback );
}

private void MyVuforiaStartedCallback() {
  if (CameraDevice.Instance.SetFocusMode( CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO)) {
    Debug.Log(" Continuous Autofocus was set");
  }
  else {
    Debug.Log( "Continuous autofocus not supported" );
  }
}

 

Android Camera continuous autofocus not unsupported

May 29, 2015 - 9:06am #5

We have the same problem except we are sure it's a Vuforia 4.x issue. We are migrating our apps from 3.x to 4.x and discovering this issue. For all the devices we have, on Vuforia 2.x and 3.x this feature works fine. Change to vuforia 4.x...not work.

The code I use to enable this feature in the past is: CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO); which is still compiling with no issues (after you add the new namespace). Is there an updated version of this code?

 

 

Android Camera continuous autofocus not unsupported

May 28, 2015 - 9:33am #4

You should probably check to see which focus modes those devices support. Create a new Android app in Eclipse or Android Studio and use some code like this in your onResume():

Camera cam = Camera.open(0);
Camera.Parameters params = cam.getParameters();
List<String> focusModes = params.getSupportedFocusModes();

Testing this on a Moto G returned 4 supported focus modes:

  1. "auto"
  2. "infinity"
  3. "continuous-picture"
  4. "continuous-video"

AttachmentSize
Image icon motogfocusmodes.png16.27 KB

Android Camera continuous autofocus not unsupported

May 27, 2015 - 8:27pm #3

Hi,

Device tested:

     a) Samsung galaxy note 3 / SM-N9005 / Android 4.4.2

     b) Samsung galaxy s3 / GT-I9300 / Android 4.3

Vuforia version: Vuforia SDK v4.0.105

Platform: Unity 5

Description: Android continuous autofocus not working.

 

Sorry for the insufficient info. Thanks for the help

Android Camera continuous autofocus not unsupported

May 26, 2015 - 8:40pm #2

Can you provide more info on which Android devices and OS versions you tried this on?

https://developer.vuforia.com/forum/device-support/how-report-device-issue

Supported Focus Modes in Android are device-specific and our API simply calls to the Android API to set these parameters. You can write a simple (non-Vuforia) Android app that tries to set Focus Modes by setting the values in Camera.Parameters:

http://developer.android.com/reference/android/hardware/Camera.Parameters.html

 

Log in or register to post comments