OpenPose  1.0.0rc2
OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
wGui.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_GUI_W_GUI_HPP
2 #define OPENPOSE_GUI_W_GUI_HPP
3 
6 #include <openpose/gui/gui.hpp>
8 
9 namespace op
10 {
11  template<typename TDatums>
12  class WGui : public WorkerConsumer<TDatums>
13  {
14  public:
15  explicit WGui(const std::shared_ptr<Gui>& gui);
16 
18 
19  void workConsumer(const TDatums& tDatums);
20 
21  private:
22  std::shared_ptr<Gui> spGui;
23 
24  DELETE_COPY(WGui);
25  };
26 }
27 
28 
29 
30 
31 
32 // Implementation
34 namespace op
35 {
36  template<typename TDatums>
37  WGui<TDatums>::WGui(const std::shared_ptr<Gui>& gui) :
38  spGui{gui}
39  {
40  }
41 
42  template<typename TDatums>
44  {
45  try
46  {
47  spGui->initializationOnThread();
48  }
49  catch (const std::exception& e)
50  {
51  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
52  }
53  }
54 
55  template<typename TDatums>
56  void WGui<TDatums>::workConsumer(const TDatums& tDatums)
57  {
58  try
59  {
60  if (tDatums != nullptr)
61  {
62  // Check tDatums->size() == 1
63  if (tDatums->size() > 1)
64  error("Only implemented for tDatums->size() == 1", __LINE__, __FUNCTION__, __FILE__);
65  // Debugging log
66  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
67  // Profiling speed
68  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
69  // T* to T
70  auto& tDatumsNoPtr = *tDatums;
71  // Refresh GUI
72  const auto cvOutputData = (!tDatumsNoPtr.empty() ? tDatumsNoPtr[0].cvOutputData : cv::Mat());
73  spGui->update(cvOutputData);
74  // Profiling speed
75  if (!tDatumsNoPtr.empty())
76  {
77  Profiler::timerEnd(profilerKey);
78  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__, Profiler::DEFAULT_X);
79  }
80  // Debugging log
81  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
82  }
83  }
84  catch (const std::exception& e)
85  {
86  this->stop();
87  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
88  }
89  }
90 
92 }
93 
94 #endif // OPENPOSE_GUI_W_GUI_HPP
Definition: workerConsumer.hpp:10
Definition: wGui.hpp:12
void workConsumer(const TDatums &tDatums)
Definition: wGui.hpp:56
void initializationOnThread()
Definition: wGui.hpp:43
static const unsigned long long DEFAULT_X
Definition: profiler.hpp:24
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:47
COMPILE_TEMPLATE_DATUM(WCvMatToOpInput)
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)
WGui(const std::shared_ptr< Gui > &gui)
Definition: wGui.hpp:37
static void timerEnd(const std::string &key)