AI Watch A1
Multi-person 3D skeleton detection using Intel RealSense and OpenPose with Kafka support.
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
OutputManagerJSON Class Reference

OutputManagerJSON class is a class that abstracts final JSON output-producing operations. More...

#include <OutputManager.hpp>

Inheritance diagram for OutputManagerJSON:
OutputManager

Public Member Functions

bool loadJSON (std::string filePathJSON, Json::Value &currentJSON)
 Loads a JSON file and returns it as a reference. The JSON file path on disk is given. More...
 
void saveJSON (std::string filePath)
 Saves content present in the "stringOutputData" in a JSON file. The file path where to save the file is given. More...
 
Json::Value getValueAt (std::string key, Json::Value currentJSON)
 Utility method to get the value at a given key in a given JSON node. More...
 
Json::Value getValueAt (unsigned int i, Json::Value currentJSON)
 Utility method to get i-th value in a given JSON node. More...
 
Json::Value getValueAt (std::string key, unsigned int i, Json::Value currentJSON)
 Utility method to get the value at a given key of the i-th value in a given JSON node. More...
 
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 frame, color, depth, distance, and skeleton-only frame, the current frame ID, and the output folder's path on disk and for each person in the people's JSON node, the method extracts, generates, and appends a single Skeleton to the current JSON node. More...
 

Protected Member Functions

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. More...
 
void setStringOutputData (std::string stringOutputData)
 Set the output file's content. More...
 
std::string getStringOutputData (void)
 Get the output file's content. More...
 

Private Attributes

std::string stringOutputData
 Output file's content. More...
 

Detailed Description

OutputManagerJSON class is a class that abstracts final JSON output-producing operations.

Definition at line 73 of file OutputManager.hpp.

Member Function Documentation

◆ createJSON()

void OutputManagerJSON::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 frame, color, depth, distance, and skeleton-only frame, the current frame ID, and the output folder's path on disk and for each person in the people's JSON node, the method extracts, generates, and appends a single Skeleton to the current JSON node.

Parameters
peopleJSON node containing people's informations detected within the frame.
colorImagecolor frame.
distanceImagedistance frame.
skeletonOnlyImageskeleton-only frame.
nFramecurrent image ID.
outputFolderoutput folder's path on disk.
skeletonThresholdThe magnitude or intensity that must be exceeded for a specific reaction, phenomenon, result, or condition to occur or be manifested. In this case, if the skeleton's confidence mean value is greater than "skeletonThreshold", then the skeleton will be considered a meaningful skeleton.
See also
Skeleton.hpp

Definition at line 67 of file OutputManagerJSON.cpp.

67 {
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"));
72
73
74 // For each OpenPose's detected skeleton
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);
78 singlePersonSkeleton.generateSkeleton();
79 // Discard Skeleton with low consistency value
80 if (singlePersonSkeleton.getConsistency() > skeletonThreshold) {
81 peopleArray.append(makeOutputString(* singlePersonSkeleton.getSkeletonPoints3D(), singlePersonSkeleton.getBodyKeyPointsMap(), nFrame, (unsigned int) i));
82 }
83 }
84
85 root["People"] = peopleArray;
86 OutputManager::setStringOutputData(root.toStyledString());
87 outputJsonFilePath << outputFolder << "movement/frame" << nFrame << "_" << JSON_FILE_PATH;
88 saveJSON(std::string(outputJsonFilePath.str()));
89 outputJsonFilePath.str(std::string());
90 outputJsonFilePath.clear();
91}
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.
void setStringOutputData(std::string stringOutputData)
Set the output file's content.
Skeleton class is used for skeleton creations and manipulations.
Definition: Skeleton.hpp:37
float getConsistency(void)
Get the Consistency float value.
Definition: Skeleton.cpp:222
std::vector< Point3D * > * getSkeletonPoints3D(void)
Get the Skeleton Points3D vector's pointer.
Definition: Skeleton.cpp:218
std::vector< bool > getBodyKeyPointsMap(void)
Get the BodyKeyPoints Map vector.
Definition: Skeleton.cpp:69
void generateSkeleton(void)
A high-level method that abstracts all the internal structure and operations of the Skeleton class....
Definition: Skeleton.cpp:203
static const char * JSON_FILE_PATH
Definition: constants.hpp:58

References Skeleton::generateSkeleton(), Skeleton::getBodyKeyPointsMap(), Skeleton::getConsistency(), Skeleton::getSkeletonPoints3D(), getValueAt(), JSON_FILE_PATH, makeOutputString(), saveJSON(), and OutputManager::setStringOutputData().

Referenced by OpenCV_Manager::showSkeletonsCV().

◆ getStringOutputData()

std::string OutputManager::getStringOutputData ( void  )
protectedinherited

Get the output file's content.

Returns
std::string

Definition at line 19 of file OutputManager.cpp.

19 {
20 return this->stringOutputData;
21}
std::string stringOutputData
Output file's content.

References OutputManager::stringOutputData.

Referenced by saveJSON().

◆ getValueAt() [1/3]

Json::Value OutputManagerJSON::getValueAt ( std::string  key,
Json::Value  currentJSON 
)

Utility method to get the value at a given key in a given JSON node.

Parameters
keyKey at which the value in the JSON node will be found.
currentJSONReference to JSON node.
Returns
Json::Value

Definition at line 55 of file OutputManagerJSON.cpp.

55 {
56 return currentJSON[key];
57}

Referenced by Skeleton::calcBodyKeypoints(), createJSON(), and OpenCV_Manager::showSkeletonsCV().

◆ getValueAt() [2/3]

Json::Value OutputManagerJSON::getValueAt ( std::string  key,
unsigned int  i,
Json::Value  currentJSON 
)

Utility method to get the value at a given key of the i-th value in a given JSON node.

Parameters
keyKey at which the value in the JSON node will be found.
iIndex at which the value in the JSON node will be found.
currentJSONReference to JSON node.
Returns
Json::Value

Definition at line 63 of file OutputManagerJSON.cpp.

63 {
64 return (currentJSON[i])[key];
65}

◆ getValueAt() [3/3]

Json::Value OutputManagerJSON::getValueAt ( unsigned int  i,
Json::Value  currentJSON 
)

Utility method to get i-th value in a given JSON node.

Parameters
iIndex at which the value in the JSON node will be found.
currentJSONReference to JSON node.
Returns
Json::Value

Definition at line 59 of file OutputManagerJSON.cpp.

59 {
60 return currentJSON[i];
61}

◆ loadJSON()

bool OutputManagerJSON::loadJSON ( std::string  filePathJSON,
Json::Value &  currentJSON 
)

Loads a JSON file and returns it as a reference. The JSON file path on disk is given.

Parameters
filePathJSONJSON file path on disk.
currentJSONJSON reference where the JSON file will be load.
Returns
true if the file-loading ends correctly.
false if the file-loading does not end correctly.

Definition at line 42 of file OutputManagerJSON.cpp.

42 {
43 Json::Reader readerJSON;
44 std::ifstream streamJSON(filePathJSON.c_str(), std::ifstream::binary);
45 return readerJSON.parse(streamJSON, currentJSON, false);
46}

Referenced by FacadeSingleton::sendData(), and OpenCV_Manager::showSkeletonsCV().

◆ makeOutputString()

Json::Value OutputManagerJSON::makeOutputString ( std::vector< Point3D * >  skeletonPoints3D,
std::vector< bool >  bodyKeyPointsMap,
unsigned int  frameID,
unsigned int  personID 
)
overrideprotectedvirtual

This method is specific for saving the output in JSON format.

Parameters
skeletonPoints3DA vector that contains pointers to Points3D whose coordinates represent the skeleton's junctions in certain space coordinates.
bodyKeyPointsMapA vector that contains for each body joint retrieved from OpenPose a corresponding boolean that means if that body joint is a valuable and effective body joint or not.
frameIDcurrent frame ID.
personIDcurrent person ID within the current frame.
Returns
Json::Value

Implements OutputManager.

Definition at line 15 of file OutputManagerJSON.cpp.

15 {
16 Json::Value root, arraySkeletonPoints3D(Json::arrayValue);
17 Json::StyledStreamWriter writer;
18
19 // For each OpenPose's skeleton body joint point
20 for (unsigned char i = 0; i < skeletonPoints3D.size(); i++) {
21 if (i >= openPoseBodyKeyPointsNumber) continue;
22 Json::Value singlePoint3D_JSON;
23 // Build JSON node for i-th body joint point
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);
34 }
35
36 root["personID"] = Json::Value((unsigned int) personID);
37 root["skeleton"] = arraySkeletonPoints3D;
38 OutputManager::setStringOutputData(root.toStyledString());
39 return root;
40}
BodyKeyPoint class is used for body keypoint creations and manipulations.
static const short int openPoseBodyKeyPointsNumber
Definition: constants.hpp:68

References openPoseBodyKeyPointsNumber, and OutputManager::setStringOutputData().

Referenced by createJSON().

◆ saveJSON()

void OutputManagerJSON::saveJSON ( std::string  filePath)

Saves content present in the "stringOutputData" in a JSON file. The file path where to save the file is given.

Parameters
filePathThe file path where to save the JSON file.

Definition at line 48 of file OutputManagerJSON.cpp.

48 {
49 Json::StyledStreamWriter writer;
50 std::ofstream outputFile(filePath);
52 outputFile.close();
53}
std::string getStringOutputData(void)
Get the output file's content.

References OutputManager::getStringOutputData().

Referenced by createJSON().

◆ setStringOutputData()

void OutputManager::setStringOutputData ( std::string  stringOutputData)
protectedinherited

Set the output file's content.

Parameters
stringOutputData

Definition at line 15 of file OutputManager.cpp.

15 {
17}

References OutputManager::stringOutputData.

Referenced by createJSON(), and makeOutputString().

Member Data Documentation

◆ stringOutputData

std::string OutputManager::stringOutputData
privateinherited

Output file's content.

Definition at line 37 of file OutputManager.hpp.

Referenced by OutputManager::getStringOutputData(), and OutputManager::setStringOutputData().


The documentation for this class was generated from the following files: