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
wPoseTriangulation.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_3D_W_POSE_TRIANGULATION_HPP
2 #define OPENPOSE_3D_W_POSE_TRIANGULATION_HPP
3 
7 
8 namespace op
9 {
10  template<typename TDatums>
11  class WPoseTriangulation : public Worker<TDatums>
12  {
13  public:
14  explicit WPoseTriangulation(const std::shared_ptr<PoseTriangulation>& poseTriangulation);
15 
17 
18  void work(TDatums& tDatums);
19 
20  private:
21  const std::shared_ptr<PoseTriangulation> spPoseTriangulation;
22 
23  DELETE_COPY(WPoseTriangulation);
24  };
25 }
26 
27 
28 
29 
30 
31 // Implementation
33 namespace op
34 {
35  template<typename TDatums>
36  WPoseTriangulation<TDatums>::WPoseTriangulation(const std::shared_ptr<PoseTriangulation>& poseTriangulation) :
37  spPoseTriangulation{poseTriangulation}
38  {
39  }
40 
41  template<typename TDatums>
43  {
44  try
45  {
46  spPoseTriangulation->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 WPoseTriangulation<TDatums>::work(TDatums& tDatums)
56  {
57  try
58  {
59  if (checkNoNullNorEmpty(tDatums))
60  {
61  // Debugging log
62  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
63  // Profiling speed
64  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
65  // 3-D triangulation and reconstruction
66  std::vector<cv::Mat> cameraMatrices;
67  std::vector<Array<float>> poseKeypointVector;
68  std::vector<Array<float>> faceKeypointVector;
69  std::vector<Array<float>> leftHandKeypointVector;
70  std::vector<Array<float>> rightHandKeypointVector;
71  std::vector<Point<int>> imageSizes;
72  for (auto& datumsElement : *tDatums)
73  {
74  poseKeypointVector.emplace_back(datumsElement.poseKeypoints);
75  faceKeypointVector.emplace_back(datumsElement.faceKeypoints);
76  leftHandKeypointVector.emplace_back(datumsElement.handKeypoints[0]);
77  rightHandKeypointVector.emplace_back(datumsElement.handKeypoints[1]);
78  cameraMatrices.emplace_back(datumsElement.cameraMatrix);
79  imageSizes.emplace_back(Point<int>{datumsElement.cvInputData.cols,
80  datumsElement.cvInputData.rows});
81  }
82  // Pose 3-D reconstruction
83  auto poseKeypoints3Ds = spPoseTriangulation->reconstructArray(
84  {poseKeypointVector, faceKeypointVector, leftHandKeypointVector, rightHandKeypointVector},
85  cameraMatrices, imageSizes);
86  // Assign to all tDatums
87  for (auto& datumsElement : *tDatums)
88  {
89  datumsElement.poseKeypoints3D = poseKeypoints3Ds[0];
90  datumsElement.faceKeypoints3D = poseKeypoints3Ds[1];
91  datumsElement.handKeypoints3D[0] = poseKeypoints3Ds[2];
92  datumsElement.handKeypoints3D[1] = poseKeypoints3Ds[3];
93  }
94  // Profiling speed
95  Profiler::timerEnd(profilerKey);
96  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
97  // Debugging log
98  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
99  }
100  }
101  catch (const std::exception& e)
102  {
103  this->stop();
104  tDatums = nullptr;
105  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
106  }
107  }
108 
110 }
111 
112 #endif // OPENPOSE_3D_W_POSE_TRIANGULATION_HPP
Definition: worker.hpp:9
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="")
WPoseTriangulation(const std::shared_ptr< PoseTriangulation > &poseTriangulation)
Definition: wPoseTriangulation.hpp:36
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
bool checkNoNullNorEmpty(const TPointerContainer &tPointerContainer)
Definition: pointerContainer.hpp:7
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)
Definition: wPoseTriangulation.hpp:11
void work(TDatums &tDatums)
Definition: wPoseTriangulation.hpp:55
void initializationOnThread()
Definition: wPoseTriangulation.hpp:42
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
static void timerEnd(const std::string &key)