From 4ab47dcfa43468e3309b7072fc9af6e66b4367da Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 12 Nov 2017 23:23:09 +0100 Subject: [PATCH] Test json output --- opencv-webcam-demo/opencv-webcam-demo.cpp | 116 +++++++++++----------- 1 file changed, 59 insertions(+), 57 deletions(-) diff --git a/opencv-webcam-demo/opencv-webcam-demo.cpp b/opencv-webcam-demo/opencv-webcam-demo.cpp index 92e5e33..144b5b8 100644 --- a/opencv-webcam-demo/opencv-webcam-demo.cpp +++ b/opencv-webcam-demo/opencv-webcam-demo.cpp @@ -19,6 +19,65 @@ using namespace std; using namespace affdex; + +std::string getAsJson(const std::map 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(); +} + + /// /// Project for demoing the Windows SDK CameraDetector class (grabbing and processing frames from the camera). /// @@ -230,60 +289,3 @@ int main(int argsc, char ** argsv) return 0; } - -std::string getAsJson(const std::map 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(); -}