OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
wFpsMax.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_THREAD_W_FPS_MAX_HPP
2 #define OPENPOSE_THREAD_W_FPS_MAX_HPP
3 
4 #include <thread>
8 
9 namespace op
10 {
11  template<typename TDatums>
12  class WFpsMax : public Worker<TDatums>
13  {
14  public:
15  explicit WFpsMax(const double fpsMax);
16 
17  virtual ~WFpsMax();
18 
20 
21  void work(TDatums& tDatums);
22 
23  private:
24  const unsigned long long mNanosecondsToSleep;
25 
26  DELETE_COPY(WFpsMax);
27  };
28 }
29 
30 
31 
32 
33 
34 // Implementation
35 namespace op
36 {
37  template<typename TDatums>
38  WFpsMax<TDatums>::WFpsMax(const double fpsMax) :
39  mNanosecondsToSleep{uLongLongRound(1e9/fpsMax)}
40  {
41  }
42 
43  template<typename TDatums>
45  {
46  }
47 
48  template<typename TDatums>
50  {
51  }
52 
53  template<typename TDatums>
54  void WFpsMax<TDatums>::work(TDatums& tDatums)
55  {
56  try
57  {
58  // Debugging log
59  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
60  // Profiling speed
61  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
62  // tDatums not used --> Avoid warning
63  UNUSED(tDatums);
64  // Sleep the desired time
65  std::this_thread::sleep_for(std::chrono::nanoseconds{mNanosecondsToSleep});
66  // Profiling speed
67  Profiler::timerEnd(profilerKey);
68  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
69  // Debugging log
70  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
71  }
72  catch (const std::exception& e)
73  {
74  this->stop();
75  tDatums = nullptr;
76  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
77  }
78  }
79 
81 }
82 
83 #endif // OPENPOSE_THREAD_W_FPS_MAX_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)
void work(TDatums &tDatums)
Definition: wFpsMax.hpp:54
virtual ~WFpsMax()
Definition: wFpsMax.hpp:44
void initializationOnThread()
Definition: wFpsMax.hpp:49
WFpsMax(const double fpsMax)
Definition: wFpsMax.hpp:38
#define UNUSED(unusedVariable)
Definition: macros.hpp:30
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
unsigned long long uLongLongRound(const T a)
Definition: fastMath.hpp:66
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