OpenPose 1.0.0rc2 OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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
6 #include <openpose/core/common.hpp>
7 #include <openpose/producer/datumProducer.hpp>
8 #include <openpose/thread/workerProducer.hpp>
9
10 namespace op
11 {
12 template<typename TDatums, typename TDatumsNoPtr>
13 class WDatumProducer : public WorkerProducer<TDatums>
14 {
15 public:
16 explicit WDatumProducer(const std::shared_ptr<DatumProducer<TDatumsNoPtr>>& datumProducer);
17
18 virtual ~WDatumProducer();
19
20 void initializationOnThread();
21
22 TDatums workProducer();
23
24 private:
25 std::shared_ptr<DatumProducer<TDatumsNoPtr>> spDatumProducer;
26 std::queue<TDatums> 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 TDatums, typename TDatumsNoPtr>
41 WDatumProducer<TDatums, TDatumsNoPtr>::WDatumProducer(const std::shared_ptr<DatumProducer<TDatumsNoPtr>>& datumProducer) :
42 spDatumProducer{datumProducer}
43 {
44 }
45
46 template<typename TDatums, typename TDatumsNoPtr>
47 WDatumProducer<TDatums, TDatumsNoPtr>::~WDatumProducer()
48 {
49 }
50
51
52 template<typename TDatums, typename TDatumsNoPtr>
53 void WDatumProducer<TDatums, TDatumsNoPtr>::initializationOnThread()
54 {
55 }
56
57 template<typename TDatums, typename TDatumsNoPtr>
58 TDatums WDatumProducer<TDatums, TDatumsNoPtr>::workProducer()
59 {
60 try
61 {
62 // Debugging log
63 dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
64 // Profiling speed
65 const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
66 // Create and fill TDatums
67 std::shared_ptr<TDatumsNoPtr> tDatums;
68 // Producer
69 if (mQueuedElements.empty())
70 {
71 bool isRunning;
72 std::tie(isRunning, tDatums) = spDatumProducer->checkIfRunningAndGetDatum();
73 // Stop Worker if producer finished
74 if (!isRunning)
75 this->stop();
76 // Profiling speed
77 Profiler::timerEnd(profilerKey);
78 Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
79 // Debugging log
80 dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
81 }
82 // Equivalent to WQueueSplitter
83 // Queued elements - Multiple views --> Split views into different TDatums
84 if (tDatums != nullptr && tDatums->size() > 1)
85 {
86 // Add tDatums to mQueuedElements
87 for (auto i = 0u ; i < tDatums->size() ; i++)
88 {
89 auto& tDatum = (*tDatums)[i];
90 tDatum.subId = i;
91 tDatum.subIdMax = tDatums->size()-1;
92 mQueuedElements.emplace(
93 std::make_shared<TDatumsNoPtr>(TDatumsNoPtr{tDatum}));
94 }
95 }
96 // Queued elements - Multiple views --> Return oldest view
97 if (!mQueuedElements.empty())
98 {
99 tDatums = mQueuedElements.front();
100 mQueuedElements.pop();
101 }
102 // Return TDatums
103 return tDatums;
104 }
105 catch (const std::exception& e)
106 {
107 this->stop();
108 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
109 return TDatums{};
110 }
111 }
112
113 extern template class WDatumProducer<DATUM_BASE, DATUM_BASE_NO_PTR>;
114 }
115
116 #endif // OPENPOSE_PRODUCER_W_DATUM_PRODUCER_HPP
op::Priority::Low
datumProducer.hpp
op::WDatumProducer::~WDatumProducer
virtual ~WDatumProducer()
Definition: wDatumProducer.hpp:47
common.hpp
op::WDatumProducer::initializationOnThread
void initializationOnThread()
Definition: wDatumProducer.hpp:53
op::Profiler::timerInit
static const std::string timerInit(const int line, const std::string &function, const std::string &file)
op::error
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
op::WDatumProducer::WDatumProducer
WDatumProducer(const std::shared_ptr< DatumProducer< TDatumsNoPtr >> &datumProducer)
Definition: wDatumProducer.hpp:41
datum.hpp
op::WorkerProducer
Definition: workerProducer.hpp:10
op::dLog
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
op::DatumProducer
Definition: datumProducer.hpp:15
workerProducer.hpp
op::Profiler::printAveragedTimeMsOnIterationX
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)
op::Profiler::timerEnd
static void timerEnd(const std::string &key)
op::WDatumProducer
Definition: wDatumProducer.hpp:13
op::WDatumProducer::workProducer
TDatums workProducer()
Definition: wDatumProducer.hpp:58