Creating a new Xcode project
The following steps are required to implement visage|SDK functionality when starting a brand new project from scratch.
To enable visage|SDK tracking functionality in new projects the additional frameworks, libraries and files need to be
added to the Xcode project.
After creating a new Xcode project the first step is to add necessary iOS frameworks:
- From the Project navigator select the root item (project name).
- In the right window from the TARGETS section select your target.
- Select Build Phases and open Link Binary With Libraries section.
- Click the Add (+) button and add following frameworks and libraries:
- AVFoundation.framework (Visage Tracker Demo)
- CoreGraphics.framework (Visage Tracker Demo, Face Detect Demo)
- CoreMedia.framework (Visage Tracker Demo)
- CoreVideo.framework (Visage Tracker Demo)
- ImageIO.framework (Visage Tracker Demo)
- QuartzCore.framework (Visage Tracker Demo)
- OpenGLES.framework (Visage Tracker Demo)
- MobileCoreServices.framework (Visage Tracker Demo, Face Detect Demo)
- UIKit.framework (Visage Tracker Demo, Face Detect Demo)
- libz.tbd (Visage Tracker Demo)
- Press Add Other... button and select visage|SDK libraries (from visageSDK-iOS/lib folder):
- libVisageVision.a
- libVisageGaze.a
- libVisageAnalyser.a
- TFPlugin.framework
- TFPlugin-simulator.framework (optional; for iOS simulator architectures)
The second step is to modify project settings:
- From the Project navigator select the root item (project name).
- Select Build Settings.
- Set the "Enable Bitcode" option to "No".
- Set "Deployment Target" to 11.0.
- Find the "Preprocessor Macros" setting and add the following two: VISAGE_STATIC and IOS
- Find the "Other Warning Flags" setting and add the following: -Wno-comment
-
Find the "Header Search Paths" settings and add the following paths (the visageSDK-iOS path should be relative
to the project path):
- visageSDK-iOS/include
- visageSDK-iOS/dependencies/OpenCV-iOS/include
- visageSDK-iOS/dependencies/OpenCV-iOS/include/opencv
- The TFPlugin framework must be embedded into the project. To do this, go to Targets-><target-name>->General->Frameworks, Libraries and Embedded Content. Set TFPlugin.framework to "Embed & Sign".
- Find the "Runpath Search Paths" setting and add the following: @executable_path/Frameworks
Note: Once you link with iOS 10 you must declare access to any user private data types (camera, photos, microphone, etc.). You do this by adding a usage key to your app’s Info.plist together with a purpose string.
The third step is to add visage|SDK required resources:
- Create a new group called Resources in the Project navigator by right clicking on the project root item and
selecting New Group from the pop-up menu.
-
Add the following files from Samples/data folder by dragging and dropping them into newly created Resources
group, a dialog window will appear. In this window, select the "Create folder references for any added
folders":
- Facial Features Tracker.cfg
- vfa, vfr and vft folders containing the data files
- This step is optional. After requesting and receiving license key file add it to the project by dragging and dropping it into previously
created Resources group. Also, please read the section Including the License Key File in your application in the Registration and Licensing page.
The fourth step is to modify precompiled header file (.pch file) and add "#include <cv.h>" before and iOS frameworks
#import commands.
Note: do not forget to add license initialization code before any calls to visage|SDK, for example see Including the
License Key File in your application project and code section.
Device-specific configuration selection
Due to differences in performance, cameras and screens between different iOS devices, it is highly recommended to use tracking configurations that are optimized for each device. This ensures optimal tracking performance on each device.
Both sample projects in visage|SDK incorporate automatic configuration selection based on detected device. There are different ways of detecting specific device: the code for configuration selection on native applications is found in TrackerWrapper.mm file in the Visage Tracker sample project, while code for Unity applications is found in Tracker.cs in the Visage Tracker Unity sample project.
Example code as is present in TrackerWrapper.mm (Visage Tracker sample):
NSString* deviceType = [UIDeviceHardware platform];
if ([deviceType hasPrefix:@"iPhone5"]) //iPhone 5
tracker = new VisageTracker("Facial Features Tracker - Low.cfg");
else
tracker = new VisageTracker("Facial Features Tracker - High.cfg"); // all other devices
Example code as is present in Tracker.cs (Visage Tracker Unity sample):
//Tracker.cs, Visage Tracker Unity sample
string config = "Head Tracker.cfg";
It is highly recommended to use such code in all applications.
Note: To make applications future-proof, a fallback default configuration that covers all other cases should always be added.