#VisionIQ iOS SDK
IQ Engines provides VisionIQ, an image recognition platform that makes it possible to add visual search to your mobile application. Before diving into the details of how you can integrate the SDK into your iOS application, we give a brief overview of the two engines at the core of VisionIQ: (1) visual search in the cloud, and (2) visual search on mobile devices. You can find more information about VisionIQ on the system overview page.
Visit our developer portal and sign up for an API key. Once you have obtained your API key, you will be able to (1) send images to the VisionIQ cloud for image recognition via the Query API and (2) train the VisionIQ cloud with your own set of images via the Training API. In the iOS SDK search in the cloud is referred to as remote search, as the image processing algorithms are running on VisionIQ's remote servers.
When you send an image to VisionIQ server, it is first analyzed by VisionIQ's computer vision algorithms. The image is matched against IQ Engines' public image dataset, as well as your private image dataset if you have trained the system.
When the computer vision algorithms are not able to recognize your image, then it is sent to VisionIQ's crowdsourcing engine, where a person will manually tag your image. By combining computer vision and crowdsourcing, we are able to provide accurate labels for 100% of images.
The VisionIQ cloud can scale to recognize millions of images. However, if your dataset is small (~100 objects), then the recognition can happen entirely on the mobile device. There is no need for an internet connection as the image isn't sent to the VisionIQ cloud. This makes for a really snappy experience, and quasi-instant results. If you turn on the continuous mode, then frames are continuously grabbed from the camera and matched against the local image dataset, which means that objects can be recognized without the user having to take an action such as pressing a shutter button.
The local dataset is hosted directly on the mobile device. It is not possible at the moment for you to directly generate the image signatures that are necessary for recognition (this "local training" feature is coming soon). To receive the iqedata folder that corresponds to your own set of images, first train VisionIQ server, and then contact us at [email protected].
The VisionIQ iOS SDK is comprised of:
- IQEnginesSDK: The VisionIQ SDK. It contains all the necessary functions to include VisionIQ functionality in your app. The two main classes are:
- The
IQE
class: it contains all the functions for local and remote image recognition. You will use this class when integrating VisionIQ into your app. - The
IQEViewController
class: it is aUIViewController
subclass, and provides an example of a user interface for visual search. It uses theIQE
class.
- The
- ExampleApp: The VisionIQ example application. It provides a good example of how the VisionIQ SDK can be included in a mobile app using the
IQEViewController
class.
Before including the SDK in your existing app, we recommend that you first try building the example app, as this is the best way to get familiar with both the SDK and VisionIQ's capabilities.
Configure the example app by editing the settings defined in the ExampleApp/Example/Config.h file:
IQE_APIKEY
andIQE_SECRET
: your API key and secret obtained after you've signed up for VisionIQ.- remote search
SEARCH_OBJECT_REMOTE
: if set toYES
, remote search is enabled.
- local search
SEARCH_OBJECT_LOCAL
: if set toYES
, local search is enabled if the iqedata folder is present and populated.SEARCH_OBJECT_LOCAL_CONTINUOUS
: if set toYES
, local continuous search is enabled.SEARCH_BARCODE
: detect barcode and QR codes if set toYES
.
Note that the example app does not work with the simulator as it is using the AVFoundation
framework. However, you can run the example app on your iOS device.
- Add the
IQEnginesSDK
folder to your project.
- Add additional frameworks and libraries:
AVFoundation.framework
CoreLocation.framework
CoreMedia.framework
CoreVideo.framework
QuartzCore.framework
libiconv.dylib
- Local search uses the standard c++ library. If the project does not contain c++ source files (.mm or .cpp), link to the standard c++ library by adding
-lstdc++
to "Other Linker Flags" in Build Settings, or link withlibstdc++.dylib
.
- When using local object detection, add the data files to the folder named:
iqedata
at the root of the project. Be sure to create folder references, not groups when adding this folder.
The IQEngines VisionIQ SDK may be configured by setting the following variables in IQEnginesSDK/IQEConfig.h:
IQENGINES_LOCAL_LIB
: If local search is not used, set toFALSE
. IQEnginesSDK/Local/libIQEnginesLocal.a can then be removed from the project.IQE_IMAGE_CAPTURE
: Designates if theIQEImageCapture
class is used byIQE
to provide the image capture functionality. Set toFALSE
if a custom image acquisition scheme will be used.
The steps to use the IQEViewController
class are as follows:
- Import IQEViewController.h and adopt the
IQEViewControllerDelegate
protocol in your view controller header:
#import "IQEViewController.h"
@interface ViewController : UIViewController <IQEViewControllerDelegate>
{
}
- Allocate and initialize an
IQEViewController
object. Set the search type depending on what search is required. Use your IQ Engines API Key and secret if doing remote search:
IQEViewController* vc = [[IQEViewController alloc] initWithParameters:IQESearchTypeRemoteSearch |
IQESearchTypeBarCode
apiKey:@""
apiSecret:@""];
vc.delegate = self;
- Present the view controller via presentModalViewController:animated:
[self presentModalViewController:vc animated:YES];
- Implement the
IQEViewControllerDelegate
delegate methods as necessary. Specifically, theiqeViewControllerDidCancel
method:
- (void) iqeViewControllerDidCancel:(IQEViewController*)controller
{
controller.delegate = nil;
[controller dismissModalViewControllerAnimated:YES];
}
The steps to use the IQE
class are as follows:
- Add an
IQE
class to your view controller and adopt theIQEDelegate
protocol:
#import "IQE.h"
@interface ViewController : UIViewController <IQEDelegate>
{
IQE* iqengines;
}
- Allocate and initialize an
IQE
object in the view controller init method. Set the search type depending on what search is required. Use your IQ Engines API Key and secret if doing remote search:
iqengines = [[IQE alloc] initWithParameters:IQESearchTypeRemoteSearch |
IQESearchTypeBarCode
apiKey:@""
apiSecret:@""];
iqengines.delegate = self;
- Set up the camera preview layer in the view controller viewDidLoad method.
CGRect rect = self.view.layer.bounds;
iqengines.previewLayer.bounds = rect;
iqengines.previewLayer.position = CGPointMake(CGRectGetMidX(rect),
CGRectGetMidY(rect));
[self.view.layer insertSublayer:iqengines.previewLayer atIndex:0];
- Start and stop camera processing in viewWillAppear: and viewDidDisappear: respectively:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[iqengines startCamera];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[iqengines stopCamera];
}
- Capture a still image from the camera by calling the
captureStillFrame
method. Process the image in thedidCaptureStillFrame IQEDelegate
method:
- (IBAction)onCameraButton:(id)sender
{
[iqengines captureStillFrame];
}
- (void)iqEngines:(IQE*)iqe didCaptureStillFrame:(UIImage*)image
{
NSString* qid = [iqengines searchWithImage:image];
}
- Handle the image search result in the
didCompleteSearch IQEDelegate
method:
- (void)iqEngines:(IQE*)iqe didCompleteSearch:(IQESearchType)type
withResults:(NSDictionary*)results
forQID:(NSString*)qid
{
NSLog(@"results:%@", results);
}
- Implement other
IQEDelegate
delegate methods as necessary. - Clean up by adding the following in dealloc:
iqengines.delegate = nil;
[iqengines stopCamera];
[iqengines release];
The image capture features are unavailable on iOS versions before 4.0. However, it is still possible to use the IQE
class with a UIImage.
-
AVFoundation framework must be weak linked to the project. Change the framework from "Required" to "Optional" in the Link Binary with Libraries section of the target Build Phases.
-
Get an image (with UIImagePickerController or other method) and call
searchWithImage
: on theIQE
instance.
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
[iqengines searchWithImage:image];
}
- FAQ
- Contact us at [email protected] if you have any questions!