OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
wKeypointScaler.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_CORE_W_KEYPOINT_SCALER_HPP
2 #define OPENPOSE_CORE_W_KEYPOINT_SCALER_HPP
3 
7 
8 namespace op
9 {
10  template<typename TDatums>
11  class WKeypointScaler : public Worker<TDatums>
12  {
13  public:
14  explicit WKeypointScaler(const std::shared_ptr<KeypointScaler>& keypointScaler);
15 
16  virtual ~WKeypointScaler();
17 
19 
20  void work(TDatums& tDatums);
21 
22  private:
23  std::shared_ptr<KeypointScaler> spKeypointScaler;
24  };
25 }
26 
27 
28 
29 
30 
31 // Implementation
33 namespace op
34 {
35  template<typename TDatums>
36  WKeypointScaler<TDatums>::WKeypointScaler(const std::shared_ptr<KeypointScaler>& keypointScaler) :
37  spKeypointScaler{keypointScaler}
38  {
39  }
40 
41  template<typename TDatums>
43  {
44  }
45 
46  template<typename TDatums>
48  {
49  }
50 
51  template<typename TDatums>
52  void WKeypointScaler<TDatums>::work(TDatums& tDatums)
53  {
54  try
55  {
56  if (checkNoNullNorEmpty(tDatums))
57  {
58  // Debugging log
59  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
60  // Profiling speed
61  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
62  // Rescale pose data
63  for (auto& tDatumPtr : *tDatums)
64  {
65  std::vector<Array<float>> arraysToScale{
66  tDatumPtr->poseKeypoints, tDatumPtr->handKeypoints[0],
67  tDatumPtr->handKeypoints[1], tDatumPtr->faceKeypoints};
68  spKeypointScaler->scale(
69  arraysToScale, tDatumPtr->scaleInputToOutput, tDatumPtr->scaleNetToOutput,
70  Point<int>{tDatumPtr->cvInputData.cols(), tDatumPtr->cvInputData.rows()});
71  // Rescale part candidates
72  spKeypointScaler->scale(
73  tDatumPtr->poseCandidates, tDatumPtr->scaleInputToOutput, tDatumPtr->scaleNetToOutput,
74  Point<int>{tDatumPtr->cvInputData.cols(), tDatumPtr->cvInputData.rows()});
75  }
76  // Profiling speed
77  Profiler::timerEnd(profilerKey);
78  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
79  // Debugging log
80  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
81  }
82  }
83  catch (const std::exception& e)
84  {
85  this->stop();
86  tDatums = nullptr;
87  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
88  }
89  }
90 
92 }
93 
94 #endif // OPENPOSE_CORE_W_KEYPOINT_SCALER_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)
WKeypointScaler(const std::shared_ptr< KeypointScaler > &keypointScaler)
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