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
wGui3D.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_GUI_W_GUI_3D_HPP
2 #define OPENPOSE_GUI_W_GUI_3D_HPP
3 
5 #include <openpose/gui/gui3D.hpp>
7 
8 namespace op
9 {
10  template<typename TDatums>
11  class WGui3D : public WorkerConsumer<TDatums>
12  {
13  public:
14  explicit WGui3D(const std::shared_ptr<Gui3D>& gui3D);
15 
17 
18  void workConsumer(const TDatums& tDatums);
19 
20  private:
21  std::shared_ptr<Gui3D> spGui3D;
22 
23  DELETE_COPY(WGui3D);
24  };
25 }
26 
27 
28 
29 
30 
31 // Implementation
33 namespace op
34 {
35  template<typename TDatums>
36  WGui3D<TDatums>::WGui3D(const std::shared_ptr<Gui3D>& gui3D) :
37  spGui3D{gui3D}
38  {
39  }
40 
41  template<typename TDatums>
43  {
44  try
45  {
46  spGui3D->initializationOnThread();
47  }
48  catch (const std::exception& e)
49  {
50  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
51  }
52  }
53 
54  template<typename TDatums>
55  void WGui3D<TDatums>::workConsumer(const TDatums& tDatums)
56  {
57  try
58  {
59  // tDatums might be empty but we still wanna update the GUI
60  if (tDatums != nullptr)
61  {
62  // Debugging log
63  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
64  // Profiling speed
65  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
66  // Update cvMat & keypoints
67  if (!tDatums->empty())
68  {
69  // Update cvMat
70  std::vector<cv::Mat> cvOutputDatas;
71  for (auto& tDatum : *tDatums)
72  cvOutputDatas.emplace_back(tDatum.cvOutputData);
73  spGui3D->setImage(cvOutputDatas);
74  // Update keypoints
75  auto& tDatum = (*tDatums)[0];
76  spGui3D->setKeypoints(tDatum.poseKeypoints3D, tDatum.faceKeypoints3D, tDatum.handKeypoints3D[0],
77  tDatum.handKeypoints3D[1]);
78  }
79  // Refresh/update GUI
80  spGui3D->update();
81  // Profiling speed
82  if (!tDatums->empty())
83  {
84  Profiler::timerEnd(profilerKey);
85  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
86  }
87  // Debugging log
88  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
89  }
90  }
91  catch (const std::exception& e)
92  {
93  this->stop();
94  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
95  }
96  }
97 
99 }
100 
101 #endif // OPENPOSE_GUI_W_GUI_3D_HPP
Definition: workerConsumer.hpp:10
void workConsumer(const TDatums &tDatums)
Definition: wGui3D.hpp:55
WGui3D(const std::shared_ptr< Gui3D > &gui3D)
Definition: wGui3D.hpp:36
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
void initializationOnThread()
Definition: wGui3D.hpp:42
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)
Definition: wGui3D.hpp:11