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 
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  dLog("", 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<cv::Mat> cvOutputDatas;
79  for (auto& tDatum : *tDatums)
80  cvOutputDatas.emplace_back(tDatum.cvOutputData);
81  spGui3D->setImage(cvOutputDatas);
82  // Update keypoints
83  auto& tDatum = (*tDatums)[0];
84  spGui3D->setKeypoints(tDatum.poseKeypoints3D, tDatum.faceKeypoints3D, tDatum.handKeypoints3D[0],
85  tDatum.handKeypoints3D[1]);
86  }
87  // Refresh/update GUI
88  spGui3D->update();
89  // Read OpenCV mat equivalent
90  if (!tDatums->empty())
91  {
92  auto& tDatum = (*tDatums)[0];
93  tDatum.cvOutputData3D = spGui3D->readCvMat();
94  }
95  // Profiling speed
96  if (!tDatums->empty())
97  {
98  Profiler::timerEnd(profilerKey);
99  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
100  }
101  // Debugging log
102  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
103  }
104  }
105  catch (const std::exception& e)
106  {
107  this->stop();
108  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
109  }
110  }
111 
113 }
114 
115 #endif // OPENPOSE_GUI_W_GUI_3D_HPP
Definition: workerConsumer.hpp:10
void workConsumer(const TDatums &tDatums)
Definition: wGui3D.hpp:63
virtual ~WGui3D()
Definition: wGui3D.hpp:45
WGui3D(const std::shared_ptr< Gui3D > &gui3D)
Definition: wGui3D.hpp:39
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:50
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