C++ Java Unity
Java Reference
CameraDevice Class Reference

Detailed Description

Provides access to the device's built-in camera.

The CameraDevice is a singleton, accessible via CameraDevice::getInstance() after Vuforia::init() has succeeded.

It provides control over the camera lifecycle (init(), deinit(), start(), and stop()), frame size and FPS (selectVideoMode()), torch (if available) (setFlashTorchMode()), and autofocus (setFocusMode()).

It also provides access to advanced camera properties such as ISO and exposure compensation (setField()). See CameraField for more details.

The CameraDevice needs special handling if you respond to suspend and resume events, such as when your app is sent to the background on a mobile device. See Vuforia::init() for more details.

Classes

class  CAMERA_DIRECTION
 
class  FOCUS_MODE
 
class  MODE
 

Public Member Functions

boolean equals (Object obj)
 
boolean init ()
 Initialize the camera. More...
 
boolean init (int camera)
 Initialize the camera with a specific direction. More...
 
boolean deinit ()
 Deinitialize the camera. More...
 
boolean start ()
 Start the camera. More...
 
boolean stop ()
 Stop the camera. More...
 
int getNumVideoModes ()
 Get the number of available VideoModes. More...
 
VideoMode getVideoMode (int nIndex)
 Get a specific VideoMode. More...
 
int getCameraDirection ()
 Get this camera's direction (i.e. More...
 
boolean selectVideoMode (int index)
 Tell the CameraDevice to use a particular VideoMode. More...
 
CameraCalibration getCameraCalibration ()
 Get camera calibration data (DEPRECATED). More...
 
boolean setFlashTorchMode (boolean on)
 Enable/disable torch mode if the device supports it. More...
 
boolean setFocusMode (int focusMode)
 Set a particular focus mode, or trigger a single autofocus event. More...
 
int getNumFields ()
 Get the number of CameraFields. More...
 
boolean getCameraField (int index, CameraField field)
 Get a particular CameraField. More...
 
boolean getFieldInt64 (String key, long[] value)
 
boolean getFieldFloat (String key, float[] value)
 
boolean getFieldBool (String key, boolean[] value)
 
boolean getFieldInt64Range (String key, long[] intRange)
 
boolean setField (String key, String value)
 Write a camera field value. More...
 
boolean setField (String key, long value)
 
boolean setField (String key, float value)
 
boolean setField (String key, boolean value)
 
boolean setField (String key, long[] intRange)
 
String getFieldString (String key)
 

Static Public Member Functions

static CameraDevice getInstance ()
 Get the CameraDevice singleton instance. More...
 

Member Function Documentation

boolean equals ( Object  obj)
static CameraDevice getInstance ( )
static

Get the CameraDevice singleton instance.

The singleton instance is available immediately after Vuforia::init() has succeeded.

It is no longer available after calling Vuforia::deinit().

boolean init ( )

Initialize the camera.

Note: This method must be handled carefully as part of your application's lifecyle. See the "Lifecycle of a Vuforia app" section on the main Vuforia reference page for more information. Lifecycle of a Vuforia app

Returns
true if the camera was initialized, or false on failure (check application logs for details).
boolean init ( int  camera)

Initialize the camera with a specific direction.

(DEPRECATED) Note: This method must be handled carefully as part of your application's lifecyle. See the "Lifecycle of a Vuforia app" section on the main Vuforia reference page for more information. Lifecycle of a Vuforia app

Parameters
cameraThe camera to initialize. If your device has only one camera, pass CAMERA_DIRECTION_DEFAULT.
Returns
true if the camera was initialized, or false on failure (check application logs for details).
Deprecated:
This method has been deprecated. It will be removed in an upcoming Vuforia release. Use CameraDevice::init() instead.
boolean deinit ( )

Deinitialize the camera.

Release any resources created or used by the camera.

Note: This method should not be called during the execution of the UpdateCallback

Note: This method must be handled carefully as part of your application's lifecyle. See the "Lifecycle of a Vuforia app" section on the main Vuforia reference page for more information. Lifecycle of a Vuforia app

Returns
true on success, otherwise false (such as if this method is called during execution of the UpdateCallback; check application logs for details).
boolean start ( )

Start the camera.

This method starts the process of delivering frames from the camera to Vuforia. The CameraDevice must have been initialized first via a call to init().

Depending on the type of the camera it may be necessary to perform certain configuration tasks after calling init() before it can be started (such as selectVideoMode() and/or specific calls to setField()).

Note: This method must be handled carefully as part of your application's lifecyle. Specifically, it is recommended that you start the camera after starting any required trackers. See the "Lifecycle of a Vuforia app" section on the main Vuforia reference page for more information. Lifecycle of a Vuforia app

Returns
true if the camera was started, otherwise false (check application logs for failure messages).
boolean stop ( )

Stop the camera.

Stop the delivery of frames from the camera to Vuforia.

Since the camera can consume a lot of power, you may want to use this method to suspend Vuforia when it is not actively required, such as when the user is doing non-AR/VR tasks in your app.

Note: This method must be handled carefully as part of your application's lifecyle. Specifically, it is recommended that you stop the camera before stopping any running trackers. See the "Lifecycle of a Vuforia app" section on the main Vuforia reference page for more information. Lifecycle of a Vuforia app

Returns
true if the camera was stopped, otherwise false (check application logs for failure messages).
int getNumVideoModes ( )

Get the number of available VideoModes.

This is device specific and can differ between mobile devices or operating system versions.

VideoMode getVideoMode ( int  nIndex)

Get a specific VideoMode.

Parameters
nIndexThe VideoMode to get, in the range 0..getNumVideoModes()-1
Returns
The requested VideoMode.
int getCameraDirection ( )

Get this camera's direction (i.e.

front-facing or back-facing).

boolean selectVideoMode ( int  index)

Tell the CameraDevice to use a particular VideoMode.

Note: This method can only be called when the camera is initialized but not started.

If this method is not called, Vuforia will select a default video mode.

To switch video modes after the camera has been started, call stop(), then deinit(), then init(), then selectVideoMode() with the new mode, then start().

Note: Calling this method changes the RenderingPrimitives returned by Device::getRenderingPrimitives(). If you have a cached copy of the RenderingPrimitives, you will need to call Device::getRenderingPrimitives() again to get an updated copy.

Parameters
indexThe VideoMode to set, in the range 0..getNumVideoModes()-1.
Returns
true if the video mode was selected, otherwise false.
CameraCalibration getCameraCalibration ( )

Get camera calibration data (DEPRECATED).

Deprecated:
This method has been deprecated. It will be removed in an upcoming Vuforia release. Use State::getCameraCalibration() instead.
boolean setFlashTorchMode ( boolean  on)

Enable/disable torch mode if the device supports it.

Returns
true if torch mode was turned on or off as requested, otherwise false.
boolean setFocusMode ( int  focusMode)

Set a particular focus mode, or trigger a single autofocus event.

Note: Not all focus modes are supported on all devices.

You can trigger a single autofocus event using FOCUS_MODE_TRIGGERAUTO. Note that doing so may interrupt FOCUS_MODE_CONTINUOUSAUTO if that mode is currently set.

Parameters
focusModeThe focus mode to set. See FOCUS_MODE for a list of possible values.
Returns
true if the focus mode was set as requested, otherwise false.
int getNumFields ( )

Get the number of CameraFields.

Note: This may not be the complete set of camera fields available on this device.

Note: Some keys may not be supported on every device.

boolean getCameraField ( int  index,
CameraField  field 
)

Get a particular CameraField.

Parameters
indexThe index of the field to get, in the range 0..getNumFields()-1.
fieldOn return, will be populated with the requested field data.
Returns
true if the requested CameraField could be got, otherwise false.
boolean getFieldInt64 ( String  key,
long[]  value 
)
boolean getFieldFloat ( String  key,
float[]  value 
)
boolean getFieldBool ( String  key,
boolean[]  value 
)
boolean getFieldInt64Range ( String  key,
long[]  intRange 
)
boolean setField ( String  key,
String  value 
)

Write a camera field value.

Parameters
keyKey for the value to write. Must match one of CameraField::mKey as returned from getCameraField().
valueThe value to write.
Returns
true on success, false on failure or if the requested key could not be found.
boolean setField ( String  key,
long  value 
)
boolean setField ( String  key,
float  value 
)
boolean setField ( String  key,
boolean  value 
)
boolean setField ( String  key,
long[]  intRange 
)
String getFieldString ( String  key)