Skip to main content



The document is a continuation of the previous document, if you have landed directly on this page then, Please read from page Get started.

What is findFace component ?#

findFace component is used to find face of person.

  • Description : findFace() takes an input(through STDIN) as embeddings of 128 float in string format returns the name of person if person face found in database.
  • Parameters :
    • Input(Via STDIN) : findFace.stdin() << inputJson << std::endl;
      • An inputJson String with following parameters:
        • Parameter1 : Vector of 128 float embeddings
        • Parameter2 : Database file name (abc.txt)
    • Output(Via STDOUT) : findFace.stdout() >> outputJson;
      • An inputJson string with following contents
        • string personname if found else NULL
        • int requestID
  • Using findFace component
    • With our getEmbeddings component: To understand how to use findFace with getEmbeddings component, check this section
    • You can also use findFace with any other getEmbeddings component but inputJson should be in the mentioned format.

List of findFace features in shunya stack#

  1. Find person in database

Using findFace#

Requirements to use findFace#

  1. Shunya OS installed (supported Arm devices) or Shunya OS docker container (X86 based windows/linux devices)
  2. Shunya AI installed in Shunya OS.

Steps to use findFace#

  1. Read inputJson.
  2. Call API binary
  3. Get found person name.

Run the steps given below inside Shunya OS installed (supported Arm devices) or Shunya OS docker container (X86 based windows/linux devices) terminals.

Lets take an example use case: Say we need to

  1. find person name if given embeddings

Steps are

Step 1: Read inputJson#

  1. Start with an ready to use template for aligning faces from image.

    git clone
    cd shunya-ai-examples/indiv-components
  2. Open the examples in a text editor and modify as per your usecase.

    • For CPP you will find the examples in the folder cpp-examples/face-recognition/findFace
    • Open the file find_face.cpp
    • Modify the line to set the input json filename.
    • IMP Note: inputJsonRaw.json file contains the parameter1 and parameter2 of input. If you want to see how it looks you can check below.
    /* Reading the json file and convert it into the Json string format */
    std::ifstream ifs { R"(inputJsonRaw.json)" };
    if ( !ifs.is_open() )
    std::cerr << "Could not open file for reading!\n";
    return EXIT_FAILURE;
    IStreamWrapper isw { ifs };
    Document doc {};
    doc.ParseStream( isw );
    StringBuffer buffer {};
    Writer<StringBuffer> writer { buffer };
    doc.Accept( writer );
    if ( doc.HasParseError() )
    std::cout << "Error : " << doc.GetParseError() << '\n'
    << "Offset : " << doc.GetErrorOffset() << '\n';
    return EXIT_FAILURE;
    /* Finally we get inputJson string */
    const std::string inputJson { buffer.GetString() };

Step 2. Call API binary#

  1. We will now call API binary by giving input image(parameter1) and face info(parameter2) as an input through STDIN.
    /*################# Call findFace() Component ###################*/
    subprocess::popen findFace("/usr/bin/findFace", {});
    /* Passing inputJson to the API */
    findFace.stdin() << inputJson << std::endl;
    std::string outputJson;
    /* Getting output in outputJson */
    findFace.stdout() >> outputJson;
  2. You will get output in outputJson string.

Step 3. Get found person name.#

  1. Code to print the json output, got from findFace API.
    /* ---- Parse outputJson ---- */
    rapidjson::Document findFaceJson = readJsonString(findFaceOut);
    std::string name = findFaceJson["data"]["person"].GetString();
    /* Print person name */
    std::cout<<"\nPerson found: "<< name;

Run ready to use example.#

  1. Once you are done editing, save and run the code, by running

    mkdir build && cd build
    cmake ../
    # before running findFaceCpp make sure you have inputJsonRaw.json in build directory
  2. Running the codes will print the JSON output on the terminal (to STDOUT).

    For Example:

    • Lets say the input image is

      Oops!, No Image to display.
    • Input JSON is

      "fname": "file.txt",
      "embeddings": [{
      "value": -0.00516019,
      "value": -0.00516019,
    • Then the JSON output is

      "apiVersion": "1.2.0",
      "requestId": 1606318527,
      "data": {
      "person": "Sneha"

This part is not updated yet (please do not use below example)#

Understand this component with an example (ready to use code)#

  • This is an example for face-recognition and here we will be using 5 components: detectFaces, alignFace, getEmbeddings, storeFace, findFace

  • Check this ready to use example in c++.

    git clone
    cd shunya-ai-examples/cpp-examples/face-recognition
  • In this folder there is a file, find_face.cpp or

  • detectFaces Components used

    subprocess::popen detectFaces("/usr/bin/detectFaces", {});
    ```shell detectFaces = Popen(['/usr/bin/detectFaces'], stdout=PIPE, stdin=PIPE) ```
  • alignFace component used

    subprocess::popen alignFace("/usr/bin/alignFace", {});
    ```shell alignFace = Popen(['/usr/bin/alignFace'], stdout=PIPE, stdin=PIPE) ```
  • getEmbeddings component used

    subprocess::popen getEmbeddings("/usr/bin/getEmbeddings", {});
    ```shell getEmbeddings = Popen(['/usr/bin/getEmbeddings'], stdout=PIPE, stdin=PIPE) ```
  • storeFace component used

    subprocess::popen storeFace("/usr/bin/storeFace", {});
    ```shell storeFace = Popen(['/usr/bin/storeFace'], stdout=PIPE, stdin=PIPE) ```
  • findFace component used

    subprocess::popen findFace("/usr/bin/findFace", {});
    ```shell findFace = Popen(['/usr/bin/findFace'], stdout=PIPE, stdin=PIPE) ```
  • Run code by yourself

    mkdir build && cd build
    cmake .. && make
    ```shell python3 ```
    - You will get a name of person

Facing errors with the component?#