Yoti.FCM 1.2.0

dotnet add package Yoti.FCM --version 1.2.0                
NuGet\Install-Package Yoti.FCM -Version 1.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Yoti.FCM" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Yoti.FCM --version 1.2.0                
#r "nuget: Yoti.FCM, 1.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Yoti.FCM as a Cake Addin
#addin nuget:?package=Yoti.FCM&version=1.2.0

// Install Yoti.FCM as a Cake Tool
#tool nuget:?package=Yoti.FCM&version=1.2.0                

Yoti Face Capture

Face capture user control handles the camera and validates the video stream frame by frame until it finds a valid face.

Dependencies

The package uses C++ libraries so the machines that run the face capture will need to install the Microsoft Visual C++ Redistributable packages.

Usage

  1. Add the package dependency in your project.

  2. Add the reference xmlns:yotiFCM="clr-namespace:Yoti.FCM;assembly=Yoti.FCM" in the view that will integrate the user control.

  3. Render the user control:

    <yotiFCM:FaceCapture FaceDetected="<FaceCapture_FaceDetectedHandler>" />
    

It does not send the image to the Yoti AI service. The FaceDetected event will provide the base64 encoded image ready to be processed by the service. Use the .NET Yoti SDK or any other Yoti SDK (if the image is propagated to a back-end) to send the image and run a prediction.

This is the properties list for the FaceCapture:

Property name Type Default value Range Description
FaceDetected EventHandler<FacesDetectedEventArgs> null Event that the face capture will trigger each time it detects a face.
OnError EventHandler<ExceptionEventArgs> null Event to handle all inner exceptions from the face capture.
ReadyToCapture EventHandler null Event to handle when the camera is ready to start the streaming and capture a face.
ProbabilityThreshold FaceConfidenceThreshold FaceConfidenceThreshold.Medium Face probability score threshold used to detect faces.
CroppingRelativeMargin float 0.5F 0.2 - 1.0 Relative margin applied to crop around the detected face.
GrayScaleThreshold float 23.0F 20.0 - 30.0 Image grayscale threshold.
MultiFaceAreaThreshold int 200 180 - 250 Minimum face area size to check for multiple faces.
FaceOverlapingThreshold float 0.3F 0.2 - 0.35 Threshold to check if there is another face in the result face area.
LowBrightnessThreshold float 50.0F 40 - 60 Lowest brightness level allowed.
HighBrightnessThreshold float 200.0F 180 - 210 Highest brightness level allowed.
MinMainFaceArea int 20000 10000 - 60000 Minimum main face size in pixels.
MinRelativeAreaAroundFace float 0.15F 0.1 - 0.4 Minimum distance from the image edges relative to the face. It is measured as a percentage of the face size.
MinFaceRelativeSize float 0.005F 0.0025 - 0.05 Minimum size for the main face relative to the frame.
MaxFaceRelativeSize float 0.15F 0.1 - 0.6 Maximum size for the main face relative to the frame.
OutputQuality ImageQuality ImageQuality.High JPEG compression quality (High, Medium, Low).
NumberStableFrames int 4 1 - 12 NumberStableFrames is the consecutive valid frames of a face needed to consider it valid.
StabilityConfidenceThreshold float 0.9F 0.8 - 0.95 StabilityConfidenceThreshold is the required stability score for each frame with the previous.
Crop bool true If the final image result will be a cropped version of the webcam frame where the focus will be on the main face.
Debug bool false If the face capture will render the face debug information.
FaceDetectionTickerInterval int 160 100 - 500 The interval that the face capture will use to detect a face in the webcam frame.
WebcamIndex int? 0 The webcam index that the face capture will use to get the stream frames.
WebcamStartTimeout int? 5000 1000 - 30000 Webcam timeout in milliseconds to detect if the webcam stream has started or not.
CameraResolution Resolution Resolution.HD720P Resolution requested to the camera video capabilities. Must be a valid resolution for the webcam.
CameraAverageFrameRate int 30 Average frame rate requested to the camera video capabilities. Must match what the webcam provide for the selected resolution.
Rotation RotationFlipType RotationFlipType.RotateNoneFlipNone The transformations applied over the input stream. Applying any transformation to a high-resolution stream could cause performance issues.
CaptureTimeout int null 1 - 900 The number of seconds the FCM will wait for the capture process to finish. An exception will be sent through the onError if the timeout is reached.

Note: FaceCapture implements the interface IFaceCapture:

/// <summary>
/// Represents an entity that is able to detect a face from a stream like a webcam.
/// </summary>
public interface IFaceCapture
{
    /// <summary>
    /// Event that the face capture will trigger each time it detects a face.
    /// </summary>
    event EventHandler<FacesDetectedEventArgs> FaceDetected;

    /// <summary>
    /// Event to handle all inner exceptions from the face capture.
    /// </summary>
    event EventHandler<ExceptionEventArgs> OnError;

    /// <summary>
    /// Event to handle when the camera is ready to start the streaming and capture a face.
    /// </summary>
    event EventHandler ReadyToCapture;

    /// <summary>
    /// Starts the webcam stream and the face detection.
    /// </summary>
    void Play();

    /// <summary>
    /// Stops the webcam stream and the face detection.
    /// </summary>
    void Stop();
}

The package also provides the DefaultConfig class that implements all the configuration fields for the face capture user control.

Available resolutions

The FCM supports the following resolutions in both landscape and portrait modes, managed by the type Resolution:

  • HD720P: (1280 x 720) or (720 x 1280)
  • HD960P: (1280 x 960) or (960 x 1280)
  • ONE_DOT_THREE_MP: (1280 x 1024) or (1024 x 1280)
  • TWO_MP: (1600 x 1200) or (1200 x 1600)
  • HD1080P: (1920 x 1080) or (1080 x 1920)

To select the portrait resolutions, they use PORTRAIT_ as a prefix. For example PORTRAIT_HD720P.

Stream Transformations

The FCM can apply various transformations to the input stream, allowing flexibility in camera positioning to maximise the capture area based on the use case.

Supported transformations are managed by the type RotationFlipType, which includes:

  • RotateNoneFlipNone: Specifies no clockwise rotation and no flipping. (Default)
  • Rotate90FlipNone: Specifies a 90-degree clockwise rotation without flipping.
  • Rotate180FlipNone: Specifies a 180-degree clockwise rotation without flipping.
  • Rotate270FlipNone: Specifies a 270-degree clockwise rotation without flipping.
  • RotateNoneFlipX: Specifies no clockwise rotation followed by a horizontal flip.
  • Rotate90FlipX: Specifies a 90-degree clockwise rotation followed by a horizontal flip.
  • Rotate180FlipX: Specifies a 180-degree clockwise rotation followed by a horizontal flip.
  • Rotate270FlipX: Specifies a 270-degree clockwise rotation followed by a horizontal flip.

Note: These transformations are computationally intensive and may affect performance, depending on the resolution and system characteristics.

Localisation

Set the FCM localisation by running the following code:

CultureInfo cultureInfo = new CultureInfo(SelectedLanguage);
Thread.CurrentThread.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentUICulture = cultureInfo;
Application.Current.MainWindow.Language = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag);

Where SelectedLanguage can be chosen from the following list:

  • ar-XM
  • bg-BG
  • cs-CZ
  • da-DK
  • de-DE
  • el-GR
  • en
  • es-419
  • es-ES
  • et-EE
  • fa-IR
  • fi-FI
  • fr-FR
  • he-IL
  • hi-IN
  • hr-HR
  • hu-HU
  • hy-AM
  • id-ID
  • it-IT
  • ja-JP
  • ko-KR
  • lt-LT
  • lv-LV
  • ms-MY
  • nb-NO
  • nl-NL
  • pl-PL
  • pt-BR
  • pt-PT
  • ro-RO
  • ru-RU
  • sv-SE
  • th-TH
  • tr-TR
  • uk-UA
  • ur-PK
  • vi-VN

Error handling

The OnError event provides the custom ExceptionEventArgs information with the exceptions that the FCM can throw. It is triggered in the following scenarios:

  • The integrator provides an invalid configuration (Yoti.FCM.FaceDetection.Exceptions.ConfigurationException).
  • The webcam index is out of range (System.ArgumentOutOfRangeException).
  • If the current webcam streaming is disconnected (Yoti.FCM.Exceptions.WebcamStreamException).
  • The capture process reach the stablished timeout (System.TimeoutException).
  • Unexpected exceptions (System.Exception).

Other controls

Webcam selector

The package exports the method Yoti.FCM.WebcamStream.WebcamInfo.GetWebcamDevices() to get all webcam devices that are available. It also provides a user control to select a webcam:

<controls:WebcamSelector Width="300" Height="24" SelectionChanged="WebcamSelector_SelectionChanged" />

The properties for the webcam selector are the following:

Property name Type Default value Description
SelectedIndex int? 0 The current webcam index.
SelectionChanged EventHandler<WebcamSelectionEventArgs> null The event that the webcam selector will trigger when the user changes the webcam selected.
Resolution selector

The package exports the method Yoti.FCM.WebcamStream.WebcamCapabilities.GetValidCapabilities(string webcamMoniker) to get all the capabilities compatible with the FCM for the provided device. It also provides a user control to select capabilities set:

<controls:ResolutionSelector Width="300" Height="24" SelectedWebcam="{Binding CurrentWebcam.MonikerString}" SelectionChanged="ResolutionSelector_SelectionChanged"/>

The properties for the webcam selector are the following:

Property name Type Default value Description
SelectedWebcam string null The current webcam ID from which the capabilities are going to be selected.
SelectedCapabilities WebcamCapabilities null The current selected capabilities.
SelectionChanged EventHandler<ResolutionSelectionEventArgs> null The event that the webcam selector will trigger when the user changes the webcam selected.
Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 40 11/14/2024
1.1.0 93 10/15/2024
1.0.2 128 8/14/2024
1.0.1 991 4/17/2023
1.0.0 302 2/8/2023
0.1.0-beta2 182 12/2/2022
0.1.0-beta1 203 11/7/2022

- Added CaptureTimeout property to define a limited time for the capture process.