Test json output

This commit is contained in:
Ruben 2017-11-12 23:23:09 +01:00
parent 8cc19d9a54
commit 4ab47dcfa4

View file

@ -19,6 +19,65 @@
using namespace std;
using namespace affdex;
std::string getAsJson(const std::map<FaceId, Face> faces, const double timeStamp)
{
std::stringstream ss;
ss << "{" << "'t':" << timeStamp << ",";
ss << "'faces':[";
int i(0);
for (auto & face_id_pair : faces)
{
Face f = face_id_pair.second;
if(i > 0) { ss << ","; }
i++;
ss << "{";
// fStream << timeStamp << ","
// << f.id << ","
// << f.measurements.interocularDistance << ","
// << glassesMap[f.appearance.glasses] << ","
// << ageMap[f.appearance.age] << ","
// << ethnicityMap[f.appearance.ethnicity] << ","
// << genderMap[f.appearance.gender] << ","
// << affdex::EmojiToString(f.emojis.dominantEmoji) << ",";
float *values = (float *)&f.measurements.orientation;
for (std::string angle : PlottingImageListener.headAngles)
{
ss << "'" << angle << "':" << (*values) << ",";
values++;
}
values = (float *)&f.emotions;
for (std::string emotion : PlottingImageListener.emotions)
{
ss << "'" << emotion << "':" << (*values) << ",";
values++;
}
values = (float *)&f.expressions;
for (std::string expression : PlottingImageListener.expressions)
{
ss << "'" << expression << "':" << (*values) << ",";
values++;
}
ss << "'ioDistance':"<< f.measurements.interocularDistance << ",";
ss << "'id':"<< f.id;
ss << "}";
}
ss << "]"; // faces
ss << "}";
return ss.str();
}
/// <summary>
/// Project for demoing the Windows SDK CameraDetector class (grabbing and processing frames from the camera).
/// </summary>
@ -230,60 +289,3 @@ int main(int argsc, char ** argsv)
return 0;
}
std::string getAsJson(const std::map<FaceId, Face> faces, const double timeStamp)
{
std::stringstream ss;
ss << "{" << "'t':" << timeStamp << ",";
ss << "'faces':[";
int i(0);
for (auto & face_id_pair : faces)
{
Face f = face_id_pair.second;
if(i > 0) { ss << ","; }
i++
ss << "{";
// fStream << timeStamp << ","
// << f.id << ","
// << f.measurements.interocularDistance << ","
// << glassesMap[f.appearance.glasses] << ","
// << ageMap[f.appearance.age] << ","
// << ethnicityMap[f.appearance.ethnicity] << ","
// << genderMap[f.appearance.gender] << ","
// << affdex::EmojiToString(f.emojis.dominantEmoji) << ",";
float *values = (float *)&f.measurements.orientation;
for (std::string angle : affdex::PlottingImageListener.headAngles)
{
ss << "'" << angle << "':" (*values) << ",";
values++;
}
values = (float *)&f.emotions;
for (std::string emotion : affdex::PlottingImageListener.emotions)
{
ss << "'" << emotion << "':" (*values) << ",";
values++;
}
values = (float *)&f.expressions;
for (std::string expression : affdex::PlottingImageListener.expressions)
{
ss << "'" << expression << "':" (*values) << ",";
values++;
}
ss << "'ioDistance':"<< f.measurements.interocularDistance << ",";
ss << "'id':"<< f.id;
ss << "}";
}
ss << "]"; // faces
ss << "}";
return ss.str();
}