Trueface C++ SDK

Getting started with Trueface C++'s SDK

1. License

To obtain a License key, please contact our sales team

2. Flow

There's three calls to implement face recognize circle, SetReference, StoreReferences / LoadReferences and GetSimilarity.

To enroll, you have to call SetReference with agreements numeric ID, binary image of person, height and width of provided image.

To calculate similarity, you have to call GetSimilarity with agreements binary image of candidate person, height and width, the candidate ID and score is passed by reference.

You can store and load references using StoreReferences and LoadReferences calls.

Supported colors space are YUV420, YUVNV21 and BGR.

3. API

namespace trueface
class Compare

Compare(std::string token);
~Compare();

void SetReferenceYUV420(int id, unsigned char* buffer, size_t rows, size_t cols);
void SetReferenceYUVNV21(int id, unsigned char* buffer, size_t rows, size_t cols);
void SetReferenceBGR(int id, unsigned char* buffer, size_t rows, size_t cols);

bool GetSimilarityYUV420(unsigned char* buffer, size_t rows, size_t cols, int& id, float& similarity);
bool GetSimilarityYUVNV21(unsigned char* buffer, size_t rows, size_t cols, int& id, float& similarity);
bool GetSimilarityBGR(unsigned char* buffer, size_t rows, size_t cols, int& id, float& similarity);

void StoreReferences(std::string filepath);
void LoadReferences(std::string filepath);

Example

#include <iostream>
#include <string>
#include <fstream>

#include "include/trueface.hpp"

using namespace std;
using namespace trueface;

unsigned char *ReadFileAsBytes(string filepath);

int main() {

    // add a new reference face image, and store the reference face features into a file
    {
        // instantiate the class that measure similarity of two faces
        Compare compareFaces("TOKEN");

        // read the first/reference picture
        unsigned char* reference_pic = ReadFileAsBytes("person.jpeg");

        // the reference face is compared against query faces
        compareFaces.SetReferenceBGR(1, reference_pic, 2592, 1944);
        delete reference_pic;
        
        compareFaces.StoreReferences("./faces.db");
    }
    
    // load the reference face features from file, and find the best candidate match for a query image
    {
        Compare compareFaces("TOKEN");

        compareFaces.LoadReferences("./faces.db");

        // read the second/query picture
        unsigned char* query_pic = ReadFileAsBytes("person.jpeg");

        // measure the similarity of the two faces
        int candidate_match_id = -1;
        float candidate_match_similarity = 0.0;
        bool found_candidate_match = compareFaces.GetSimilarityBGR(query_pic, 2592, 1944, candidate_match_id, candidate_match_similarity);
        delete query_pic;

        cout << "found candidate match: "<< std::boolalpha << found_candidate_match << endl
             << "candidate match id: " << candidate_match_id << endl
             << "similarity score: " << candidate_match_similarity << endl;
    }

    return 0;
}

unsigned char *ReadFileAsBytes(string filepath) {
    ifstream ifs(filepath, ofstream::binary | ifstream::ate);
    if (!ifs.is_open()) {
        return(nullptr);
    }

    ifs.seekg(0, ifs.end);
    size_t buffer_len = static_cast<size_t>(ifs.tellg());
    ifs.seekg(0, ifs.beg);
    unsigned char* buffer = new unsigned char[buffer_len];

    ifs.read(reinterpret_cast<char*>(buffer), buffer_len);
    ifs.close();

    return buffer;
}

Trueface C++ SDK


Getting started with Trueface C++'s SDK

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.