C# Challenge Response ExampleΒΆ

Initialize Challenge Response module

using OneML.Face;
ChallengeResponse challenge = new ChallengeResponse();

Initialize Challenge Response module from existing FaceDetector and FaceLandmarkDetector

using OneML.Face;
FaceDetector faceDetector = new FaceDetector();
FaceLandmarkDetector faceLandmark = new FaceLandmarkDetector();
ChallengeResponse challenge = new ChallengeResponse(faceDetector, faceLandmark);

Initialize Challenge Response module with licensing

using OneML.Face;
LicenseManager licenseManager = new LicenseManager();
licenseManager.SetKey("LICENSE_KEY_VALUE_HERE");
licenseManager.ActivateKey();
ChallengeResponse challenge = new ChallengeResponse(licenseManager);

Initialize Challenge Response module with licensing from existing FaceDetector and FaceLandmarkDetector

using OneML.Face;
LicenseManager licenseManager = new LicenseManager();
licenseManager.SetKey("LICENSE_KEY_VALUE_HERE");
licenseManager.ActivateKey();

FaceDetector faceDetector = new FaceDetector(licenseManager);
FaceLandmarkDetector faceLandmark = new FaceLandmarkDetector(licenseManager);
ChallengeResponse challenge = new ChallengeResponse(faceDetector, faceLandmark, licenseManager);

Run the module from videos

string vidPath = @"path/to/video.mp4";
ChallengeResponseOps ops = new ChallengeResponseOps(true);
ChallengeResponseResult result = challenge.Run(vidPath, ops);

Run the module from stream of images (can be used with opencv VideoCapture)

# if we can still read frame from image stream
ChallengeResponseOps ops = new ChallengeResponseOps(true);
while (can_read_frame):
    # use any function to get each frame from image stream
    Image frame = GetOneFrame()
    ChallengeResponseResult result = challenge.Run(frame, ops)
challenge.Reset()

Run the module with ImageBatch

// create ImageBatch
Utils utils = new Utils();

string vidPath = @"path/to/video.mp4";
ImageBatch images = utils.VideoToImages(vidPath);
ChallengeResponseOps ops = new ChallengeResponseOps(true);

// run ChallengeResponse with ImageBatch
ChallengeResponseResult result = challenge.Run(images, ops);

Get result

Console.WriteLine("status: " + result.GetReturnStatus());
Console.WriteLine("is_blink: " + result.IsBlink());
Console.WriteLine("number of blinks: " + result.GetNumBlinks());
Console.WriteLine("liveness_score: " + result.GetLivenessScore());
Image bestFrame = result.GetBestFrame();

Cleanup

faceDetector.Dispose();
faceLandmark.Dispose();
challenge.Dispose();

or wrap the application with

using (FaceDetector faceDetector = new FaceDetector())
using (FaceLandmarkDetector faceLandmark = new FaceLandmarkDetector())
using (ChallengeResponse challenge = new ChallengeResponse())
{
// use faceDetector, faceLandmark, challenge here
}