OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
wHandSaver.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_FILESTREAM_W_HAND_SAVER_HPP
2 #define OPENPOSE_FILESTREAM_W_HAND_SAVER_HPP
3 
8 
9 namespace op
10 {
11  template<typename TDatums>
12  class WHandSaver : public WorkerConsumer<TDatums>
13  {
14  public:
15  explicit WHandSaver(const std::shared_ptr<KeypointSaver>& keypointSaver);
16 
17  virtual ~WHandSaver();
18 
20 
21  void workConsumer(const TDatums& tDatums);
22 
23  private:
24  const std::shared_ptr<KeypointSaver> spKeypointSaver;
25 
26  DELETE_COPY(WHandSaver);
27  };
28 }
29 
30 
31 
32 
33 
34 // Implementation
36 namespace op
37 {
38  template<typename TDatums>
39  WHandSaver<TDatums>::WHandSaver(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 WHandSaver<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 hand keypoint data
68  const auto fileName = (!tDatumsNoPtr[0]->name.empty()
69  ? tDatumsNoPtr[0]->name : std::to_string(tDatumsNoPtr[0]->id));
70  std::vector<Array<float>> keypointVector(tDatumsNoPtr.size());
71  // Left hand
72  for (auto i = 0u; i < tDatumsNoPtr.size(); i++)
73  keypointVector[i] = tDatumsNoPtr[i]->handKeypoints[0];
74  spKeypointSaver->saveKeypoints(keypointVector, fileName, "hand_left");
75  // Right hand
76  for (auto i = 0u; i < tDatumsNoPtr.size(); i++)
77  keypointVector[i] = tDatumsNoPtr[i]->handKeypoints[1];
78  spKeypointSaver->saveKeypoints(keypointVector, fileName, "hand_right");
79  // Profiling speed
80  Profiler::timerEnd(profilerKey);
81  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
82  // Debugging log
83  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
84  }
85  }
86  catch (const std::exception& e)
87  {
88  this->stop();
89  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
90  }
91  }
92 
94 }
95 
96 #endif // OPENPOSE_FILESTREAM_W_HAND_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 initializationOnThread()
Definition: wHandSaver.hpp:50
WHandSaver(const std::shared_ptr< KeypointSaver > &keypointSaver)
Definition: wHandSaver.hpp:39
virtual ~WHandSaver()
Definition: wHandSaver.hpp:45
void workConsumer(const TDatums &tDatums)
Definition: wHandSaver.hpp:55
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