// target.json
"version": 1.3,
"people": [
{
"person_id": [ -1 ],
"pose_keypoints_2d": [
332.057,
110.042,
0.857808,
329.165,
130.613,
0.854567,
...
...
271.479,
325.256,
0.729781,
291.995,
317.458,
0.778235
],
"face_keypoints_2d": [],
"hand_left_keypoints_2d": [],
"hand_right_keypoints_2d": [],
"pose_keypoints_3d": [],
"face_keypoints_3d": [],
"hand_left_keypoints_3d": [],
"hand_right_keypoints_3d": []
}
]
}
"pose_keypoint_2d" 는
["Nose": 0, "Neck": 1, "RShoulder": 2, "RElbow": 3, "RWrist": 4,
"LShoulder": 5, "LElbow": 6, "LWrist": 7, "CHip":8,"RHip": 9, "RKnee": 10,
"RAnkle": 11, "LHip": 12, "LKnee": 13, "LAnkle": 14, "REye": 15,
"LEye": 16, "REar": 17, "LEar": 18, "Lfoot": 19,"Ltoe":20,"Lan":21,
"Rfoot": 22,"Rtoe":23,"Ran":24] 로 이루어져 있으며,
(아래 그림 참조)

각 Keypoint마다 (x, y, 해당 좌표가 맞을확률)로 구성되어 있다.
이 Keypoint들 값들을 추출하기 위해 JSON 파일 파싱할 라이브러리리 중 jsoncpp를 사용하게 되었다.
struct Keypoint{
double x;
double y;
double prob;
};
std::map<int, Keypoint> Keypoints;
int read_json(char *str){
Json::Value root;
std::ifstream ifs(str, std::ifstream::in);
Json::CharReaderBuilder builder;
builder["collectComments"] = false;
JSONCPP_STRING errs;
if (!parseFromStream(builder, ifs, &root, &errs)) {
std::cout << errs << std::endl;
return EXIT_FAILURE;
}
Json::Value Target = root["people"];
for(Json::ValueIterator it1 = Target.begin(); it1 != Target.end(); ++it1){
Json::Value NewTarget = (*it1)["pose_keypoints_2d"];
for(Json::ValueIterator it2 = NewTarget.begin(); it2 != NewTarget.end();){
static int key_id = 0;
Keypoint cur;
cur.x = (*it2++).asDouble();
cur.y = (*it2++).asDouble();
cur.prob = (*it2++).asDouble();
Keypoints.insert(std::pair<int, Keypoint>(key_id++, cur));
}
}
return EXIT_SUCCESS;
}
struct Keypoint{
double x;
double y;
double prob;
};
std::map<int, Keypoint> Keypoints;
int read_json(char *str){
Json::Value root;
std::ifstream ifs(str, std::ifstream::in);
Json::CharReaderBuilder builder;
builder["collectComments"] = false;
JSONCPP_STRING errs;
if (!parseFromStream(builder, ifs, &root, &errs)) {
std::cout << errs << std::endl;
return EXIT_FAILURE;
}
ifstream : https://www.cplusplus.com/reference/fstream/ifstream/?kw=ifstream
fstream : https://www.cplusplus.com/reference/fstream/fstream/?kw=fstream
(Json::CharReaderBuilder) : 파싱하면서 "주석 무시", "특수기호 무시" 등의 조건을 넣을 수 있다.
( parseFromStream() ) : Json::CharReaderBuilder, std::ifstream, Json::Value, JSONCPP_STRING 을 인자로 받으며 특정 파일에서 파싱할 수 있게 해준다.
Json::Value Target = root["people"];
for(Json::ValueIterator it1 = Target.begin(); it1 != Target.end(); ++it1){
Json::Value NewTarget = (*it1)["pose_keypoints_2d"];
for(Json::ValueIterator it2 = NewTarget.begin(); it2 != NewTarget.end();){
static int key_id = 0;
Keypoint cur;
cur.x = (*it2++).asDouble();
cur.y = (*it2++).asDouble();
cur.prob = (*it2++).asDouble();
Keypoints.insert(std::pair<int, Keypoint>(key_id++, cur));
}
}
