gausam / yoti-face-capture-ios

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

YotiFaceCapture

YotiFaceCapture provides a simplified way of capturing a face. It performs face detection from the front facing camera, analyses those frames and produces an optimised cropped image of the captured face.

Requirements

  • iOS 12.0+
  • Swift 5.3+

Installation

Make sure you've installed and are running the latest version of:

CocoaPods

Add the following to your Podfile and run pod install from its directory:

platform :ios, '12.0'

target 'TargetName' do
  use_frameworks!
  pod 'YotiFaceCapture'
end

Integration

1. Import frameworks

Import the framework in your implementation:

import YotiFaceCapture

2. Create FaceCaptureViewController

Fetch FaceCaptureViewController from framework and set delegate

let faceCaptureViewController = FaceCapture.faceCaptureViewController()
faceCaptureViewController.delegate = self

3. Start camera feed and analysis

Start the camera feed

faceCaptureViewController.startCamera()

Start the analysis

faceCaptureViewController.startAnalyzing(withConfiguration: .default)

Whenever required, both camera feed and analysis process can be stopped

faceCaptureViewController.stopCamera()
faceCaptureViewController.stopAnalyzing()

4. Receive framework state and analysis results

Conform to FaceCaptureViewDelegate

func faceCapture(didTransitionToState state: FaceCaptureState) {
    switch state {
        case .success(.cameraReady):
            break
        case .success(.analyzing):
            break
        case .success(.cameraStopped):
            break
        case .failure(let error):
            break
    }
}

func faceCapture(originalImage: UIImage?, didResult result: FaceCaptureResult) {
    switch result {
        case .success(.validFrame(let information)):
            break
        case .failure(let error):
            break
    }
}

5. Customize framework configuration

Provide a FaceCaptureConfiguration instance when calling the startAnalyzing method

let faceCaptureConfiguration = FaceCaptureConfiguration(scanningArea: view.frame,
                                                        imageQuality: .medium,
                                                        validationOptions: [.faceNotStraight])
faceCaptureViewController.startAnalyzing(withConfiguration: faceCaptureConfiguration)    

The validation options available are:

case eyesNotOpen
case faceNotStraight
case faceNotStable(requiredFrames: Int)

About

License:MIT License