Interfacing with OpenFace: C++ & Terminal

Here I detail my experiments in interfacing with OpenFace using C++ and the terminal.

When provided with the initial prototype made by Sjaak Verwaaijen my goal was to better see how to integrate OpenFace with a custom application. The more I looked at it, however, the more I thought it should not be necessary to integrate the library at all. One of the goals of the pipeline is to be modular and allow developers to (relatively) easily swap out the analysis library. Integrating it tightly with the analysis application does not aid in this goal.

This sentiment was solidified when I saw support for running OpenFace from the terminal. My idea was as follows: what if, instead of integrating OpenFace with the analysis service, I instead run a standalone instance of OpenFace concurrently:

Diagram of how running OpenFace concurrently would work.

To see if this would work, I decided to create a test script. In this, I set up a REST server and allow the user to send an image URL. This image is then downloaded using curl and analysed. OpenFace automatically generates a .csv file with the generated data.

std::string Analyse(std::string body, std::string& randomString)
    {
        std::cout << "Analysing using OpenFace";

        //Build string and download image using curl command
        std::string imageName = "Image" + randomString;
        std::string curlCommandString = "cd ~/Projects/OpenFace/OpenFace/build/TestImages && curl " + body + " > " + imageName + ".png";
        const char * curlCommandChar = curlCommandString.c_str();
        system(curlCommandChar);

        //Run analysis
        system("cd ~/Projects/OpenFace/OpenFace/build/ && ./bin/FaceLandmarkImg -fdir \"TestImages\" -wild");

        delete curlCommandChar;

        //Get and return contents of generated csv file
        return GetCsvContents(imageName);
    }

Conclusion

This seems like a good way to get an MVP up and running quickly while not compromising on the overall goals of the project. It is both easier to set up and makes it so there is little dependence on the chosen facial analysis library. As long as there is a .csv at the correct place, this will work.

Last updated

Was this helpful?