Skip to content

Commit

Permalink
Updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubdolejs committed Apr 14, 2023
1 parent 3635857 commit 436c796
Showing 1 changed file with 193 additions and 13 deletions.
206 changes: 193 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/AppliedRecognition/Ver-ID-Credentials-iOS-Sample?sort=semver) [![Tests](https://github.com/AppliedRecognition/Ver-ID-Credentials-iOS-Sample/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/AppliedRecognition/Ver-ID-Credentials-iOS-Sample/actions/workflows/main.yml)

# Ver-ID ID Capture Sample

![](ID%20Capture/Assets.xcassets/woman_with_licence.imageset/iStock-466158408.png)

The project contains a sample application that uses Microblink's [BlinkID SDK](https://github.com/BlinkID/blinkid-ios) to scan an ID card. The app uses Ver-ID SDK to detect a face on the captured ID card and compare it to a live selfie taken with the iOS device's camera.
The project contains a sample application that uses Microblink's [BlinkID SDK](https://github.com/BlinkID/blinkid-ios) to scan an ID card. The app uses [Ver-ID SDK](https://github.com/AppliedRecognition/Ver-ID-UI-iOS) to detect a face on the captured ID card and compare it to a live selfie taken with the iOS device's camera.

## Project setup
1. Download and install [CocoaPods](https://cocoapods.org/).
Expand All @@ -19,13 +17,16 @@ The project contains a sample application that uses Microblink's [BlinkID SDK](h
pod install
```
4. Open the generated **ID Capture.xcworkspace** in Xcode.
5. Open the **Signing & Capabilities** tab and change **Team** to your account
6. Click on the **Pods** project, click on **Ver-ID-VerIDUIResources**
7. Navigate to **Signing & Capabilities** and change **Team** to your account

## Adding Ver-ID to your own Xcode project

1. Add **Ver-ID**:

```ruby
pod 'Ver-ID', '~> 2.7'
pod 'Ver-ID', '~> 2.10'
```
into your Podfile and run:

Expand Down Expand Up @@ -60,17 +61,196 @@ The project contains a sample application that uses Microblink's [BlinkID SDK](h
## Adding Microblink to your Xcode project
1. Apply for an API key on the [Microblink website](https://microblink.com/products/blinkid).
2. Add **PPBlinkID** into your Podfile:
```ruby
pod 'PPBlinkID', '~> 5.20'
```
3. Before calling the BlinkID API set your licence key:
2. Open your workspace in **Xcode** and click on your app project
3. Navigate to the **Package Dependencies** tab and under Packages click the + button
4. Enter **https://github.com/BlinkID/blinkid-ios** in the search bar of the dialog that just opened
5. Select **blinkid-ios** in the menu and under **Dependency Rule** select **Up to Next Major Version** and enter 6.1.2
6. Select your project in the **Add to Project** dropdown menu
7. Press the **Add Package** button
8. Before calling the BlinkID API set your licence key:
```swift
import Microblink
import BlinkID
let licenceKey = "keyObtainedInStep1"
MBMicroblinkSDK.sharedInstance().setLicenseKey(licenceKey)
MBMicroblinkSDK.shared().setLicenseKey(key) { error in
// TODO: Handle error
}
```
4. Detailed instructions are available on the [BlinkID Github page](https://github.com/BlinkID/blinkid-ios#getting-started-with-blinkid-sdk)
9. Detailed instructions are available on the [BlinkID Github page](https://github.com/BlinkID/blinkid-ios#getting-started-with-blinkid-sdk)
## Example 1 – Capture ID card
~~~swift
import UIKit
import BlinkID
class MyViewController: UIViewController, MBBlinkIdOverlayViewControllerDelegate {
private var blinkIdRecognizer: MBBlinkIdMultiSideRecognizer?
func captureIdCard() {
let recognizer = MBBlinkIdMultiSideRecognizer()
recognizer.returnFullDocumentImage = true
self.blinkIdRecognizer = recognizer
let settings = MBBlinkIdOverlaySettings()
let recognizerCollection = MBRecognizerCollection(recognizers: [recognizer])
let blinkIdOverlayViewController = MBBlinkIdOverlayViewController(
settings: settings,
recognizerCollection: recognizerCollection,
delegate: self)
guard let recognizerRunnerViewController = MBViewControllerFactory
.recognizerRunnerViewController(withOverlayViewController: blinkIdOverlayViewController) else {
return
}
}
// MARK: - MBBlinkIdOverlayViewControllerDelegate
func blinkIdOverlayViewControllerDidFinishScanning(_ blinkIdOverlayViewController: MBBlinkIdOverlayViewController, state: MBRecognizerResultState) {
if state == .valid {
blinkIdOverlayViewController.recognizerRunnerViewController?.pauseScanning()
DispatchQueue.main.async {
blinkIdOverlayViewController.dismiss(animated: true, completion: nil)
guard let result = self.blinkIdRecognizer?.result else {
return
}
guard let documentImage: UIImage = result.fullDocumentBackImage?.image else {
return
}
// You can pass documentImage to Ver-ID face detection
}
}
}
func blinkIdOverlayViewControllerDidTapClose(_ blinkIdOverlayViewController: MBBlinkIdOverlayViewController) {
blinkIdOverlayViewController.dismiss(animated: true)
}
}
~~~
## Example 2 – Capture live face
~~~swift
import UIKit
import VerIDCore
import VerIDUI
class MyViewController: UIViewController, VerIDSessionDelegate {
var verID: VerID?
lazy var faceDetectionRecognitionWithAuthenticityCheck: VerIDFaceDetectionRecognitionFactory? = {
let detrecFactory = VerIDFaceDetectionRecognitionFactory(apiSecret: nil)
guard let classifierPath = Bundle.main.path(forResource: "license01-20210820ay-xiypjic%2200-q08", ofType: "nv") else {
return nil
}
let classifier = Classifier(name: "licence", filename: classifierPath)
detrecFactory.additionalFaceClassifiers = [classifier]
return detrecFactory
}()
func createVerID() {
if verID != nil {
// Return if Ver-ID is already loaded
return
}
let veridFactory = VerIDFactory()
// To enable authenticity check on supported Canadian ID documents include
// bundle the ID Capture/license01-20210820ay-xiypjic%2200-q08.nv file
// with your app
if let detRecFactory = self.faceDetectionRecognitionWithAuthenticityCheck {
veridFactory.faceDetectionFactory = detRecFactory
veridFactory.faceRecognitionFactory = detRecFactory
}
// Skip the above 4 lines to disable authenticity check
veridFactory.delegate = self
veridFactory.createVerID { result in
switch result {
case .success(let verID):
self.verID = verID
// TODO: This is a good place to enable a button that launches a face capture session
case .failure(let error):
// TODO: Handle error
}
}
}
func startFaceCapture() {
guard let verID = self.verID else {
// TODO: Handle this
return
}
let settings = LivenessDetectionSessionSettings()
let session = VerIDSession(environment: verID, settings: settings)
session.delegate = self
session.start()
}
// MARK: - VerIDSessionDelegate
func didFinishSession(_ session: VerIDSession, withResult result: VerIDSessionResult) {
if let error = result.error {
// TODO: Handle session failure
return
}
guard let face = result.faces(withBearing: .straight).first else {
return
}
// You can use face for comparison
}
}
~~~
## Example 3 - Compare face on ID card with live face
Building on example 1 and 2, you can use the results of the ID capture and liveness detection sessions and compare their faces.
~~~swift
class FaceUtilities {
let verID: VerID
// This must be the same name you used in the Classifier constructor
// (see faceDetectionRecognitionWithAuthenticityCheck in example 2 above)
private let authenticityClassifierName = "licence"
init(verID: VerID) {
self.verID = verID
}
// Compare live face with a face detected in an ID card image
func compareFaceToIDCard(face: RecognizableFace, idCardImage: UIImage) throws -> Float {
// Get an instance of face detection utilities, this will always be available unless
// you supplied your own implementation of face recognition to VerIDFactory
guard let faceDetectionUtilities = verID.utilities?.faceDetection else {
throw FaceUtilitiesError.faceDetectionUtilitiesUnavailable
}
// Detect a face on the ID card
guard let idCardFace: RecognizableFace = try faceDetectionUtilities.detectRecognizableFacesInImage(idCardImage, 1).first else {
throw FaceUtilitiesError.faceNotFound
}
// Compare faces
return try verID.faceRecognition.compareSubjectFaces([face], toFaces: [idCardFace])
}
// Check document authenticity (works with select Canadian documents)
func checkDocumentAuthenticity(idCardImage: UIImage) throws -> Float {
guard let faceDetection = verID.faceDetection as? VerIDFaceDetection else {
throw FaceUtilitiesError.unsupportedFaceDetectionImplementation
}
guard let face: Face = try faceDetection.detectFacesInImage(idCardImage, limit: 1, options: 0).first else {
throw FaceUtilitiesError.faceNotFound
}
return try faceDetection..extractAttributeFromFace(face, image: idCardImage, using: authenticityClassifierName)
}
}
enum FaceUtilitiesError: Error, Int {
case faceDetectionUtilitiesUnavailable
case faceNotFound
case unsupportedFaceDetectionImplementation
}
~~~

0 comments on commit 436c796

Please sign in to comment.