Golang Challenge Response ExampleΒΆ

Initialize Challenge Response module

import ("oneml/face")
challenge := face.NewChallengeResponse()

Initialize Challenge Response module from existing FaceDetector and FaceLandmarkDetector

import ("oneml/face")
faceDetector := face.NewFaceDetector()
faceLandmark := face.NewFaceLandmarkDetector()
challenge := face.NewChallengeResponse(faceDetector, faceLandmark)

Initialize Challenge Response module with licensing

import ("oneml/face")
licenseManager := face.NewLicenseManager()
licenseManager.SetKey("LICENSE_KEY_VALUE_HERE")
licenseManager.ActivateKey()
challenge := face.NewChallengeResponse(licenseManager)

Initialize Challenge Response module with licensing from existing FaceDetector and FaceLandmarkDetector

import ("oneml/face")
licenseManager := face.NewLicenseManager()
licenseManager.SetKey("LICENSE_KEY_VALUE_HERE")
licenseManager.ActivateKey()

faceDetector := face.NewFaceDetector(licenseManager)
faceLandmark := face.NewFaceLandmarkDetector(licenseManager)
challenge := face.NewChallengeResponse(faceDetector, faceLandmark, licenseManager)

Run the module from videos

vidPath := "path/to/video.mp4"
ops := face.NewChallengeResponseOps(true)
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
ops := face.NewChallengeResponseOps(true)
while (can_read_frame):
    # use any function to get each frame from image stream
    frame := GetOneFrame()
    result := challenge.Run(frame, ops)
challenge.Reset()

Run the module with ImageBatch

// create ImageBatch
utils := face.NewUtils()

vidPath := "path/to/video.mp4"
images := utils.VideoToImages(vidPath)

// run ChallengeResponse with ImageBatch
ops := face.NewChallengeResponseOps(true)
result := challenge.Run(images, ops)

Get result

fmt.Println("status:", result.GetReturnStatus())
    fmt.Println("is_blink:", utility.BoolToInt(result.IsBlink()))
    fmt.Println("number of blinks:", result.GetNumBlinks())
    fmt.Printf("liveness score: %.2f\n", result.GetLivenessScore())
bestFrame := result.GetBestFrame()

Cleanup

defer face.DeleteFaceDetector(faceDetector)
defer face.DeleteFaceLandmarkDetector(faceLandmark)
defer face.DeleteChallengeResponse(challenge)