OpenPose  1.0.0rc2
OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
wPeopleJsonSaver.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_FILESTREAM_W_PEOPLE_JSON_SAVER_HPP
2 #define OPENPOSE_FILESTREAM_W_PEOPLE_JSON_SAVER_HPP
3 
7 
8 namespace op
9 {
10  template<typename TDatums>
11  class WPeopleJsonSaver : public WorkerConsumer<TDatums>
12  {
13  public:
14  explicit WPeopleJsonSaver(const std::shared_ptr<PeopleJsonSaver>& peopleJsonSaver);
15 
16  virtual ~WPeopleJsonSaver();
17 
19 
20  void workConsumer(const TDatums& tDatums);
21 
22  private:
23  const std::shared_ptr<PeopleJsonSaver> spPeopleJsonSaver;
24 
25  DELETE_COPY(WPeopleJsonSaver);
26  };
27 }
28 
29 
30 
31 
32 
33 // Implementation
35 namespace op
36 {
37  template<typename TDatums>
38  WPeopleJsonSaver<TDatums>::WPeopleJsonSaver(const std::shared_ptr<PeopleJsonSaver>& peopleJsonSaver) :
39  spPeopleJsonSaver{peopleJsonSaver}
40  {
41  }
42 
43  template<typename TDatums>
45  {
46  }
47 
48  template<typename TDatums>
50  {
51  }
52 
53  template<typename TDatums>
54  void WPeopleJsonSaver<TDatums>::workConsumer(const TDatums& tDatums)
55  {
56  try
57  {
58  if (checkNoNullNorEmpty(tDatums))
59  {
60  // Debugging log
61  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
62  // Profiling speed
63  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
64  // Save body/face/hand keypoints to JSON file
65  const auto& tDatumFirst = (*tDatums)[0];
66  const auto baseFileName = (!tDatumFirst.name.empty() ? tDatumFirst.name
67  : std::to_string(tDatumFirst.id)) + "_keypoints";
68  const bool humanReadable = false;
69  for (auto i = 0u ; i < tDatums->size() ; i++)
70  {
71  const auto& tDatum = (*tDatums)[i];
72  // const auto fileName = baseFileName;
73  const auto fileName = baseFileName + (i != 0 ? "_" + std::to_string(i) : "");
74 
75  const std::vector<std::pair<Array<float>, std::string>> keypointVector{
76  // 2D
77  std::make_pair(tDatum.poseKeypoints, "pose_keypoints_2d"),
78  std::make_pair(tDatum.faceKeypoints, "face_keypoints_2d"),
79  std::make_pair(tDatum.handKeypoints[0], "hand_left_keypoints_2d"),
80  std::make_pair(tDatum.handKeypoints[1], "hand_right_keypoints_2d"),
81  // 3D
82  std::make_pair(tDatum.poseKeypoints3D, "pose_keypoints_3d"),
83  std::make_pair(tDatum.faceKeypoints3D, "face_keypoints_3d"),
84  std::make_pair(tDatum.handKeypoints3D[0], "hand_left_keypoints_3d"),
85  std::make_pair(tDatum.handKeypoints3D[1], "hand_right_keypoints_3d")
86  };
87  // Save keypoints
88  spPeopleJsonSaver->save(keypointVector, tDatum.poseCandidates, fileName, humanReadable);
89  }
90  // Profiling speed
91  Profiler::timerEnd(profilerKey);
92  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
93  // Debugging log
94  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
95  }
96  }
97  catch (const std::exception& e)
98  {
99  this->stop();
100  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
101  }
102  }
103 
105 }
106 
107 #endif // OPENPOSE_FILESTREAM_W_PEOPLE_JSON_SAVER_HPP
Definition: workerConsumer.hpp:10
void initializationOnThread()
Definition: wPeopleJsonSaver.hpp:49
Definition: wPeopleJsonSaver.hpp:11
WPeopleJsonSaver(const std::shared_ptr< PeopleJsonSaver > &peopleJsonSaver)
Definition: wPeopleJsonSaver.hpp:38
virtual ~WPeopleJsonSaver()
Definition: wPeopleJsonSaver.hpp:44
static const std::string timerInit(const int line, const std::string &function, const std::string &file)
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
void dLog(const T &message, const Priority priority=Priority::Max, const int line=-1, const std::string &function="", const std::string &file="")
Definition: errorAndLog.hpp:53
bool checkNoNullNorEmpty(const TPointerContainer &tPointerContainer)
Definition: pointerContainer.hpp:7
static void printAveragedTimeMsOnIterationX(const std::string &key, const int line, const std::string &function, const std::string &file, const unsigned long long x=DEFAULT_X)
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
static void timerEnd(const std::string &key)
void workConsumer(const TDatums &tDatums)
Definition: wPeopleJsonSaver.hpp:54
std::string string
Definition: cl2.hpp:574