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
wHeatMapSaver.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_FILESTREAM_W_HEAT_MAP_SAVER_HPP
2 #define OPENPOSE_FILESTREAM_W_HEAT_MAP_SAVER_HPP
3 
7 
8 namespace op
9 {
10  template<typename TDatums>
11  class WHeatMapSaver : public WorkerConsumer<TDatums>
12  {
13  public:
14  explicit WHeatMapSaver(const std::shared_ptr<HeatMapSaver>& heatMapSaver);
15 
17 
18  void workConsumer(const TDatums& tDatums);
19 
20  private:
21  const std::shared_ptr<HeatMapSaver> spHeatMapSaver;
22 
23  DELETE_COPY(WHeatMapSaver);
24  };
25 }
26 
27 
28 
29 
30 
31 // Implementation
33 namespace op
34 {
35  template<typename TDatums>
36  WHeatMapSaver<TDatums>::WHeatMapSaver(const std::shared_ptr<HeatMapSaver>& heatMapSaver) :
37  spHeatMapSaver{heatMapSaver}
38  {
39  }
40 
41  template<typename TDatums>
43  {
44  }
45 
46  template<typename TDatums>
47  void WHeatMapSaver<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  // T* to T
58  auto& tDatumsNoPtr = *tDatums;
59  // Record pose heatmap image(s) on disk
60  std::vector<Array<float>> poseHeatMaps(tDatumsNoPtr.size());
61  for (auto i = 0u; i < tDatumsNoPtr.size(); i++)
62  poseHeatMaps[i] = tDatumsNoPtr[i].poseHeatMaps;
63  const auto fileName = (!tDatumsNoPtr[0].name.empty()
64  ? tDatumsNoPtr[0].name : std::to_string(tDatumsNoPtr[0].id)) + "_pose_heatmaps";
65  spHeatMapSaver->saveHeatMaps(poseHeatMaps, fileName);
66  // Profiling speed
67  Profiler::timerEnd(profilerKey);
69  __LINE__, __FUNCTION__, __FILE__);
70  // Debugging log
71  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
72  }
73  }
74  catch (const std::exception& e)
75  {
76  this->stop();
77  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
78  }
79  }
80 
82 }
83 
84 #endif // OPENPOSE_FILESTREAM_W_HEAT_MAP_SAVER_HPP
Definition: workerConsumer.hpp:10
void initializationOnThread()
Definition: wHeatMapSaver.hpp:42
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
WHeatMapSaver(const std::shared_ptr< HeatMapSaver > &heatMapSaver)
Definition: wHeatMapSaver.hpp:36
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)
Definition: wHeatMapSaver.hpp:11
void workConsumer(const TDatums &tDatums)
Definition: wHeatMapSaver.hpp:47
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
static void timerEnd(const std::string &key)