CloudTracker Class
A Tracker represents a Target Collection which is created with
the Target Management Tool.
A Tracker needs to include the binary .wtc targets describing the targets and
needs to be referenced via a URI. The Tracker object is used to reference
specific Trackable2DObjects (the targets inside the target collection).
Trackers can be enabled and disabled. Only one Tracker can be active at a time. The current enabled/disabled state of a Tracker is reflected in the enabled property. Should there be multiple Trackers used in the ARchitect file, the following logic applies to specify the currently active Tracker:
- When a new Tracker is created, it is automatically set to the active one, unless it was created with enabled set to false.
- When a specific Tracker is enabled, it is automatically set to the active one. The previously active Tracker is disabled by the system.
// a CloudTracker referencing a target collection with a specific authentication token var cloudTracker = new AR.CloudTracker("__your_authentication_token__", "__target_collection_id__", { onLoaded: function onLoadedFn() { // enable UI elements to start recognition calls } }); // ... additional code... // to start a single recognition process, call the cloud tracker's recognize function. cloudTracker.recognize(function(recognized, responseData) { if ( recognized ) { // A target image was found in the processed camera frame. // The name of the recognized target can be retrieved from the responseData object. alert('recognized target image: ' + responseData.targetInfo.name); } else { // No target image could be found in the processed camera frame. } });
Constructor
Item Index
Properties
Events
Methods
destroy
()
Destroys the object.
isLoaded
()
Boolean
Returns a boolean value indicating if the tracker has already been successfully loaded.
Returns:
true if the Tracker has successfully loaded, false if the Tracker has not been successfully loaded yet.
recognize
-
onRecognizedCallback
-
onErrorCallback
Starts a single recognition process.
When this function is called, the current camera frame will be send to our servers and processed. Once the Server finishes his work, the onRecognizedCallback will be called.
Parameters:
-
onRecognizedCallback
FunctionA callback function that is called when the SDK received the server response.
This callback has two parameters.- recognized True if a reference image could be found in the current camera image, false otherwise
- recognitionData A JSON object containing a targetInfo object and an optional metadata object.
- targetInfo A JSON object containing the targetName, it's star rating and optional it's physical height in mm
- metadata The custom metadata JSON object that was assigned to a target image during creation.
-
onErrorCallback
Function optionalA callback function that is called when the SDK was unable to contact the cloud recognition server or the server encountered any error during recognition.
This callback has two parameters:- code A number representing the kind of error that occured.
- errorObject A JSON object containing more information about what failed.
startContinuousRecognition
-
interval
-
onRecognizedCallback
-
onErrorCallback
-
onInterruptionCallback
Starts a continuous recognition session.
A active continous recognition session will upload a new camera frame to the server in the specified interval.
Parameters:
-
interval
NumberThe interval in which a new recognition should be started. The minimum value is 500 ms.
-
onRecognizedCallback
FunctionA callback function that is called when the SDK received a server response. See recognize for more information.
-
onErrorCallback
Function optionalA callback function that is called when the SDK was unable to contact the cloud recognition server or the server encountered any error during recognition.
This callback has two parameters:- code A number representing the kind of error that occured.
- errorObject A JSON object containing more information about what failed.
-
onInterruptionCallback
Function optionalA callback function that is called when the interval is set to a number that can not be fullfilled by the current network conditions.
This callback has one parameter: suggestedInterval A number representing a interval that could be used with the current network conditions.
stopContinuousRecognition
()
Stops an active continuous recognition session.
Properties
enabled
Boolean
The current activity state of the Tracker. This property might by changed automatically by the system, in case another Tracker is enabled, causing this Tracker to be disabled. The onDisabled trigger will be called in this case.
onRecognitionError
Function
The function that is called when a single recognition request failed. The property is read-only and can only be set when the recognize or startContinuousRecognition function is called.
onRecognized
Function
The function that is called when a recognition request finished. The property is read-only and can only be set when the recognize or startContinuousRecognition function is called.
physicalTargetImageHeights
Object
Use this option to specify the physical height of a image target that is included in the .wtc file. These options are only necessary if the distanceToUser functionality is used and the .wtc file version is below 4.1. The physical height is expressed in millimeter, and this object contains a map using target names as keys.
src
String
The URI pointing to the referenced target collection. The property is read-only and can only be set on creation.
targetCollectionID
String
The target collection id identifying a specific image target collection. The property is read-only and can only be set on creation.
token
String
The token identifying the user account where the target collection belongs to. The property is read-only and can only be set on creation.
Events
onDisabled
The trigger fires when the Tracker has been disabled by
the system. It does not fire when enabled is set to
false manually.
The trigger is null by default, and will thus result in no action executed when the trigger fires. A developer can add custom functionality by assigning a custom function to onDisabled.
onError
The trigger fires when the Tracker's target collection
could not be loaded. Causes for this might include bad
network connection or a corrupt target collection.
The trigger is null by default, and will thus result in no action executed when the trigger fires. A developer can add custom functionality by assigning a custom function to onError.
onLoaded
The trigger fires when the Tracker's target collection
was successfully loaded. TrackableObjects related to
this Tracker can only be tracked after the Tracker was
successfully loaded.
The trigger is null by default, and will thus result in no action executed when the trigger fires. A developer can add custom functionality by assigning a custom function to onLoaded.