Ver-ID Core
The Ver-ID Core framework does face detection, face recognition and user management. The default implementation uses Core Data to store user’s face templates.
Installation
To create Ver-ID environment you will need a valid API secret for your app’s bundle ID. Please contact a member of the Applied Recognition team to obtain it.
Once you obtain the API secret for your project add it to your app’s Info.plist file under the key com.appliedrec.verid.apiSecret
:
<key>com.appliedrec.verid.apiSecret</key>
<string>[your API secret]</string>
Your app will also need to contain a directory with resources needed for Ver-ID face detection. Clone the repository into a VerIDModels folder in your project and add it as a folder reference to your Xcode project.
As of version 1.2.2 VerIDModels are packaged into the VerIDCore.framework.
Usage
The following example creates an instance of VerID
and attempts to detect a face in an image.
import UIKit
import VerIDCore
class MyClass: VerIDFactoryDelegate {
func detectFaceInImage(_ image: CGImage, withOrientation orientation: CGImagePropertyOrientation) {
// Create VerID image from the CGImage and orientation
let verIDImage = VerIDImage(cgImage: image, orientation: orientation)
// Create VerIDFactory instance
let verIDFactory = VerIDFactory()
// Here you can set the factory's faceDetectionFactory, faceRecognitionFactory or userManagementFactory properties if you don't wish to use the defaults
// Set the factory's delegate, which will receive a callback if the VerID instance creation fails
verIDFactory.delegate = self
// Create an instance of VerID
verIDFactory.createVerID { [weak self] verID in
do {
// Detect faces in the Ver-ID image
let faces = try verID.faceDetection.detectFacesInImage(verIDImage, limit: 1, options: 0)
if faces.isEmpty {
// No face detected in the image
return
}
// Convert faces to faces that can be used for face recognition
let recognizableFaces = try verID.faceRecognition.createRecognizableFacesFromFaces(faces, inImage: verIDImage)
guard let face = recognizableFaces.first else {
// This will not be reached as faces weren't empty
return
}
// Face can be used for face recognition
} catch {
// Face detection or recognition failed
}
}
}
// MARK: - VerIDFactoryDelegate method
func veridFactory(_ factory: VerIDFactory, didFailWithError error: Error) {
// Something went wrong. Inspect the error to find out more
}
}