Enrollment
Example for how to enroll a new user.
The enrollment creates a new user entity within the Keyless Network based on the face features captured by the selected camera device. Succesful enrollment outputs a User Secret which may be later used to verify the user identity during an authentication.
To start an enrollment we must first initialize a Keyless SDK session (see Getting Started).

Synchronous enrollment

We will perform enrollment using a simple blocking call.
1
/// USER SESSION HAS BEEN INITIALIZED
2
​
3
// Enrollment outputs (User Key used as input to authentications, User Secret to
4
// verify authentication), let's save both
5
std::vector<unsigned char> user_key, user_secret;
6
​
7
try
8
{
9
// IEnrollment object will hold the enrollment result
10
keyless::IEnrollment::Ptr enroll;
11
12
// Perform enrollment using previously selected and configured camera device
13
enroll = session->enroll(*device_selector, nullptr);
14
15
/// USER HAS BEEN SUCCESFULLY ENROLLED HERE
16
17
// Optionally we can double-check enrollment here
18
if (session->isEnrolled()) {
19
// Save User Key
20
user_key.resize(enroll->getUserKey().getDataSize());
21
enroll->getUserKey().readData(user_key.data(), user_key.size());
22
23
// Save User Secret
24
user_secret.resize(enroll->getUserKey().getDataSize());
25
enroll->getUserSecret().readData(user_secret.data(), user_secret.size());
26
}
27
}
28
catch (const keyless::IException& e)
29
{
30
std::cerr << e.message() << std::endl;
31
}
32
​
Copied!

Asynchronous enrollment

To perform the enrollment we call the enrollAsync()method with our implementation of IEnrollmentCallbacks interface which will report the execution end.
1
class KeylessEnrollmentCallbacks : public keyless::IEnrollmentCallbacks
2
{
3
private:
4
void KEYLESS_SDK_CALL onFailure(const keyless::IException& exception) noexcept override
5
{
6
// Enrollment has ended with failure here, save details from `exception`
7
}
8
9
void KEYLESS_SDK_CALL onSuccess(keyless::IEnrollment* enrollment) noexcept override
10
{
11
// Enrollment has ended with success here, save results from `enrollment`
12
}
13
14
keyless::IStatusCallbacks* KEYLESS_SDK_CALL getStatusCallbacks() noexcept override
15
{
16
return nullptr; // see "Status Updates" below
17
}
18
};
Copied!
We will also retrieve the IControl interface allowing us to stop the running execution.
1
/// USER SESSION HAS BEEN INITIALIZED
2
​
3
try
4
{
5
// declare our asynchronous callbacks
6
KeylessEnrollmentCallbacks callbacks;
7
8
// Perform enrollment
9
keyless::IControl& control = session->enrollAsync(callbacks);
10
11
/// ENROLLMENT IN PROGRESS, WAIT FOR RESULT VIA CALLBACKS
12
13
// we can optionally interrupt the running execution with this call
14
control.stop();
15
}
16
catch (const keyless::IException& e)
17
{
18
std::cerr << e.message() << std::endl;
19
}
Copied!

Status updates

We may provide both enroll() and enrollAsync() methods with our implementation of IStatusCallbacks interface which will report enrollment progress.
1
class KeylessWndStatusCallbacks : public keyless::IStatusCallbacks
2
{
3
private:
4
void KEYLESS_SDK_CALL onFrameCapture(const keyless::IFrame& frame) noexcept override
5
{
6
// New frame capture from the camera, save it to be displayed to user
7
}
8
void KEYLESS_SDK_CALL onSessionStatus(keyless::SessionStatus status, const keyless::IException& e) noexcept override
9
{
10
// Overall execution status has changed
11
}
12
void KEYLESS_SDK_CALL onLivenessStatus(keyless::LivenessStatus status) noexcept override
13
{
14
// Liveness detection status has changed
15
}
16
void KEYLESS_SDK_CALL onRecognitionStatus(keyless::FaceRecognitionStatus status) noexcept override
17
{
18
// Face recognition status has changed
19
}
20
}
Copied!
Last modified 4mo ago