int write_landmark_to_proto(fstream& fout, std::string data_id, MGFLandmarkMap *landmarks, size_t faceNum) {
Json::Value root;
root["data_id"] = data_id;
/*for (size_t i = 0; i < landmarks.size(); i++) {
for(size_t j = 0; j < 81; j++) {
Json::Value pt_obj;
pt_obj["left"] = landmarks[i].points[j].x;
pt_obj["top"] = landmarks[i].points[j].y;
Json::Value lmk_obj;
lmk_obj["point"] = pt_obj;
lmk_obj["name"] = facerec::LM_NAME[j];
root["contours"].append(lmk_obj);
}
}*/
for (size_t i = 0; i < faceNum;i++) {
Json::Value contour_obj;
for(size_t j = 0; j < 81; j++) {
Json::Value pt_obj;
pt_obj["left"] = landmarks[i].points[j].x;
pt_obj["top"] = landmarks[i].points[j].y;
Json::Value lmk_obj;
lmk_obj["point"] = pt_obj;
lmk_obj["name"] = LM_NAME[j];
contour_obj["contour"].append(lmk_obj);
}
root["contours"].append(contour_obj);
}
Json::FastWriter fast_writer;
std::string json_str = fast_writer.write(root);
//printf("json: %s \n", json_str.c_str());
fout<<json_str;
return 0;
}
//纯数组模式
int write_landmark_to_json_arrary(fstream& fout, MGFLandmarkMap *landmarks, size_t faceNum) {
Json::Value root;
// root["data_id"] = data_id;
/*for (size_t i = 0; i < landmarks.size(); i++) {
for(size_t j = 0; j < 81; j++) {
Json::Value pt_obj;
pt_obj["left"] = landmarks[i].points[j].x;
pt_obj["top"] = landmarks[i].points[j].y;
Json::Value lmk_obj;
lmk_obj["point"] = pt_obj;
lmk_obj["name"] = facerec::LM_NAME[j];
root["contours"].append(lmk_obj);
}
}*/
for (size_t i = 0; i < faceNum;i++) {
Json::Value contour_obj;
for(size_t j = 0; j < 81; j++) {
Json::Value lmk_obj;
{
Json::Value point_obj;
point_obj = landmarks[i].points[j].x;
lmk_obj.append(point_obj);
point_obj = landmarks[i].points[j].y;
lmk_obj.append(point_obj);
}
contour_obj.append(lmk_obj);
}
root.append(contour_obj);
}
Json::FastWriter fast_writer;
std::string json_str = fast_writer.write(root);
printf("json: %s \n", json_str.c_str());
fout<<json_str;
return 0;
}