OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
wDatumProducer.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_PRODUCER_W_DATUM_PRODUCER_HPP
2 #define OPENPOSE_PRODUCER_W_DATUM_PRODUCER_HPP
3 
4 #include <limits> // std::numeric_limits
5 #include <queue> // std::queue
9 
10 namespace op
11 {
12  template<typename TDatum>
13  class WDatumProducer : public WorkerProducer<std::shared_ptr<std::vector<std::shared_ptr<TDatum>>>>
14  {
15  public:
16  explicit WDatumProducer(const std::shared_ptr<DatumProducer<TDatum>>& datumProducer);
17 
18  virtual ~WDatumProducer();
19 
21 
22  std::shared_ptr<std::vector<std::shared_ptr<TDatum>>> workProducer();
23 
24  private:
25  std::shared_ptr<DatumProducer<TDatum>> spDatumProducer;
26  std::queue<std::shared_ptr<std::vector<std::shared_ptr<TDatum>>>> mQueuedElements;
27 
28  DELETE_COPY(WDatumProducer);
29  };
30 }
31 
32 
33 
34 
35 
36 // Implementation
37 #include <openpose/core/datum.hpp>
38 namespace op
39 {
40  template<typename TDatum>
42  const std::shared_ptr<DatumProducer<TDatum>>& datumProducer) :
43  spDatumProducer{datumProducer}
44  {
45  }
46 
47  template<typename TDatum>
49  {
50  }
51 
52 
53  template<typename TDatum>
55  {
56  }
57 
58  template<typename TDatum>
59  std::shared_ptr<std::vector<std::shared_ptr<TDatum>>> WDatumProducer<TDatum>::workProducer()
60  {
61  try
62  {
63  // Debugging log
64  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
65  // Profiling speed
66  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
67  // Create and fill final shared pointer
68  std::shared_ptr<std::vector<std::shared_ptr<TDatum>>> tDatums;
69  // Producer
70  if (mQueuedElements.empty())
71  {
72  bool isRunning;
73  std::tie(isRunning, tDatums) = spDatumProducer->checkIfRunningAndGetDatum();
74  // Stop Worker if producer finished
75  if (!isRunning)
76  this->stop();
77  // Profiling speed
78  Profiler::timerEnd(profilerKey);
79  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
80  // Debugging log
81  opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
82  }
83  // Equivalent to WQueueSplitter
84  // Queued elements - Multiple views --> Split views into different shared pointers
85  if (tDatums != nullptr && tDatums->size() > 1)
86  {
87  // Add tDatums to mQueuedElements
88  for (auto i = 0u ; i < tDatums->size() ; i++)
89  {
90  auto& tDatumPtr = (*tDatums)[i];
91  tDatumPtr->subId = i;
92  tDatumPtr->subIdMax = tDatums->size()-1;
93  mQueuedElements.emplace(
94  std::make_shared<std::vector<std::shared_ptr<TDatum>>>(
95  std::vector<std::shared_ptr<TDatum>>{tDatumPtr}));
96  }
97  }
98  // Queued elements - Multiple views --> Return oldest view
99  if (!mQueuedElements.empty())
100  {
101  tDatums = mQueuedElements.front();
102  mQueuedElements.pop();
103  }
104  // Return result
105  return tDatums;
106  }
107  catch (const std::exception& e)
108  {
109  this->stop();
110  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
111  return nullptr;
112  }
113  }
114 
115  extern template class WDatumProducer<BASE_DATUM>;
116 }
117 
118 #endif // OPENPOSE_PRODUCER_W_DATUM_PRODUCER_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)
WDatumProducer(const std::shared_ptr< DatumProducer< TDatum >> &datumProducer)
std::shared_ptr< std::vector< std::shared_ptr< TDatum > > > workProducer()
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