View
Integration of MobaiBiometric View with plain camera feed
This example shows how to integrate the Biometric Capture Session into your project. The Biometric Capture Session extracts a frame collection from the camera preview.
Create View inside ViewController.
After finishing the import of .xcframework inside the project, you can import the library inside the swift file.
import MobaiBiometric
In the UI for this example app, we use the following:
Create view
private var mbCaptureSessionView: MBCaptureSessionView
Initialisation view with MBCaptureSessionOptions
public init() {
self.options = MBCaptureSessionOptions()
self.mbCaptureSessionView = MBCaptureSessionView(options: self.options)
}
Setup View Constraints
view.addSubview(takePictureButton)
NSLayoutConstraint.activate([
mbCaptureSessionView.topAnchor.constraint(equalTo: view.topAnchor),
mbCaptureSessionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
mbCaptureSessionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
mbCaptureSessionView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
Starts Camera if camera permissions are granted
public override func viewWillAppear(_ animated: Bool) {
mbCaptureSessionView.onStartCapturing()
}
Stop Capturing
public override func viewWillDisappear(_ animated: Bool) {
mbCaptureSessionView.onStopCapturing()
}
Adding delegate and implementing the delegate inside View Controller
mbCaptureSessionView.delegate = self
extension ExampleViewController: MBCaptureSessionDelegate { }
Delegate
onInitializing Is executed when the camera it's started successfully
func onInitializing() { }
onValidation gives you data about the face position @param faceStatus is an enum that sends information about the face
func onValidation(_ status: DetectedFaceStatus)
onCountDown tells the time count down before capturing the image(This method is activated when you are using Automatic Capturing) @param time returns seconds of countdown in UI
func onCountDown(time: Int)
onCapturing is when the user starts capturing the image process
func onCapturing()
onCaptureProgress shows the progress of the process until it reaches completion. @captureProgressCounter progress between 0.0 till 1.0
func onCaptureProgress(captureProgressCounter: Float)
onSuccess is executed for MBCaptureSession class when the capture session is successfully finished @param result contains a list of frames.
func onSuccess(result: MBCaptureSessionResult)
onFailure is executed for MBCaptureSessionService class when the camera can not be @param error describes whether there is a camera or face failure
func onFailure(error: MBCaptureSessionError)
Options
Inside the library, we have some options for changing the behaviour of capturing data:
Variable Name | Type | Default Value |
---|---|---|
autoCaptureEnabled | boolean | true |
numberOfFramesBeforeCapture | number | 10 |
numberOfFrameToCollect | number | 3 |
frameInterval | number | 10 |
timeBeforeAutomaticCapture | number | 4 |
faceQualityEnabled | boolean | false |
isDebugging | boolean | false |
faceStatusTexts | MBFaceStatusTexts | MBFaceStatusTexts() |
previewScaleType | PreviewScaleType | .fit |
showCountdownTimerLabel | boolean | false |
countdownLabelText | string | 'Hold Still' |
showProgressBar | boolean | false |
showFaceStatusLabel | boolean | false |
targetResolutionPad | MBTargetResolution | .hd1280x720 |
cameraPosition | CameraPostion | .front |
payloadOptimization | boolean | false |
Description
- autoCaptureEnabled
- tells whether the capture is automatic or manual:
- Automatic: Automatically take an image with a specific time that you can configure with timeBeforeAutomaticCapture
- Manual: Manually take an image with the help of a button that the library shows
- tells whether the capture is automatic or manual:
- numberOfFramesBeforeCapture
- describes a number of the frame that the library capture before starting the process of capturing
- numberOfFrameToCollect
- describes the number of frames to collect during the capture session.
- frameInterval
- After collecting the first frame, is the number of frames to skip before collecting a frame.
- faceQualityEnabled
- to capture an image in a higher resolution
- timeBeforeAutomaticCapture
- number of seconds that the user needs to wait in automatic capture
- isDebugging
- If it is set to false will just display the overlay on the top of the camera. If it is set to true will display all components available ont the top of the camera(timer text, progress bar and face status text).
- cameraPosition
- option to select the side of the camera|
- Front
- Back
- option to select the side of the camera|
- presentedDismissButtonEnabled
- option to add or remove the dismiss button at the top (This works only with the ViewController approach)
- targetResolutionPad
- option to change the resolution of the camera
- hd1280x720(default option)
- hd1920x1080
- hd4K3840x2160
- qHD960x540
- option to change the resolution of the camera
- previewScaleType
- Fill: Resize the video preview to fill the layer and keep the aspect ratio
- Fit: Resize the video preview to fit inside the layer and keep the aspect ratio
- timerTextViewEnabled
- If it's enabled, it will show a timer text label on the top of the screen
- progressBarViewEnabled
- If it's enabled, it will show the progress bar with the implementation
- faceStatusTextViewEnabled
- If it's enabled, it will show the face status text label
- faceStatusTexts
- Is used to customize or localize the text displayed to the user indicating if the face is in correct position or not.
If no input is provided to
faceStatusTexts
default values are used.
- Is used to customize or localize the text displayed to the user indicating if the face is in correct position or not.
If no input is provided to
- showCountdownTimerLabel
- Is used to show or hide the label displayed during countdown before capture starts.
The text for the countdownLabel can be set using the
countdownLabelText
option.
- Is used to show or hide the label displayed during countdown before capture starts.
The text for the countdownLabel can be set using the
- showProgressBar
- Is used to show or hide the progress bar. The progress bar indicates to the user how far in the capture process we are.
- showFaceStatusLabel
- Is used to show or hide the face status label. The face status label is used to indicate to the user if the face is in the correct position or not.
- countdownLabelText
- Is used to customize the text shown in the countdown label
- payloadOptimization
- It is use to enable or disable the optimization of the payload you send to the backend | reduces the payload size.
MBFaceStatusTexts
- MBFaceStatusTexts class containing the default face status strings
Member | Type | Description |
---|---|---|
faceTooFarAway | string | Text to display when the face is too far away from the camera |
faceTooFarUp | string | Text to display when the face i too far up in the camera |
faceTooFarDown | string | Text to display when the face is too far down in the camera |
faceTooFarLeft | string | Text to display when the face is too far left in the camera |
faceTooFarRight | string | Text to display when the face is too far right in the camera |
faceTooClose | string | Text to display when the face is too close to the camera |
faceNotFound | string | Text to display when no face is found |
tooManyFaces | string | Text to display when too many faces are found in the camera |
validFace | string | Text to display when the face is in a valid position in the camera |
If you have any questions, please contact .....