OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
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 
16  virtual ~WPoseTriangulation();
17 
19 
20  void work(TDatums& tDatums);
21 
22  private:
23  const std::shared_ptr<PoseTriangulation> spPoseTriangulation;
24 
25  DELETE_COPY(WPoseTriangulation);
26  };
27 }
28 
29 
30 
31 
32 
33 // Implementation
35 namespace op
36 {
37  template<typename TDatums>
38  WPoseTriangulation<TDatums>::WPoseTriangulation(const std::shared_ptr<PoseTriangulation>& poseTriangulation) :
39  spPoseTriangulation{poseTriangulation}
40  {
41  }
42 
43  template<typename TDatums>
45  {
46  }
47 
48  template<typename TDatums>
50  {
51  try
52  {
53  spPoseTriangulation->initializationOnThread();
54  }
55  catch (const std::exception& e)
56  {
57  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
58  }
59  }
60 
61  template<typename TDatums>
62  void WPoseTriangulation<TDatums>::work(TDatums& tDatums)
63  {
64  try
65  {
66  if (checkNoNullNorEmpty(tDatums))
67  {
68  // Debugging log
69  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
70  // Profiling speed
71  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
72  // 3-D triangulation and reconstruction
73  std::vector<Matrix> cameraMatrices;
74  std::vector<Array<float>> poseKeypointVector;
75  std::vector<Array<float>> faceKeypointVector;
76  std::vector<Array<float>> leftHandKeypointVector;
77  std::vector<Array<float>> rightHandKeypointVector;
78  std::vector<Point<int>> imageSizes;
79  for (auto& tDatumPtr : *tDatums)
80  {
81  poseKeypointVector.emplace_back(tDatumPtr->poseKeypoints);
82  faceKeypointVector.emplace_back(tDatumPtr->faceKeypoints);
83  leftHandKeypointVector.emplace_back(tDatumPtr->handKeypoints[0]);
84  rightHandKeypointVector.emplace_back(tDatumPtr->handKeypoints[1]);
85  cameraMatrices.emplace_back(tDatumPtr->cameraMatrix);
86  imageSizes.emplace_back(
87  Point<int>{tDatumPtr->cvInputData.cols(), tDatumPtr->cvInputData.rows()});
88  }
89  // Pose 3-D reconstruction
90  auto poseKeypoints3Ds = spPoseTriangulation->reconstructArray(
91  {poseKeypointVector, faceKeypointVector, leftHandKeypointVector, rightHandKeypointVector},
92  cameraMatrices, imageSizes);
93  // Assign to all tDatums
94  for (auto& tDatumPtr : *tDatums)
95  {
96  tDatumPtr->poseKeypoints3D = poseKeypoints3Ds[0];
97  tDatumPtr->faceKeypoints3D = poseKeypoints3Ds[1];
98  tDatumPtr->handKeypoints3D[0] = poseKeypoints3Ds[2];
99  tDatumPtr->handKeypoints3D[1] = poseKeypoints3Ds[3];
100  }
101  // Profiling speed
102  Profiler::timerEnd(profilerKey);
103  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
104  // Debugging log
105  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
106  }
107  }
108  catch (const std::exception& e)
109  {
110  this->stop();
111  tDatums = nullptr;
112  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
113  }
114  }
115 
117 }
118 
119 #endif // OPENPOSE_3D_W_POSE_TRIANGULATION_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)
WPoseTriangulation(const std::shared_ptr< PoseTriangulation > &poseTriangulation)
void work(TDatums &tDatums)
bool checkNoNullNorEmpty(const TPointerContainer &tPointerContainer)
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