OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
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 
17  virtual ~WGui3D();
18 
20 
21  void workConsumer(const TDatums& tDatums);
22 
23  private:
24  std::shared_ptr<Gui3D> spGui3D;
25 
26  DELETE_COPY(WGui3D);
27  };
28 }
29 
30 
31 
32 
33 
34 // Implementation
36 namespace op
37 {
38  template<typename TDatums>
39  WGui3D<TDatums>::WGui3D(const std::shared_ptr<Gui3D>& gui3D) :
40  spGui3D{gui3D}
41  {
42  }
43 
44  template<typename TDatums>
46  {
47  }
48 
49  template<typename TDatums>
51  {
52  try
53  {
54  spGui3D->initializationOnThread();
55  }
56  catch (const std::exception& e)
57  {
58  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
59  }
60  }
61 
62  template<typename TDatums>
63  void WGui3D<TDatums>::workConsumer(const TDatums& tDatums)
64  {
65  try
66  {
67  // tDatums might be empty but we still wanna update the GUI
68  if (tDatums != nullptr)
69  {
70  // Debugging log
71  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
72  // Profiling speed
73  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
74  // Update cvMat & keypoints
75  if (!tDatums->empty())
76  {
77  // Update cvMat
78  std::vector<Matrix> cvOutputDatas;
79  for (auto& tDatumPtr : *tDatums)
80  cvOutputDatas.emplace_back(tDatumPtr->cvOutputData);
81  spGui3D->setImage(cvOutputDatas);
82  // Update keypoints
83  auto& tDatumPtr = (*tDatums)[0];
84  spGui3D->setKeypoints(
85  tDatumPtr->poseKeypoints3D, tDatumPtr->faceKeypoints3D, tDatumPtr->handKeypoints3D[0],
86  tDatumPtr->handKeypoints3D[1]);
87  }
88  // Refresh/update GUI
89  spGui3D->update();
90  // Read OpenCV mat equivalent
91  if (!tDatums->empty())
92  {
93  auto& tDatumPtr = (*tDatums)[0];
94  tDatumPtr->cvOutputData3D = spGui3D->readCvMat();
95  }
96  // Profiling speed
97  if (!tDatums->empty())
98  {
99  Profiler::timerEnd(profilerKey);
100  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
101  }
102  // Debugging log
103  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
104  }
105  }
106  catch (const std::exception& e)
107  {
108  this->stop();
109  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
110  }
111  }
112 
114 }
115 
116 #endif // OPENPOSE_GUI_W_GUI_3D_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 ~WGui3D()
Definition: wGui3D.hpp:45
void initializationOnThread()
Definition: wGui3D.hpp:50
WGui3D(const std::shared_ptr< Gui3D > &gui3D)
Definition: wGui3D.hpp:39
void workConsumer(const TDatums &tDatums)
Definition: wGui3D.hpp:63
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