OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
wGui.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_GUI_W_GUI_HPP
2 #define OPENPOSE_GUI_W_GUI_HPP
3 
5 #include <openpose/gui/gui.hpp>
7 
8 namespace op
9 {
10  template<typename TDatums>
11  class WGui : public WorkerConsumer<TDatums>
12  {
13  public:
14  explicit WGui(const std::shared_ptr<Gui>& gui);
15 
16  virtual ~WGui();
17 
19 
20  void workConsumer(const TDatums& tDatums);
21 
22  private:
23  std::shared_ptr<Gui> spGui;
24 
25  DELETE_COPY(WGui);
26  };
27 }
28 
29 
30 
31 
32 
33 // Implementation
35 namespace op
36 {
37  template<typename TDatums>
38  WGui<TDatums>::WGui(const std::shared_ptr<Gui>& gui) :
39  spGui{gui}
40  {
41  }
42 
43  template<typename TDatums>
45  {
46  }
47 
48  template<typename TDatums>
50  {
51  try
52  {
53  spGui->initializationOnThread();
54  }
55  catch (const std::exception& e)
56  {
57  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
58  }
59  }
60 
61  template<typename TDatums>
62  void WGui<TDatums>::workConsumer(const TDatums& tDatums)
63  {
64  try
65  {
66  // tDatums might be empty but we still wanna update the GUI
67  if (tDatums != nullptr)
68  {
69  // Debugging log
70  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
71  // Profiling speed
72  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
73  // Update cvMat
74  if (!tDatums->empty())
75  {
76  std::vector<Matrix> cvOutputDatas;
77  for (auto& tDatumPtr : *tDatums)
78  cvOutputDatas.emplace_back(tDatumPtr->cvOutputData);
79  spGui->setImage(cvOutputDatas);
80  }
81  // Refresh/update GUI
82  spGui->update();
83  // Profiling speed
84  if (!tDatums->empty())
85  {
86  Profiler::timerEnd(profilerKey);
87  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
88  }
89  // Debugging log
90  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
91  }
92  }
93  catch (const std::exception& e)
94  {
95  this->stop();
96  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
97  }
98  }
99 
101 }
102 
103 #endif // OPENPOSE_GUI_W_GUI_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)
virtual ~WGui()
Definition: wGui.hpp:44
void initializationOnThread()
Definition: wGui.hpp:49
WGui(const std::shared_ptr< Gui > &gui)
Definition: wGui.hpp:38
void workConsumer(const TDatums &tDatums)
Definition: wGui.hpp:62
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