Topic locked

Camera Focus Modes

March 8, 2015 - 4:08pm #1
Hi All,
I'm trying  to set up Camera Focus Modes in unity3d project.
My clean scene without Vuforia UI setup screen is out of focus.
 

https://developer.vuforia.com/library/articles/Solution/How-To-Migrate-a-Unity-Project

 
When saving script, report  error .... namespaces,.....Parse error....?  java,C#, using Vuforia;....
 
Where is my mistake? Can anyone provide a functionally scrypt?
I need CONTINUOUS_AUTOFOCUS after app starts without Vuforia UI.

My setup: PC, Win 8.1, Unity3D Pro 4.6.3, Android Pro, uScript, Vuforia  4, Image Target, for Mobile Android OS

Camera Focus Modes

March 9, 2015 - 12:13pm #6

You're welcome.

Camera Focus Modes

March 9, 2015 - 10:15am #5

Hi AlessandroB,

Thank you very much, this is exactly what I needed, everything works !

It can be added to the Clasic plan payment. /50 USD/

 

Camera Focus Modes

March 9, 2015 - 8:28am #4

This is a full example (just tested on Unity 4.6.3 with Vuforia 4.0.103 Unity extension package, on a Windows PC):

- create Scene

- import vuforia-unity-mobile-android-ios-4-0-103.unitypackage

- remove MainCamera

- add ARCamera to scene (drag it from Qualcomm Augmented Reality / Prefabs folder in Assets)

- create C# script called "FocusMode.cs"

- attach FocusMode script to ARCamera object in your scene

- copy-paste the following code snippet into the script above:

using UnityEngine;
using System.Collections;
using Vuforia;

public class FocusMode : MonoBehaviour {

	private bool mVuforiaStarted = false;

	// Use this for initialization
	void Start () {
		QCARAbstractBehaviour qcar = (QCARAbstractBehaviour)FindObjectOfType( typeof(QCARAbstractBehaviour) );
		if (qcar) {
			qcar.RegisterQCARStartedCallback( OnQCARStarted );
		}
		else {
			Debug.Log ("Failed to find QCARBehaviour in current scene");
		}
	}

	private void OnQCARStarted()
	{
		Debug.Log ("Vuforia has started.");
		mVuforiaStarted = true;

		// Enable focus mode:
		bool autofocusOK = CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
		if (autofocusOK) {
			Debug.Log ("Successfully enabled Continuous Autofocus mode");
		}
		else {
			// set a different focus mode (for example, FOCUS_NORMAL):
			CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_NORMAL);

			// Other possible options:
			// CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_MACRO);
			// CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_INFINITY);
		}
	}
}

- Build and run on Android device.

 

 

Camera Focus Modes

March 9, 2015 - 6:10am #3

Hi AlessandroB,

Thanks for your help, but me it does not work. /stil Parsing error/ I ask this for the second time. I have to accelerate.

I have a "Classic plan" Please send functional script,scene.., /as you advised/ , with my requirements / CONTINUOUS_AUTOFOCUS after app starts without Vuforia UI/ and your company can receive further 50 USD from my Card. /tax for my stupidity/ If it really works, it should not be problem for you.

If it really does not work, /Your advice/ I will demand the money back.

Thank you very much

 

My setup: PC, Win 8.1, Unity3D Pro 4.6.3, Android Pro, uScript, Vuforia  4, Image Target, for Mobile Android OS,

vuforia-unity-mobile-android-ios-4-0-103.unitypackage (28.61 MB)

Camera Focus Modes

March 9, 2015 - 12:10am #2

The article you refer to :

https://developer.vuforia.com/library//articles/Solution/Camera-Focus-Modes

contains this snippet:

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

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

Just copy paste it into a method of  a C# script.

Also, you need to add this line 

    using Vuforia;

at the top of the script.

 

Topic locked