Class FaceRecognition
- Namespace
- FaceRecognitionDotNet
- Assembly
- VisioForge.Core.FaceAI.dll
Provides the method to find and recognize face methods. This class cannot be inherited.
public sealed class FaceRecognition : DisposableObject, IDisposableInheritance
Implements
Inherited Members
Properties
CustomAgeEstimator
Gets or sets the custom age estimator that user defined.
public AgeEstimator CustomAgeEstimator { get; set; }Property Value
CustomEmotionEstimator
Gets or sets the custom emotion estimator that user defined.
public EmotionEstimator CustomEmotionEstimator { get; set; }Property Value
CustomEyeBlinkDetector
Gets or sets the custom eye blink detector that user defined.
public EyeBlinkDetector CustomEyeBlinkDetector { get; set; }Property Value
CustomFaceDetector
Gets or sets the custom face detector that user defined.
public FaceDetector CustomFaceDetector { get; set; }Property Value
CustomFaceLandmarkDetector
Gets or sets the custom face landmark detector that user defined.
public FaceLandmarkDetector CustomFaceLandmarkDetector { get; set; }Property Value
CustomGenderEstimator
Gets or sets the custom gender estimator that user defined.
public GenderEstimator CustomGenderEstimator { get; set; }Property Value
CustomHeadPoseEstimator
Gets or sets the custom head pose estimator that user defined.
public HeadPoseEstimator CustomHeadPoseEstimator { get; set; }Property Value
InternalEncoding
Gets or sets the character encoding to convert String to array of Byte for internal library.
public static Encoding InternalEncoding { get; set; }Property Value
Methods
BatchFaceLocations(IEnumerable<Image>, int, int)
Returns an enumerable collection of array of bounding boxes of human faces in a image using the cnn face detector.
public IEnumerable<Location[]> BatchFaceLocations(IEnumerable<Image> images, int numberOfTimesToUpsample = 1, int batchSize = 128)Parameters
imagesIEnumerable<Image>-
An enumerable collection of images.
numberOfTimesToUpsampleint-
The number of image looking for faces. Higher numbers find smaller faces.
batchSizeint-
The number of images to include in each GPU processing batch.
Returns
- IEnumerable<Location[]>
-
An enumerable collection of array of found face locations.
Exceptions
- ArgumentNullException
-
imagesis null.
CompareFace(FaceEncoding, FaceEncoding, double)
Compare a known face encoding against a candidate encoding to see if they match.
public static bool CompareFace(FaceEncoding knownFaceEncoding, FaceEncoding faceEncodingToCheck, double tolerance = 0.6)Parameters
knownFaceEncodingFaceEncoding-
A known face encodings.
faceEncodingToCheckFaceEncoding-
A single face encoding to compare against a known face encoding.
tolerancedouble-
The distance between faces to consider it a match. Lower is more strict. The default value is 0.6.
Returns
- bool
-
A True/False value indicating which known a face encoding matches the face encoding to check.
Exceptions
- ArgumentNullException
-
knownFaceEncodingorfaceEncodingToCheckis null. - ObjectDisposedException
-
knownFaceEncodingorfaceEncodingToCheck.
CompareFace(FaceInfo, FaceInfo, double)
Compare a known face encoding against a candidate encoding to see if they match.
public static bool CompareFace(FaceInfo knownFaceEncoding, FaceInfo faceEncodingToCheck, double tolerance = 0.6)Parameters
knownFaceEncodingFaceInfo-
A known face encodings.
faceEncodingToCheckFaceInfo-
A single face encoding to compare against a known face encoding.
tolerancedouble-
The distance between faces to consider it a match. Lower is more strict. The default value is 0.6.
Returns
- bool
-
A True/False value indicating which known a face encoding matches the face encoding to check.
Exceptions
- ArgumentNullException
-
knownFaceEncodingorfaceEncodingToCheckis null. - ObjectDisposedException
-
knownFaceEncodingorfaceEncodingToCheck.
CompareFaces(IEnumerable<FaceEncoding>, FaceEncoding, double)
Compare an enumerable collection of face encodings against a candidate encoding to see if they match.
public static List<bool> CompareFaces(IEnumerable<FaceEncoding> knownFaceEncodings, FaceEncoding faceEncodingToCheck, double tolerance = 0.6)Parameters
knownFaceEncodingsIEnumerable<FaceEncoding>-
An enumerable collection of known face encodings.
faceEncodingToCheckFaceEncoding-
A single face encoding to compare against the enumerable collection.
tolerancedouble-
The distance between faces to consider it a match. Lower is more strict. The default value is 0.6.
Returns
- List<bool>
-
An enumerable collection of True/False values indicating which known face encodings match the face encoding to check.
Exceptions
- ArgumentNullException
-
knownFaceEncodingsorfaceEncodingToCheckis null. - ObjectDisposedException
-
faceEncodingToCheckis disposed. OrknownFaceEncodingscontains disposed object.
CompareFaces(IEnumerable<FaceInfo>, FaceInfo, double)
Compare an enumerable collection of face encodings against a candidate encoding to see if they match.
public static List<bool> CompareFaces(IEnumerable<FaceInfo> knownFaceEncodings, FaceInfo faceEncodingToCheck, double tolerance = 0.6)Parameters
knownFaceEncodingsIEnumerable<FaceInfo>-
An enumerable collection of known face encodings.
faceEncodingToCheckFaceInfo-
A single face encoding to compare against the enumerable collection.
tolerancedouble-
The distance between faces to consider it a match. Lower is more strict. The default value is 0.6.
Returns
- List<bool>
-
An enumerable collection of True/False values indicating which known face encodings match the face encoding to check.
Exceptions
- ArgumentNullException
-
knownFaceEncodingsorfaceEncodingToCheckis null. - ObjectDisposedException
-
faceEncodingToCheckis disposed. OrknownFaceEncodingscontains disposed object.
CompareFaces(IEnumerable<FaceEncoding>, IEnumerable<FaceEncoding>, double)
Compare an enumerable collection of face encodings against a candidate encoding to see if they match.
public static List<bool> CompareFaces(IEnumerable<FaceEncoding> knownFaceEncodings, IEnumerable<FaceEncoding> faceEncodingsToCheck, double tolerance = 0.6)Parameters
knownFaceEncodingsIEnumerable<FaceEncoding>-
An enumerable collection of known face encodings.
faceEncodingsToCheckIEnumerable<FaceEncoding>-
A enumerable collection of face encoding to compare against the enumerable collection.
tolerancedouble-
The distance between faces to consider it a match. Lower is more strict. The default value is 0.6.
Returns
- List<bool>
-
An enumerable collection of True/False values indicating which known face encodings match the face encoding to check.
Exceptions
- ArgumentNullException
-
knownFaceEncodingsorfaceEncodingToCheckis null. - ObjectDisposedException
-
faceEncodingToCheckis disposed. OrknownFaceEncodingscontains disposed object.
CompareFaces(IEnumerable<FaceInfo>, IEnumerable<FaceInfo>, double)
Compare an enumerable collection of face encodings against a candidate encoding to see if they match.
public static List<bool> CompareFaces(IEnumerable<FaceInfo> knownFaceEncodings, IEnumerable<FaceInfo> faceEncodingsToCheck, double tolerance = 0.6)Parameters
knownFaceEncodingsIEnumerable<FaceInfo>-
An enumerable collection of known face encodings.
faceEncodingsToCheckIEnumerable<FaceInfo>-
A enumerable collection of face encoding to compare against the enumerable collection.
tolerancedouble-
The distance between faces to consider it a match. Lower is more strict. The default value is 0.6.
Returns
- List<bool>
-
An enumerable collection of True/False values indicating which known face encodings match the face encoding to check.
Exceptions
- ArgumentNullException
-
knownFaceEncodingsorfaceEncodingToCheckis null. - ObjectDisposedException
-
faceEncodingToCheckis disposed. OrknownFaceEncodingscontains disposed object.
Create(string)
Create a new instance of the FaceRecognitionDotNet.FaceRecognition class.
public static FaceRecognition Create(string directory)Parameters
directorystring-
The directory path that stores model files.
Returns
Exceptions
- FileNotFoundException
-
The model file is not found.
- DirectoryNotFoundException
-
The specified directory path is not found.
Create(ModelParameter)
Create a new instance of the FaceRecognitionDotNet.FaceRecognition class.
public static FaceRecognition Create(ModelParameter parameter)Parameters
parameterModelParameter-
The instance that contains model binary datum.
Returns
Exceptions
- ArgumentNullException
-
parameteris null. - NullReferenceException
-
The model data is null.
CropFaces(Image, IEnumerable<Location>)
Crop a specified image with enumerable collection of face locations.
public static IEnumerable<Image> CropFaces(Image image, IEnumerable<Location> locations)Parameters
imageImage-
The image contains a face.
locationsIEnumerable<Location>-
The enumerable collection of location rectangle for faces.
Returns
Exceptions
- ArgumentNullException
-
imageorlocationsis null. - ObjectDisposedException
-
imageis disposed.
DisposeUnmanaged()
Releases all unmanaged resources.
protected override void DisposeUnmanaged()EyeBlinkDetect(IDictionary<FacePart, IEnumerable<FacePoint>>, out bool, out bool)
Detects the values whether human eye's blink or not from face landmark.
public void EyeBlinkDetect(IDictionary<FacePart, IEnumerable<FacePoint>> landmark, out bool leftBlink, out bool rightBlink)Parameters
landmarkIDictionary<FacePart, IEnumerable<FacePoint>>-
The dictionary of face parts locations (eyes, nose, etc).
leftBlinkbool-
When this method returns, contains
true , if the left eye blinks; otherwise,false . rightBlinkbool-
When this method returns, contains
true , if the right eye blinks; otherwise,false .
Exceptions
- ArgumentNullException
-
landmarkis null. - ArgumentException
-
landmarkdoes not contain FaceRecognitionDotNet.FacePart.LeftEye or FaceRecognitionDotNet.FacePart.RightEye. - NotSupportedException
-
The custom eye blink detector is not ready.
- ObjectDisposedException
-
This object or custom eye blink detector is disposed.
FaceDistance(FaceEncoding, FaceEncoding)
Compare a face encoding to a known face encoding and get a euclidean distance for comparison face.
public static double FaceDistance(FaceEncoding faceEncoding, FaceEncoding faceToCompare)Parameters
faceEncodingFaceEncoding-
The face encoding to compare.
faceToCompareFaceEncoding-
The face encoding to compare against.
Returns
- double
-
The euclidean distance for comparison face. If 0, faces are completely equal.
Exceptions
- ArgumentNullException
-
faceEncodingorfaceToCompareis null. - ObjectDisposedException
-
faceEncodingorfaceToCompareis disposed.
FaceDistances(IEnumerable<FaceEncoding>, FaceEncoding)
Compare an enumerable collection of face encoding to a known face encoding and get an enumerable collection of euclidean distance for comparison face.
public static IEnumerable<double> FaceDistances(IEnumerable<FaceEncoding> faceEncodings, FaceEncoding faceToCompare)Parameters
faceEncodingsIEnumerable<FaceEncoding>-
The enumerable collection of face encoding to compare.
faceToCompareFaceEncoding-
The face encoding to compare against.
Returns
- IEnumerable<double>
-
The enumerable collection of euclidean distance for comparison face. If 0, faces are completely equal.
Exceptions
- ArgumentNullException
-
faceEncodingsorfaceToCompareis null. - ObjectDisposedException
-
faceToCompareis disposed. OrfaceEncodingscontains disposed object.
FaceEncodings(Image, IEnumerable<Location>, int, PredictorModel, Model)
Returns an enumerable collection of face feature data corresponds to all faces in specified image.
public IEnumerable<FaceEncoding> FaceEncodings(Image image, IEnumerable<Location> knownFaceLocation = null, int numJitters = 1, PredictorModel predictorModel = PredictorModel.Small, Model model = Model.Hog)Parameters
imageImage-
The image contains faces. The image can contain multiple faces.
knownFaceLocationIEnumerable<Location>-
The enumerable collection of location rectangle for faces. If specified null, method will find face locations.
numJittersint-
The number of times to re-sample the face when calculating encoding.
predictorModelPredictorModel-
The dimension of vector which be returned from detector.
modelModel-
The model of face detector to detect in image. If
knownFaceLocationis not null, this value is ignored.
Returns
- IEnumerable<FaceEncoding>
-
An enumerable collection of face feature data corresponds to all faces in specified image.
Exceptions
- ArgumentNullException
-
imageis null. - InvalidOperationException
-
knownFaceLocationcontains no elements. - ObjectDisposedException
-
imageor this object or custom face landmark detector is disposed. - NotSupportedException
-
FaceRecognitionDotNet.PredictorModel.Custom is not supported.
FaceLandmark(Image, IEnumerable<Location>, PredictorModel, Model)
Returns an enumerable collection of dictionary of face parts locations (eyes, nose, etc) for each face in the image.
public IEnumerable<IDictionary<FacePart, IEnumerable<FacePoint>>> FaceLandmark(Image faceImage, IEnumerable<Location> faceLocations = null, PredictorModel predictorModel = PredictorModel.Large, Model model = Model.Hog)Parameters
faceImageImage-
The image contains faces. The image can contain multiple faces.
faceLocationsIEnumerable<Location>-
The enumerable collection of location rectangle for faces. If specified null, method will find face locations.
predictorModelPredictorModel-
The dimension of vector which be returned from detector.
modelModel-
The model of face detector to detect in image. If
faceLocationsis not null, this value is ignored.
Returns
- IEnumerable<IDictionary<FacePart, IEnumerable<FacePoint>>>
-
An enumerable collection of dictionary of face parts locations (eyes, nose, etc).
Exceptions
- ArgumentNullException
-
faceImageis null. - InvalidOperationException
-
faceLocationscontains no elements. - ObjectDisposedException
-
faceImageor this object or custom face landmark detector is disposed. - NotSupportedException
-
The custom face landmark detector is not ready.
FaceLocations(Image, int, Model)
Returns an enumerable collection of face location correspond to all faces in specified image.
public IEnumerable<Location> FaceLocations(Image image, int numberOfTimesToUpsample = 1, Model model = Model.Hog)Parameters
imageImage-
The image contains faces. The image can contain multiple faces.
numberOfTimesToUpsampleint-
The number of times to up-sample the image when finding faces.
modelModel-
The model of face detector to detect in image.
Returns
- IEnumerable<Location>
-
An enumerable collection of face location correspond to all faces in specified image.
Exceptions
- ArgumentNullException
-
imageis null. - ObjectDisposedException
-
imageor this object is disposed.
LoadFaceEncoding(double[])
Creates an FaceRecognitionDotNet.FaceEncoding from the Double array.
public static FaceEncoding LoadFaceEncoding(double[] encoding)Parameters
Returns
- FaceEncoding
-
The FaceRecognitionDotNet.FaceEncoding this method creates.
Exceptions
- ArgumentNullException
-
encodingis null. - ArgumentOutOfRangeException
-
encodingmust be 128.
LoadImage(Bitmap)
Creates an FaceRecognitionDotNet.Image from the specified existing bitmap image.
public static Image LoadImage(Bitmap bitmap)Parameters
Returns
- Image
-
The FaceRecognitionDotNet.Image this method creates.
Exceptions
- ArgumentNullException
-
bitmapis null. - ArgumentOutOfRangeException
-
The specified PixelFormat is not supported.
LoadImage(byte[], int, int, int, Mode)
Creates an FaceRecognitionDotNet.Image from the Byte array.
public static Image LoadImage(byte[] array, int row, int column, int stride, Mode mode)Parameters
arraybyte[]-
The Byte array contains image data.
rowint-
The number of rows in a image data.
columnint-
The number of columns in a image data.
strideint-
The stride width in bytes.
modeMode-
A image color mode.
Returns
- Image
-
The FaceRecognitionDotNet.Image this method creates.
Exceptions
- ArgumentNullException
-
arrayis null. - ArgumentOutOfRangeException
-
rowis less than 0. - ArgumentOutOfRangeException
-
columnis less than 0. - ArgumentOutOfRangeException
-
strideis less than 0. - ArgumentOutOfRangeException
-
strideis less thancolumn. - ArgumentOutOfRangeException
-
rowxstrideis less than Length.
LoadImage(nint, int, int, int, Mode)
Creates an FaceRecognitionDotNet.Image from the unmanaged memory pointer indicates Byte array image data.
public static Image LoadImage(nint array, int row, int column, int stride, Mode mode)Parameters
arraynint-
The unmanaged memory pointer indicates Byte array image data.
rowint-
The number of rows in a image data.
columnint-
The number of columns in a image data.
strideint-
The stride width in bytes.
modeMode-
A image color mode.
Returns
- Image
-
The FaceRecognitionDotNet.Image this method creates.
Exceptions
- ArgumentException
-
arrayis Zero. - ArgumentOutOfRangeException
-
rowis less than 0. - ArgumentOutOfRangeException
-
columnis less than 0. - ArgumentOutOfRangeException
-
strideis less than 0. - ArgumentOutOfRangeException
-
strideis less thancolumn.
LoadImageFile(string, Mode)
Creates an FaceRecognitionDotNet.Image from the specified path.
public static Image LoadImageFile(string file, Mode mode = Mode.Rgb)Parameters
filestring-
A string that contains the path of the file from which to create the FaceRecognitionDotNet.Image.
modeMode-
A image color mode.
Returns
- Image
-
The FaceRecognitionDotNet.Image this method creates.
Exceptions
- FileNotFoundException
-
The specified path does not exist.
PredictAge(Image, Location)
Returns an index of age group of face image correspond to specified location in specified image.
public uint PredictAge(Image image, Location location)Parameters
Returns
- uint
-
An index of age group of face image correspond to specified location in specified image.
Exceptions
- ArgumentNullException
-
imageorlocationis null. - ObjectDisposedException
-
imageor this object or custom age estimator is disposed. - NotSupportedException
-
The custom age estimator is not ready.
PredictEmotion(Image, Location)
Returns an emotion of face image correspond to specified location in specified image.
public string PredictEmotion(Image image, Location location)Parameters
Returns
- string
-
An emotion of face image correspond to specified location in specified image.
Exceptions
- ArgumentNullException
-
imageorlocationis null. - ObjectDisposedException
-
imageor this object or custom emotion estimator is disposed. - NotSupportedException
-
The custom emotion estimator is not ready.
PredictGender(Image, Location)
Returns an gender of face image correspond to specified location in specified image.
public Gender PredictGender(Image image, Location location)Parameters
Returns
- Gender
-
An gender of face image correspond to specified location in specified image.
Exceptions
- ArgumentNullException
-
imageorlocationis null. - ObjectDisposedException
-
imageor this object or custom gender estimator is disposed. - NotSupportedException
-
The custom gender estimator is not ready.
PredictHeadPose(IDictionary<FacePart, IEnumerable<FacePoint>>)
Returns a head pose estimated from face parts locations.
public HeadPose PredictHeadPose(IDictionary<FacePart, IEnumerable<FacePoint>> landmark)Parameters
landmarkIDictionary<FacePart, IEnumerable<FacePoint>>-
The dictionary of face parts locations (eyes, nose, etc).
Returns
- HeadPose
-
A head pose estimated from face parts locations.
Exceptions
- ArgumentNullException
-
landmarkis null. - ObjectDisposedException
-
This object or custom head pose estimator is disposed.
- NotSupportedException
-
The custom head pose estimator is not ready.
PredictProbabilityAge(Image, Location)
Returns probabilities of age group of face image correspond to specified location in specified image.
public IDictionary<uint, float> PredictProbabilityAge(Image image, Location location)Parameters
Returns
- IDictionary<uint, float>
-
Probabilities of age group of face image correspond to specified location in specified image.
Exceptions
- ArgumentNullException
-
imageorlocationis null. - ObjectDisposedException
-
imageor this object or custom age estimator is disposed. - NotSupportedException
-
The custom age estimator is not ready.
PredictProbabilityEmotion(Image, Location)
Returns probabilities of emotion of face image correspond to specified location in specified image.
public IDictionary<string, float> PredictProbabilityEmotion(Image image, Location location)Parameters
Returns
- IDictionary<string, float>
-
Probabilities of emotion of face image correspond to specified location in specified image.
Exceptions
- ArgumentNullException
-
imageorlocationis null. - ObjectDisposedException
-
imageor this object or custom emotion estimator is disposed. - NotSupportedException
-
The custom emotion estimator is not ready.
PredictProbabilityGender(Image, Location)
Returns probabilities of gender of face image correspond to specified location in specified image.
public IDictionary<Gender, float> PredictProbabilityGender(Image image, Location location)Parameters
Returns
- IDictionary<Gender, float>
-
Probabilities of gender of face image correspond to specified location in specified image.
Exceptions
- ArgumentNullException
-
imageorlocationis null. - ObjectDisposedException
-
imageor this object or custom gender estimator is disposed. - NotSupportedException
-
The custom gender estimator is not ready.