Face SDK  1.7 Mozart rc
Face Recognition Software Development Kit
deserialize.cpp
#include <iostream>
#include <fstream>
int main(int argc, char **argv)
{
if (argc < 2) {
std::cout << "usage: <FILE_1> <FILE_2> ... <FILE_N>" << std::endl;
return 1;
}
std::shared_ptr<face_sdk::serializer> serializer;
try {
// initialize serializer
serializer = face_sdk::make_serializer();
// load images and make faces objects.
for (int i = 1; i < argc; i++) {
std::string file_path;
file_path.assign(argv[i]);
// read file
std::ifstream stream;
stream.open(file_path, std::ios::binary);
stream.seekg(0, std::ifstream::end);
size_t file_size = stream.tellg();
stream.seekg(0, std::ifstream::beg);
std::vector<uint8_t> file_data;
file_data.resize(file_size);
stream.read((char*)file_data.data(), file_size);
std::cout << "file: " << file_path << std::endl;
// determinate file extension
auto pos = file_path.rfind('.', 0);
auto ext = file_path.substr(pos);
if (ext == ".fir") {
// deserialize as fir
auto fir = serializer->deserialize_fir(file_data);
std::cout <<" fir_version: " << fir->version() << std::endl;
} else if (ext == ".fac") {
//deserialize as face
auto face = serializer->deserialize_face(file_data);
std::cout << " face:" << std::endl;
std::cout << " x:" << face->x() << std::endl;
std::cout << " y:" << face->y() << std::endl;
std::cout << " width:" << face->width() << std::endl;
std::cout << " height:" << face->height() << std::endl;
} else if (ext == ".alg") {
//deserialize as alignment_info
auto alg = serializer->deserialize_alignment_info(file_data);
std::cout << " version: " << alg->version() << std::endl;
std::cout << " aligned_image:" << std::endl;
std::cout << " width:" << alg->aligned_image()->width() << std::endl;
std::cout << " height:" << alg->aligned_image()->height() << std::endl;
std::cout << " raw_size:" << alg->aligned_image()->data_size() << std::endl;
std::cout << " face:" << std::endl;
std::cout << " x:" << alg->face()->x() << std::endl;
std::cout << " y:" << alg->face()->y() << std::endl;
std::cout << " width:" << alg->face()->width() << std::endl;
std::cout << " height:" << alg->face()->height() << std::endl;
std::cout << " face_image:" << std::endl;
std::cout << " width:" << alg->face()->img()->width() << std::endl;
std::cout << " height:" << alg->face()->img()->height() << std::endl;
std::cout << " raw_size:" << alg->face()->img()->data_size() << 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;
}
alignment.h
face_sdk::make_serializer
std::shared_ptr< face_sdk::serializer > FACE_SDK_EXPORT make_serializer()
Makes the face_sdk::serializer object.
image.h
serialize.h
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