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
wFaceSaver.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_FILESTREAM_W_FACE_SAVER_HPP
2 #define OPENPOSE_FILESTREAM_W_FACE_SAVER_HPP
3 
8 
9 namespace op
10 {
11  template<typename TDatums>
12  class WFaceSaver : public WorkerConsumer<TDatums>
13  {
14  public:
15  explicit WFaceSaver(const std::shared_ptr<KeypointSaver>& keypointSaver);
16 
18 
19  void workConsumer(const TDatums& tDatums);
20 
21  private:
22  const std::shared_ptr<KeypointSaver> spKeypointSaver;
23 
24  DELETE_COPY(WFaceSaver);
25  };
26 }
27 
28 
29 
30 
31 
32 // Implementation
34 namespace op
35 {
36  template<typename TDatums>
37  WFaceSaver<TDatums>::WFaceSaver(const std::shared_ptr<KeypointSaver>& keypointSaver) :
38  spKeypointSaver{keypointSaver}
39  {
40  }
41 
42  template<typename TDatums>
44  {
45  }
46 
47  template<typename TDatums>
48  void WFaceSaver<TDatums>::workConsumer(const TDatums& tDatums)
49  {
50  try
51  {
52  if (checkNoNullNorEmpty(tDatums))
53  {
54  // Debugging log
55  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
56  // Profiling speed
57  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
58  // T* to T
59  auto& tDatumsNoPtr = *tDatums;
60  // Record people face keypoint data
61  std::vector<Array<float>> keypointVector(tDatumsNoPtr.size());
62  for (auto i = 0u; i < tDatumsNoPtr.size(); i++)
63  keypointVector[i] = tDatumsNoPtr[i].faceKeypoints;
64  const auto fileName = (!tDatumsNoPtr[0].name.empty() ? tDatumsNoPtr[0].name : std::to_string(tDatumsNoPtr[0].id));
65  spKeypointSaver->saveKeypoints(keypointVector, fileName, "face");
66  // Profiling speed
67  Profiler::timerEnd(profilerKey);
68  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
69  // Debugging log
70  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
71  }
72  }
73  catch (const std::exception& e)
74  {
75  this->stop();
76  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
77  }
78  }
79 
81 }
82 
83 #endif // OPENPOSE_FILESTREAM_W_FACE_SAVER_HPP
void initializationOnThread()
Definition: wFaceSaver.hpp:43
Definition: workerConsumer.hpp:10
void workConsumer(const TDatums &tDatums)
Definition: wFaceSaver.hpp:48
Definition: wFaceSaver.hpp:12
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)
WFaceSaver(const std::shared_ptr< KeypointSaver > &keypointSaver)
Definition: wFaceSaver.hpp:37