Search code examples
c++jsonoscsupercollideropenpose

Is it possible to output JSON data from the OpenPose library in real-time?


I'm trying to use the OpenPose pose estimation library (C++) to output body position information in order to create sound using SuperCollider.

The JSON information is outputted as a file, I would like to output the data in real-time. I have tried looking through the source code of OpenPose and could not find any specific section where the output format is specified. The header files in the "filestream" folder only seem to contain variable declarations, as shown below:

#ifndef 
OPENPOSE_FILESTREAM_DATA_SAVER_HPP
#define 
OPENPOSE_FILESTREAM_DATA_SAVER_HPP

#include <openpose/core/common.hpp>
#include <openpose/utilities/string.hpp>

namespace op
{
    class OP_API FileSaver
    {
     protected:
        explicit FileSaver(const std::string& directoryPath);

        virtual ~FileSaver();

        std::string getNextFileName(const unsigned long long index) const;

        std::string getNextFileName(const std::string& fileNameNoExtension) const;

    private:
        const std::string mDirectoryPath;
    };
}

#endif // OPENPOSE_FILESTREAM_DATA_SAVER_HPP

I expected to find a file path or something similar, to lead me in the direction of where the data is outputted from. If anyone is familiar with this library and could point me in the right direction it would be much appreciated.

My plan is to use the Quarks API to send the keypoint data to SuperCollider through OSC. I am using MacOS X 10.11.6.


Solution

  • if you have downloaded the openpose sample code, in the file openpose.cpp, you would find the line

    DEFINE_string(write_json,"","Directory to write OpenPose output in JSON format. It includes body, hand, and face pose keypoints (2-D and 3-D), as well as pose candidates (if `--part_candidates` enabled).");
    

    The path of json output file is specified by the argument --write_json of main. For example:

    c:>openpose.exe --video "D:\user\video.avi"--write_json "D:\user\desktop\output.json"

    The input is the video "D:\user\video.avi" and the json output is "D:\user\desktop\output.json"

    Note: if you do not use the argument --write_json, it will not write json output.

    Update 1: if you want to access directly to keypoints you can follow the How to access pose keypoint