Developer Guide

Tutorial: Use Cloud Image Recognition on Android with the CraftAR SDK

Developer Guide

Dec 22, 2020

Catchoom Team

, ,

This section applies the following SDKs:

  • Augmented Reality SDK v4+
  • Cloud Image Recognition SDK v3.0+
  • On-device Image Recognition SDK v1.1+

Are you still using an older version? Previous versions of the SDKs will not receive updates anymore. If you need help transitioning to the newer version, you can get support through our support channel.

An Image Recognition app using the Android native SDK can be implemented following two steps. First, you need to set up the CraftARActivity and then you can run image recognition and parse the results for each item that is recognised.

If you want to see an example that implements Cloud Image Recognition using the Augmented Reality SDK, take a look at the open source samples available in our Github repository: https://github.com/Catchoom/craftar-example-android

Set up the SDK in your CraftARActivity

Once you have set up the CraftARSDK into your Android project, it’s time to implement the CraftARActivity that will show the experience.
The following is an example for an app that uses CraftAR’s Cloud Image Recognition.

1. Create a CraftARCameraView in your layout. This is the view where the camera frames will be drawn.

2. Make your Activity extend from CraftARActivity

You will have to implement the methods onPostCreate(), onPreviewStarted(), and onCameraOpenFailed(). Obtain the CraftARSDK instance and start the camera capture:

3. Obtain and configure the CraftARCloudRecognition instance

Once the CraftARSDK is initalised, you can get an instance of the CraftARCloudRecognition. To perform image recognition, you will have to implement the SetCollectionListener and CraftARSearchResponseHandler interfaces. For simplicity, we will implement them in the same Activity, so everything is in place. Call setCollection() to configure the SDK to your with the collection pointed by your collection token.

4. Do the Image Recognition request and parse the results

The CraftARSDK class manages the search modes (the Finder Mode or Single Shot Mode) and forwards the events to the assigned SearchController. When a response is found, the CraftARCloudRecognition instance will notify the CraftARSearchResponseHandler (in this case our CraftARActivity) with the search results.

You can scan in the two modes described below

Option A. Use Single Shot Mode to take a single picture

You can call singleShotSearch to perform a search with a single image. This method sends a single query to CraftAR’s Cloud Image Recognition. The response to that query triggers searchResults. You could for instance call the following function once the collectionReady callback has been received:

and then the implementation of searchResults() should parse the results and restart the camera.

Option B. Use Finder Mode for continuous scanning

You can call startFinder to start searching continuously without user intervention. This method sends queries at a controllable rate to CraftAR’s Cloud Image Recognition. For every query, the response triggers searchResults.
You could for instance call the following function once the collectionReady callback has been received:

and then the implementation of searchResults() should parse the results.

Related Posts in Developer Guide