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