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 
17 
18  void workConsumer(const TDatums& tDatums);
19 
20  private:
21  const std::shared_ptr<PeopleJsonSaver> spPeopleJsonSaver;
22 
23  DELETE_COPY(WPeopleJsonSaver);
24  };
25 }
26 
27 
28 
29 
30 
31 // Implementation
33 namespace op
34 {
35  template<typename TDatums>
36  WPeopleJsonSaver<TDatums>::WPeopleJsonSaver(const std::shared_ptr<PeopleJsonSaver>& peopleJsonSaver) :
37  spPeopleJsonSaver{peopleJsonSaver}
38  {
39  }
40 
41  template<typename TDatums>
43  {
44  }
45 
46  template<typename TDatums>
47  void WPeopleJsonSaver<TDatums>::workConsumer(const TDatums& tDatums)
48  {
49  try
50  {
51  if (checkNoNullNorEmpty(tDatums))
52  {
53  // Debugging log
54  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
55  // Profiling speed
56  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
57  // Save body/face/hand keypoints to JSON file
58  const auto& tDatumFirst = (*tDatums)[0];
59  const auto baseFileName = (!tDatumFirst.name.empty() ? tDatumFirst.name
60  : std::to_string(tDatumFirst.id)) + "_keypoints";
61  const bool humanReadable = false;
62  for (auto i = 0u ; i < tDatums->size() ; i++)
63  {
64  const auto& tDatum = (*tDatums)[i];
65  // const auto fileName = baseFileName;
66  const auto fileName = baseFileName + (i != 0 ? "_" + std::to_string(i) : "");
67 
68  const std::vector<std::pair<Array<float>, std::string>> keypointVector{
69  // 2D
70  std::make_pair(tDatum.poseKeypoints, "pose_keypoints_2d"),
71  std::make_pair(tDatum.faceKeypoints, "face_keypoints_2d"),
72  std::make_pair(tDatum.handKeypoints[0], "hand_left_keypoints_2d"),
73  std::make_pair(tDatum.handKeypoints[1], "hand_right_keypoints_2d"),
74  // 3D
75  std::make_pair(tDatum.poseKeypoints3D, "pose_keypoints_3d"),
76  std::make_pair(tDatum.faceKeypoints3D, "face_keypoints_3d"),
77  std::make_pair(tDatum.handKeypoints3D[0], "hand_left_keypoints_3d"),
78  std::make_pair(tDatum.handKeypoints3D[1], "hand_right_keypoints_3d")
79  };
80  // Save keypoints
81  spPeopleJsonSaver->save(keypointVector, tDatum.poseCandidates, fileName, humanReadable);
82  }
83  // Profiling speed
84  Profiler::timerEnd(profilerKey);
85  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
86  // Debugging log
87  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
88  }
89  }
90  catch (const std::exception& e)
91  {
92  this->stop();
93  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
94  }
95  }
96 
98 }
99 
100 #endif // OPENPOSE_FILESTREAM_W_PEOPLE_JSON_SAVER_HPP
Definition: workerConsumer.hpp:10
void initializationOnThread()
Definition: wPeopleJsonSaver.hpp:42
Definition: wPeopleJsonSaver.hpp:11
WPeopleJsonSaver(const std::shared_ptr< PeopleJsonSaver > &peopleJsonSaver)
Definition: wPeopleJsonSaver.hpp:36
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:47
std::string string
Definition: cl2.hpp:574