FaceScannerController

class FaceScannerController : UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate

This FaseScannercontroller is responsiable for active face capture and face capture camera view and handels all the AV capture operation for face scan view

  • The AV capture session used by active and passive liveness

    Declaration

    Swift

    var captureSessionMain: AVCaptureSession?
  • Indicates if the session setup of the AV capture is done or not

    Declaration

    Swift

    var sessionSetupCompleted: Bool
  • AVCaptureDeviceInput for front camera

    Declaration

    Swift

    var frontCameraInput: AVCaptureDeviceInput?
  • AVCaptureDeviceInput for back camera

    Declaration

    Swift

    var backCameraInput: AVCaptureDeviceInput?
  • Indicates the current active capture mode for the face scanner controller

    Declaration

    Swift

    let captureMode: faceCaptureMode
  • The AVCaptureVideoPreviewLayer used to display the camera view

    Declaration

    Swift

    var previewLayer: AVCaptureVideoPreviewLayer?
  • Closure that recieves each captured camera frame when scanning the face

    Declaration

    Swift

    var onFrameCaptured: ((_ image: CMSampleBuffer) -> Void)?
  • Float to ensures circle of the camera if aligned currently on the y axis

    Declaration

    Swift

    var y_pos: CGFloat
  • Indicates the current position of the camera

    Declaration

    Swift

    private let position: AVCaptureDevice.Position
  • Initialize the FaceScannerController

    Declaration

    Swift

    init(captureSessionMain: AVCaptureSession? = nil, frontCameraInput: AVCaptureDeviceInput? = nil, backCameraInput: AVCaptureDeviceInput? = nil, previewLayer: AVCaptureVideoPreviewLayer? = nil, onFrameCaptured: ((CMSampleBuffer) -> Void)? = nil, y_pos: CGFloat = 0.0)

    Parameters

    captureSessionMain

    The main capture session used by active and passive liveness.

    frontCameraInput

    The input for the front camera.

    backCameraInput

    The input for the back camera.

    previewLayer

    The preview layer for the camera view.

    onFrameCaptured

    A closure that is called when a frame is captured.

    y_pos

    The y position of the camera view.

  • Initialize the FaceScannerController

    Declaration

    Swift

    required init?(coder: NSCoder)

    Parameters

    coder

    The coder used to initialize the controller.

  • This method is called after the controller’s view is loaded into memory.

    Declaration

    Swift

    override func viewDidLoad()
  • This method is called when the controller’s view is about to appear.

    Declaration

    Swift

    override func viewWillAppear(_ animated: Bool)

    Parameters

    animated

    A boolean value indicating whether the appearance should be animated.

  • This method is called when the controller’s view is about to disappear.

    Declaration

    Swift

    override func viewWillDisappear(_ animated: Bool)

    Parameters

    animated

    A boolean value indicating whether the disappearance should be animated.

  • For active face capture view we are changing a preview layer to circle

    Declaration

    Swift

    func updatePreviewLayerFrame()
  • Sets up the AVCaptureSession and adds the video preview layer to the view.

    Declaration

    Swift

    func setupCameraForView()
  • captureOutput is called when a new frame is captured by the camera.

    Declaration

    Swift

    func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection)

    Parameters

    output

    The output that captured the frame.

    sampleBuffer

    The sample buffer containing the frame data.

    connection

    The connection used to capture the frame.

  • Triggers onFrameCaptured in a global dispatched queue

    Declaration

    Swift

    func captureFrame(sampleBuffer: CMSampleBuffer)

    Parameters

    sampleBuffer

    The sample buffer containing the frame data.

  • Starts the camera session for face scan. If the camera session is already running, it will not start the session again. If the AVCaptureSession has not been setup, it will setup the session. If the current SDK state is in camera QR scanning mode, it will not start the camera session.

    Declaration

    Swift

    func startCameraSession()
  • Stops the camera session for face scan and sets the AVCaptureSession to nil.

    Declaration

    Swift

    func stopFaceScan()
  • Adjust the zoom level of the camera.

    Declaration

    Swift

    func adjustZoom(scale: CGFloat)

    Parameters

    scale

    The scale factor for zooming.

  • Returns the AVCaptureDevice of the current AVCaptureSession.

    Declaration

    Swift

    func getCurrentCaptureDevice() -> AVCaptureDevice?

    Return Value

    The AVCaptureDevice of the current AVCaptureSession, or nil if no video device is found.