Face SDK  1.7 Mozart rc
Face Recognition Software Development Kit
complex.cpp
#include <iostream>
#include <algorithm>
int main(int argc, char **argv)
{
if (argc < 2) {
std::cout << "usage: <IMG_1> <IMG_2> ... <IMG_N>" << std::endl;
return 1;
}
std::shared_ptr<face_sdk::face_detector> face_detector;
std::shared_ptr<face_sdk::alignment> alignment;
std::shared_ptr<face_sdk::builder> builder;
std::shared_ptr<face_sdk::fir_matcher> matcher;
std::shared_ptr<face_sdk::age_gender> age_gender;
try {
// initialize Face Detector, Alignment, Builder and Age&Gender algorithms with batch size 1 and on CPU
face_detector = face_sdk::make_face_detector(200, 1, -1);
alignment = face_sdk::make_alignment(103, 1, -1);
builder = face_sdk::make_builder(200, 1, -1);
age_gender = face_sdk::make_age_gender(100, 1, -1);
// initialize FIRs matcher with builder version and "gn" mathing table code. See \ref matching_table_codes.
matcher = face_sdk::make_fir_matcher(builder->version(), "gn");
// load images and make faces objects.
std::vector< std::shared_ptr< face_sdk::image > > images;
for (int i = 1; i < argc; i++) {
auto img = face_sdk::load_image_from_file(argv[i]);
images.push_back(img);
}
// detect faces on each image
std::vector< std::shared_ptr< face_sdk::face > > faces;
for (auto img : images) {
auto faces = face_detector->detect_faces({ img }, 0.4f)[0];
if (faces.size() == 0) {
// no faces found
continue;
}
// select only best detected face (with better confidence)
std::sort(faces.begin(), faces.end(), [](const std::shared_ptr<face_sdk::face> &f1, const std::shared_ptr<face_sdk::face> &f2) -> bool { return f1->confidence() < f2->confidence(); });
faces.push_back(faces.back());
}
// perform alignment
auto align_results = alignment->calc_alignment(faces);
// build FIRs for previously aligned images
auto firs = builder->build(align_results);
// match FIRs to each other and print results
for (int i = 0; i < firs.size(); i++) {
for (int j = i + 1; j < firs.size(); j++) {
auto match_result = matcher->match(firs[i], firs[j]);
std::cout << i << " -> " << j << " = " << match_result << std::endl;
}
}
// classify age and gender for previously aligned images
auto age_gender_info = age_gender->calc_age_gender(align_results);
for (int i = 0; i < age_gender_info.size(); i++) {
std::cout << i << " -> " << " age " << age_gender_info[i].age << ", gender " << (age_gender_info[i].gender < 0 ? "female" : "male") << std::endl;
}
}
// exception handling
catch (const face_sdk::exception &exp) {
// print the stack of nested exceptions ...
std::cerr << face_sdk::format_exception(exp) << std::endl;
// ... or handle more detailed exceptions
try {
std::rethrow_if_nested(exp);
}
catch (const face_sdk::version_not_available_exception &nested) {
// ...
std::cerr << nested.what() << std::endl;
}
catch (const face_sdk::license_exception &nested) {
// ...
std::cerr << nested.what() << std::endl;
}
catch (const std::exception &nested) {
// ...
std::cerr << nested.what() << std::endl;
}
return 2;
}
return 0;
}
face_sdk::make_fir_matcher
std::shared_ptr< face_sdk::fir_matcher > FACE_SDK_EXPORT make_fir_matcher(uint32_t builder_version, const std::string &table_code, const std::shared_ptr< face_sdk::license > &license, const std::shared_ptr< face_sdk::data_container > &container, const architecture_type type)
Makes FIRs matcher with needed builder version, FAR table code, license object and data container.
alignment.h
face_sdk::load_image_from_file
std::shared_ptr< face_sdk::image > FACE_SDK_EXPORT load_image_from_file(const std::string &file_name)
Load encoded image from file. Image must be in RBG or BRG channels order. Grayscale or images with al...
face_sdk::make_alignment
std::shared_ptr< alignment > FACE_SDK_EXPORT make_alignment(uint32_t version, const std::shared_ptr< face_sdk::license > &license, const std::shared_ptr< face_sdk::data_container > &contaner, uint32_t batch_size, int32_t compute_device)
Makes the face_sdk::alignment object with needed version, license, data container,...
fir_matcher.h
face_detector.h
face_sdk::make_age_gender
std::shared_ptr< face_sdk::age_gender > FACE_SDK_EXPORT make_age_gender(uint32_t version, const std::shared_ptr< face_sdk::license > &license, const std::shared_ptr< face_sdk::data_container > &container, uint32_t batch_size, int32_t compute_device)
Makes the face_sdk::age_gender object with needed version, license, data container,...
image.h
age_gender.h
face_sdk::make_face_detector
std::shared_ptr< face_sdk::face_detector > FACE_SDK_EXPORT make_face_detector(uint32_t version, const std::shared_ptr< face_sdk::license > &license, const std::shared_ptr< face_sdk::data_container > &contaner, uint32_t batch_size, int32_t compute_device)
Makes the face_sdk::face_detector object with specified version, license, data container,...
face_sdk::make_builder
std::shared_ptr< face_sdk::builder > FACE_SDK_EXPORT make_builder(uint32_t version, const std::shared_ptr< face_sdk::license > &license, const std::shared_ptr< face_sdk::data_container > &contaner, uint32_t batch_size, int32_t compute_device)
Makes the face_sdk::builder object with specified version, license, data container,...
face_sdk::exception
Base FaceSDK exception class. Almost all exceptions that FaceSDK throws are inherits this class.
Definition: exception.h:56
exception.h
builder.h