Get Started         Best Practices         Developer Guide         FAQ        
Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Check if tracking is lost

Jochem Rommens Jun 16, 2015

Hi,

I am creating an app with Cordova and the CraftAR Cordova plugin.

The CraftAR scanner is successfully implemented.
I have an overlay with a bar that tells the user to tap the screen to start scanning.
When they tap the screen the finder is started and when AR is found the bar fades out (so the user doesn't get distracted when watching the video).
Now when the user takes it's camera off the image the bar should fade back in, but this part is not working yet.

The problem is that I can't find a way to know when the tracking is lost.
Is there a way to send a message back to the Javascript part when the scanner loses the tracking of an image?

I tried adjusting the code of the Cordova plugin (for iOS) but couldn't get it to work.


( Agent )
Luis Martinell

Jun 16, 2015

Hello,

The Cordova plugin is a bit limited in terms of AR features. We have plans to improve it in the future but we are open to contributions. The plugin is based on the public CraftAR SDK so, anyone can extend it to add features that the SDK offers but the plugin does not. What are the problems you are experiencing to add that feature?

0 rated
Jochem Rommens

Jun 18, 2015

Hello Luis,

Adding features from the SDK to the plugin is not really the problem at the moment.

The problem mainly lies with the SDK itself.
I can't find a way inside the SDK to know if the tracking of an image is lost.

Like in your CraftAR app, where the user is shown a pop-up "Scan again to load the scene".
How do you know when to show that message?
0 rated
( Agent )
Luis Martinell

Jun 18, 2015

Hi Jochem,

You need to extend the CraftARItemAR and implement the trackingStarted and trackingLost methods.

http://catchoom.com/documentation/augmented-reality-sdk/ios-augmented-reality-sdk/classes/

then create an instance of your extended itemAR. In order to have the SDK create instances of your ARItems instead of the superclass, you need to add this to the ARItem class as well:

+ (CraftARItem*) itemFromJSON:(id)json {
if ( [CraftARItem itemTypeFromJSON:json] == ITEM_TYPE_RECOGNITION) {
return [[CraftARItem alloc] initWithJSONObject:json];
} else { // type == ITEM_TYPE_AR
NSLog(@"Here you can create your custom extended CatchoomARItem");
return [[MyARItem alloc] initWithJSONObject:json];
}
}

And ask the SDK to use your ARItem class to create the items upon recognition (when setting up the view controller):

_cloudRecognition = [[CraftARSDK sharedCraftAR] getCloudRecognitionInterface]; _cloudRecognition.cloudRecognitionItemClass = [MyARItem class];

We are planning to make it easier for future versions of the SDK but right now this is what you need to get tracking events.

Best regards,

Luis

0 rated
Paul Sturgess

Jul 23, 2015

I have this working nicely for iOS.

How would it be achieved for Android?

I can see: CraftARItem.getItemTypeFromJSONObject(JSONObject json)
0 rated
( Agent )
Luis Martinell

Jul 23, 2015

That would be to extend entire AR Items. For extending contents you need to set the ContentFactory class like this:

CraftARItemAR.setContentFactory(new MyCraftARTrackingContentFactory());

With your own implementation, here’s an example:

public class MyCraftARTrackingContentFactory extends CraftARTrackingContentFactory {

public int mContentsVersion = 1;

/**
* Returns a {@link CraftARTrackingContent} of the type specified in the JSON object.
* @throws CraftARSDKException
*/
public CraftARTrackingContent contentFromJSONObject(JSONObject object) throws CraftARSDKException {
int type=-1;

type = CraftARTrackingContent.contentTypeFromJSON(object);

CraftARTrackingContent content = null;

switch (type) {
case CraftARTrackingContent.ContentType.CONTENT_TYPE_IMAGE_BUTTON:
content = new MyImageButtonContent(object);
break;
default:
return super.contentFromJSONObject(object);
}

return content;
}

}

1 rated
Alan Pennell-Smith

Jul 23, 2015

Hi Luis,

Thanks for the rapid response. Is there a trackingLost equivalent on Android to user/override? If so, is there any examples anywhere?

Thanks

Al
0 rated
( Agent )
Luis Martinell

Jul 23, 2015

For Android, you need to create your own items as well using the ItemFactory class. You need to set it on the CloudRecognition object:

mCloudRecognition.setItemsFactory(new MyItemFactory()); //Set your items factory

Your items factory would be something like this:

public class MyItemFactory extends CraftARItemFactory{

public CraftARItem itemFromJSONObject(JSONObject object) throws CraftARSDKException {
int itemType = CraftARItem.getItemTypeFromJSONObject(object);
switch (itemType) {
case CraftARItem.ITEM_TYPE_RECOGNITION_ONLY:
return new CraftARItem(object);
case CraftARItem.ITEM_TYPE_AR:
return new MyItem(object);
default:
return null;
}
}
}

Then you will be able to receive the tracking events in your custom item:

public class MyItem extends CraftARItemAR{

boolean mIsTracking=false;
public MyItem(JSONObject json) throws CraftARSDKException {
super(json);
//Parse your fields here
}

@Override
protected void trackingStarted(){
// call super
super.trackingStarted();

// your code here

}

@Override
protected void trackingLost(){
// your code here

// call super

super.trackingLost();
}
}

0 rated
Paul Sturgess

Jul 23, 2015

Thanks that's brilliant!
0 rated

Post Your Public Answer

Your name (required)
Your email address (required)
Answer (required)

Couldn't find what you were looking for?

support@catchoom.com
https://cdn.desk.com/
false
catchoom
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete