16 Json::Value root, arraySkeletonPoints3D(Json::arrayValue);
17 Json::StyledStreamWriter writer;
20 for (
unsigned char i = 0; i < skeletonPoints3D.size(); i++) {
22 Json::Value singlePoint3D_JSON;
24 singlePoint3D_JSON[
"pointID"] = Json::Value((
unsigned int) i);
25 singlePoint3D_JSON[
"confidence"] = Json::Value(((
BodyKeyPoint *) skeletonPoints3D.at(i)->getDecorated())->getConfidence());
26 singlePoint3D_JSON[
"x"] = Json::Value((
double) skeletonPoints3D.at(i)->getZ());
27 singlePoint3D_JSON[
"y"] = Json::Value((
double) skeletonPoints3D.at(i)->getY());
28 singlePoint3D_JSON[
"z"] = Json::Value((
double) skeletonPoints3D.at(i)->getX());
29 singlePoint3D_JSON[
"x_rotation"] = Json::Value(0.0);
30 singlePoint3D_JSON[
"y_rotation"] = Json::Value(0.0);
31 singlePoint3D_JSON[
"z_rotation"] = Json::Value(0.0);
32 singlePoint3D_JSON[
"w_rotation"] = Json::Value(1.0);
33 arraySkeletonPoints3D.append(singlePoint3D_JSON);
36 root[
"personID"] = Json::Value((
unsigned int) personID);
37 root[
"skeleton"] = arraySkeletonPoints3D;
43 Json::Reader readerJSON;
44 std::ifstream streamJSON(filePathJSON.c_str(), std::ifstream::binary);
45 return readerJSON.parse(streamJSON, currentJSON,
false);
49 Json::StyledStreamWriter writer;
50 std::ofstream outputFile(filePath);
56 return currentJSON[key];
60 return currentJSON[i];
64 return (currentJSON[i])[key];
67void OutputManagerJSON::createJSON (Json::Value & people, cv::Mat & colorImage, cv::Mat & distanceImage, cv::Mat & skeletonOnlyImage,
unsigned int nFrame,
const char * outputFolder,
const float skeletonThreshold) {
68 Json::Value root, peopleArray(Json::arrayValue);
69 std::stringstream outputJsonFilePath;
70 root[
"ID_Frame"] = nFrame;
71 root[
"thingId"] = Json::Value(std::string(
"digitaltwin:Laboratorio_Corridoio:1"));
75 for (Json::Value::ArrayIndex i = 0; i < people.size(); i++) {
76 Json::Value singlePerson =
getValueAt(
"pose_keypoints_2d", i, people);
77 Skeleton singlePersonSkeleton =
Skeleton(colorImage, distanceImage, skeletonOnlyImage, singlePerson);
85 root[
"People"] = peopleArray;
87 outputJsonFilePath << outputFolder <<
"movement/frame" << nFrame <<
"_" <<
JSON_FILE_PATH;
88 saveJSON(std::string(outputJsonFilePath.str()));
89 outputJsonFilePath.str(std::string());
90 outputJsonFilePath.clear();
BodyKeyPoint class is used for body keypoint creations and manipulations.
void createJSON(Json::Value &people, cv::Mat &colorImage, cv::Mat &distanceImage, cv::Mat &skeletonOnlyImage, unsigned int nFrame, const char *outputFolder, const float skeletonThreshold)
This methods take a reference to a JSON node that represents all the people's informations within the...
Json::Value makeOutputString(std::vector< Point3D * > skeletonPoints3D, std::vector< bool > bodyKeyPointsMap, unsigned int frameID, unsigned int personID) override
This method is specific for saving the output in JSON format.
void saveJSON(std::string filePath)
Saves content present in the "stringOutputData" in a JSON file. The file path where to save the file ...
Json::Value getValueAt(std::string key, Json::Value currentJSON)
Utility method to get the value at a given key in a given JSON node.
bool loadJSON(std::string filePathJSON, Json::Value ¤tJSON)
Loads a JSON file and returns it as a reference. The JSON file path on disk is given.
void setStringOutputData(std::string stringOutputData)
Set the output file's content.
std::string getStringOutputData(void)
Get the output file's content.
Skeleton class is used for skeleton creations and manipulations.
float getConsistency(void)
Get the Consistency float value.
std::vector< Point3D * > * getSkeletonPoints3D(void)
Get the Skeleton Points3D vector's pointer.
std::vector< bool > getBodyKeyPointsMap(void)
Get the BodyKeyPoints Map vector.
void generateSkeleton(void)
A high-level method that abstracts all the internal structure and operations of the Skeleton class....
static const char * JSON_FILE_PATH
static const short int openPoseBodyKeyPointsNumber