OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
wPoseSaver.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_FILESTREAM_W_POSE_SAVER_HPP
2 #define OPENPOSE_FILESTREAM_W_POSE_SAVER_HPP
3 
8 
9 namespace op
10 {
11  template<typename TDatums>
12  class WPoseSaver : public WorkerConsumer<TDatums>
13  {
14  public:
15  explicit WPoseSaver(const std::shared_ptr<KeypointSaver>& keypointSaver);
16 
17  virtual ~WPoseSaver();
18 
20 
21  void workConsumer(const TDatums& tDatums);
22 
23  private:
24  const std::shared_ptr<KeypointSaver> spKeypointSaver;
25 
26  DELETE_COPY(WPoseSaver);
27  };
28 }
29 
30 
31 
32 
33 
34 // Implementation
36 namespace op
37 {
38  template<typename TDatums>
39  WPoseSaver<TDatums>::WPoseSaver(const std::shared_ptr<KeypointSaver>& keypointSaver) :
40  spKeypointSaver{keypointSaver}
41  {
42  }
43 
44  template<typename TDatums>
46  {
47  }
48 
49  template<typename TDatums>
51  {
52  }
53 
54  template<typename TDatums>
55  void WPoseSaver<TDatums>::workConsumer(const TDatums& tDatums)
56  {
57  try
58  {
59  if (checkNoNullNorEmpty(tDatums))
60  {
61  // Debugging log
62  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
63  // Profiling speed
64  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
65  // T* to T
66  auto& tDatumsNoPtr = *tDatums;
67  // Record people pose keypoint data
68  std::vector<Array<float>> keypointVector(tDatumsNoPtr.size());
69  for (auto i = 0u; i < tDatumsNoPtr.size(); i++)
70  keypointVector[i] = tDatumsNoPtr[i]->poseKeypoints;
71  const auto fileName = (!tDatumsNoPtr[0]->name.empty()
72  ? tDatumsNoPtr[0]->name : std::to_string(tDatumsNoPtr[0]->id));
73  spKeypointSaver->saveKeypoints(keypointVector, fileName, "pose");
74  // Profiling speed
75  Profiler::timerEnd(profilerKey);
76  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
77  // Debugging log
78  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
79  }
80  }
81  catch (const std::exception& e)
82  {
83  this->stop();
84  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
85  }
86  }
87 
89 }
90 
91 #endif // OPENPOSE_FILESTREAM_W_POSE_SAVER_HPP
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)
static const std::string timerInit(const int line, const std::string &function, const std::string &file)
static void timerEnd(const std::string &key)
void workConsumer(const TDatums &tDatums)
Definition: wPoseSaver.hpp:55
void initializationOnThread()
Definition: wPoseSaver.hpp:50
virtual ~WPoseSaver()
Definition: wPoseSaver.hpp:45
WPoseSaver(const std::shared_ptr< KeypointSaver > &keypointSaver)
Definition: wPoseSaver.hpp:39
bool checkNoNullNorEmpty(const TPointerContainer &tPointerContainer)
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
void opLogIfDebug(const T &message, const Priority priority=Priority::Max, const int line=-1, const std::string &function="", const std::string &file="")
Definition: errorAndLog.hpp:97