Configuration
The face capture consists of two components:
MIDFaceView: the camera view. It shows the preview, the detection area and the guidance messages.MIDFaceSDK: the face engine. It detects the face, applies liveness and runs the biometric operation.
Initialisation
Initialise the SDK before using any other component, with the application ID, a token issued by your backend and the full server URL:
- Swift
- Objective-C
MIDSDK.shared.doInitSDK(applicationId: "YOUR_APPLICATION_ID",
authToken: authToken,
serverUrl: "https://{SERVER-URL}/api/v7")
[CMIDSDK.mIDSDK doInitSDKApplicationId:@"YOUR_APPLICATION_ID"
authToken:authToken
serverUrl:@"https://{SERVER-URL}/api/v7"];
Since version 7.0.2, the SDK no longer appends the API version. serverUrl must contain the complete host and path.
The token is valid for 30 minutes. Request it right before the user reaches the capture screen, so that it remains valid during the operation.
Camera view
Build MIDFaceView with the frame it will occupy and add it to your view hierarchy:
- Swift
- Objective-C
let builder = MIDFaceViewBuilder()
builder.set(frame: frame)
let faceView = try builder.build()
MIDFaceViewBuilder *builder = [[MIDFaceViewBuilder alloc] init];
[builder setFrame:frame];
NSError *error;
MIDFaceView *faceView = [builder buildAndReturnError:&error];
The view guides the user in real time to place the face inside the detection area, at the right distance and with suitable lighting. Since version 7.2.1, it also warns about non-frontal faces, sunglasses and faces outside the detection area.
Face engine
Build MIDFaceSDK with MIDFaceSDKBuilder and attach it to the view:
| Option | Description |
|---|---|
targetView | The MIDFaceView that hosts the camera. |
addFeedbackListener | Receives the guidance events. Pass MIDFaceView to display them. |
livenessDetectionMode | Liveness method applied to the capture. See Liveness. |
addLivenessListener | Receives the progress of the liveness check. Pass MIDFaceView to display it. Only applies when a liveness method is set. |
Liveness modes
Liveness is configured once in the engine and applies to every operation it runs.
MIDFaceLivenessDetectionMode | Type | User interaction |
|---|---|---|
headPassiveImage | Passive, on one image. Recommended | The user looks at the camera |
headPassiveVideo | Passive, on a short video | The user looks at the camera for a few seconds |
headMovement | Active | The user moves the head when prompted |
none | No liveness | Face comparison only. Not suitable for authentication |
Keep liveness enabled in every operation, including enrolment. Without it, a photo of another person could be enrolled or verified. See Attack detection.
- Swift
- Objective-C
let builder = MIDFaceSDKBuilder()
builder.targetView(faceView)
builder.addFeedbackListener(faceView)
if livenessMode != .none {
builder.addLivenessListener(faceView)
builder.livenessDetectionMode(livenessMode)
}
let faceSDK = builder.build()
MIDFaceSDKBuilder *builder = [[[[MIDFaceSDKBuilder alloc] init] targetView:faceView] addFeedbackListener:faceView];
if (livenessMode != MIDFaceLivenessDetectionMode.none) {
builder = [[builder addLivenessListener:faceView] livenessDetectionMode:livenessMode];
}
MIDFaceSDK *faceSDK = [builder build];
Run an operation
faceSDK.start(recognitionMode: recognitionMode, parameters: parameters, operationListener: listener)
MIDRecognitionMode | Parameters | Listener | Guide |
|---|---|---|---|
.enrollment | MIDEnrollmentParameters(userId:) | MIDEnrollmentListener | Enrolment |
.verification | MIDVerificationParameters(userId:) | MIDVerificationListener | Verification |
.identification | MIDIdentificationParameters(groupId:) | MIDIdentificationListener | Identification |
In Objective-C, the classes and protocols use the CMID prefix: CMIDRecognitionMode, CMIDVerificationParameters, CMIDVerificationListener and so on.