OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
wCocoJsonSaver.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_FILESTREAM_W_COCO_JSON_SAVER_HPP
2 #define OPENPOSE_FILESTREAM_W_COCO_JSON_SAVER_HPP
3 
7 
8 namespace op
9 {
10  template<typename TDatums>
11  class WCocoJsonSaver : public WorkerConsumer<TDatums>
12  {
13  public:
14  explicit WCocoJsonSaver(const std::shared_ptr<CocoJsonSaver>& cocoJsonSaver);
15 
16  virtual ~WCocoJsonSaver();
17 
19 
20  void workConsumer(const TDatums& tDatums);
21 
22  private:
23  std::shared_ptr<CocoJsonSaver> spCocoJsonSaver;
24 
25  DELETE_COPY(WCocoJsonSaver);
26  };
27 }
28 
29 
30 
31 
32 
33 // Implementation
35 namespace op
36 {
37  template<typename TDatums>
38  WCocoJsonSaver<TDatums>::WCocoJsonSaver(const std::shared_ptr<CocoJsonSaver>& cocoJsonSaver) :
39  spCocoJsonSaver{cocoJsonSaver}
40  {
41  }
42 
43  template<typename TDatums>
45  {
46  }
47 
48  template<typename TDatums>
50  {
51  }
52 
53  template<typename TDatums>
54  void WCocoJsonSaver<TDatums>::workConsumer(const TDatums& tDatums)
55  {
56  try
57  {
58  if (checkNoNullNorEmpty(tDatums))
59  {
60  // Check tDatums->size() == 1
61  if (tDatums->size() > 1)
62  error("Function only ready for tDatums->size() == 1", __LINE__, __FUNCTION__, __FILE__);
63  // Debugging log
64  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
65  // Profiling speed
66  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
67  // T* to T
68  const auto& tDatumPtr = tDatums->at(0);
69  // Record json in COCO format
70  spCocoJsonSaver->record(
71  tDatumPtr->poseKeypoints, tDatumPtr->poseScores, tDatumPtr->name, tDatumPtr->frameNumber);
72  // Profiling speed
73  Profiler::timerEnd(profilerKey);
74  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
75  // Debugging log
76  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
77  }
78  }
79  catch (const std::exception& e)
80  {
81  this->stop();
82  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
83  }
84  }
85 
87 }
88 
89 #endif // OPENPOSE_FILESTREAM_W_COCO_JSON_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)
WCocoJsonSaver(const std::shared_ptr< CocoJsonSaver > &cocoJsonSaver)
void workConsumer(const TDatums &tDatums)
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