Developer Guide

Tutorial: How to use Cloud Image Recognition on iOS with CraftAR

icon Date Developer Guide

icon Date Dec 22, 2020

icon author Catchoom Team

icon folder , ,

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 iOS native SDK can be implemented following two steps. First, you need to set up the UIVIewController and then you can run image recognition and parse the results for each item that is recognized.
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-ios

Set up the SDK in your UIViewController

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

1. Adopt CraftARSDKProtocol in your UIViewController

Adopt the CraftARSDKProtocol and the SearchProtocol in your UIViewController.

2. Get the instance of the CraftARSDK and the CloudRecognition

Once the view is loaded, you can get an instance of the CraftARSDK, the CloudRecognition and set up the CloudRecognition.

3. Start the VideoCapture

Once the view is loaded and will appear, you can initialize the VideoCapture module of the CraftARSDK with a specific UIView from your Storyboards.

Note: the ‘videoPreviewView’ you provide will be loaded with a rendering view and no other subviews will be displayed for it. If you need to display other UIViews as part of MyViewController, add them to self.view of MyViewController (i.e. at the same level as ‘videoPreviewView’).

4. Set up the Search controller

Once the VideoCapture module is ready, it performs a callback to didStartCapture. Here you can set up the CloudRecognition interface as the SearchController for the SDK. The SDK manages the Single shot and Finder Mode searches with the frames and pictures from the camera. At this moment, it is also worth to set the token of the collection that you want to search through when performing Cloud Image Recognition.

Implementing the Image Recognition request and parsing the results

Once your ViewController has the necessary protocol and instance of CloudRecognition, it’s time to add code to start scanning the real world.
The SDK class manages the search modes (the Finder Mode or Single Shot Mode) and forwards the events to the assigned search controller delegate, in this case this is the Cloud Recognition instance. When a response is found, the Cloud Recognition will notify its delegate, your ViewController.
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 didGetSearchResults. You could for instance call the following function once the Collection token has been set:

and then the implementation of didGetSearchResults should parse the results.

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 didGetSearchResults.
You could for instance call the following function once the Collection token has been set:

and then the implementation of didGetSearchResults should parse the results.

Related Posts in Developer Guide