| | #ifndef OPENPOSE_WRAPPER_WRAPPER_HPP |
| | #define OPENPOSE_WRAPPER_WRAPPER_HPP |
| |
|
| | #include <openpose/core/common.hpp> |
| | #include <openpose/thread/headers.hpp> |
| | #include <openpose/wrapper/enumClasses.hpp> |
| | #include <openpose/wrapper/wrapperStructExtra.hpp> |
| | #include <openpose/wrapper/wrapperStructFace.hpp> |
| | #include <openpose/wrapper/wrapperStructGui.hpp> |
| | #include <openpose/wrapper/wrapperStructHand.hpp> |
| | #include <openpose/wrapper/wrapperStructInput.hpp> |
| | #include <openpose/wrapper/wrapperStructOutput.hpp> |
| | #include <openpose/wrapper/wrapperStructPose.hpp> |
| |
|
| | namespace op |
| | { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | template<typename TDatum = BASE_DATUM, |
| | typename TDatums = std::vector<std::shared_ptr<TDatum>>, |
| | typename TDatumsSP = std::shared_ptr<TDatums>, |
| | typename TWorker = std::shared_ptr<Worker<TDatumsSP>>> |
| | class WrapperT |
| | { |
| | public: |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | explicit WrapperT(const ThreadManagerMode threadManagerMode = ThreadManagerMode::Synchronous); |
| |
|
| | |
| | |
| | |
| | |
| | virtual ~WrapperT(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | void disableMultiThreading(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | void setWorker(const WorkerType workerType, const TWorker& worker, const bool workerOnNewThread = true); |
| |
|
| | |
| | |
| | |
| | void configure(const WrapperStructPose& wrapperStructPose); |
| |
|
| | |
| | |
| | |
| | void configure(const WrapperStructFace& wrapperStructFace); |
| |
|
| | |
| | |
| | |
| | void configure(const WrapperStructHand& wrapperStructHand); |
| |
|
| | |
| | |
| | |
| | void configure(const WrapperStructExtra& wrapperStructExtra); |
| |
|
| | |
| | |
| | |
| | void configure(const WrapperStructInput& wrapperStructInput); |
| |
|
| | |
| | |
| | |
| | void configure(const WrapperStructOutput& wrapperStructOutput); |
| |
|
| | |
| | |
| | |
| | void configure(const WrapperStructGui& wrapperStructGui); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | void exec(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | void start(); |
| |
|
| | |
| | |
| | |
| | |
| | void stop(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | bool isRunning() const; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | void setDefaultMaxSizeQueues(const long long defaultMaxSizeQueues = -1); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | bool tryEmplace(TDatumsSP& tDatums); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | bool waitAndEmplace(TDatumsSP& tDatums); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | bool waitAndEmplace(Matrix& matrix); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | bool tryPush(const TDatumsSP& tDatums); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | bool waitAndPush(const TDatumsSP& tDatums); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | bool waitAndPush(const Matrix& matrix); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | bool tryPop(TDatumsSP& tDatums); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | bool waitAndPop(TDatumsSP& tDatums); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | bool emplaceAndPop(TDatumsSP& tDatums); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | TDatumsSP emplaceAndPop(const Matrix& matrix); |
| |
|
| | private: |
| | const ThreadManagerMode mThreadManagerMode; |
| | ThreadManager<TDatumsSP> mThreadManager; |
| | bool mMultiThreadEnabled; |
| | |
| | WrapperStructPose mWrapperStructPose; |
| | WrapperStructFace mWrapperStructFace; |
| | WrapperStructHand mWrapperStructHand; |
| | WrapperStructExtra mWrapperStructExtra; |
| | WrapperStructInput mWrapperStructInput; |
| | WrapperStructOutput mWrapperStructOutput; |
| | WrapperStructGui mWrapperStructGui; |
| | |
| | std::array<bool, int(WorkerType::Size)> mUserWsOnNewThread; |
| | std::array<std::vector<TWorker>, int(WorkerType::Size)> mUserWs; |
| |
|
| | DELETE_COPY(WrapperT); |
| | }; |
| |
|
| | |
| | typedef WrapperT<BASE_DATUM> Wrapper; |
| | } |
| |
|
| |
|
| |
|
| |
|
| |
|
| | |
| | #include <openpose/wrapper/wrapperAuxiliary.hpp> |
| | namespace op |
| | { |
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::WrapperT(const ThreadManagerMode threadManagerMode) : |
| | mThreadManagerMode{threadManagerMode}, |
| | mThreadManager{threadManagerMode}, |
| | mMultiThreadEnabled{true} |
| | { |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::~WrapperT() |
| | { |
| | try |
| | { |
| | stop(); |
| | |
| | mThreadManager.reset(); |
| | |
| | for (auto& userW : mUserWs) |
| | userW.clear(); |
| | } |
| | catch (const std::exception& e) |
| | { |
| | errorDestructor(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | void WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::disableMultiThreading() |
| | { |
| | try |
| | { |
| | mMultiThreadEnabled = false; |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | void WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::setWorker( |
| | const WorkerType workerType, const TWorker& worker, const bool workerOnNewThread) |
| | { |
| | try |
| | { |
| | |
| | if (worker == nullptr) |
| | error("Your worker is a nullptr.", __LINE__, __FILE__, __FUNCTION__); |
| | |
| | mUserWs[int(workerType)].clear(); |
| | mUserWs[int(workerType)].emplace_back(worker); |
| | mUserWsOnNewThread[int(workerType)] = workerOnNewThread; |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | void WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::configure(const WrapperStructPose& wrapperStructPose) |
| | { |
| | try |
| | { |
| | mWrapperStructPose = wrapperStructPose; |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | void WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::configure(const WrapperStructFace& wrapperStructFace) |
| | { |
| | try |
| | { |
| | mWrapperStructFace = wrapperStructFace; |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | void WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::configure(const WrapperStructHand& wrapperStructHand) |
| | { |
| | try |
| | { |
| | mWrapperStructHand = wrapperStructHand; |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | void WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::configure(const WrapperStructExtra& wrapperStructExtra) |
| | { |
| | try |
| | { |
| | mWrapperStructExtra = wrapperStructExtra; |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | void WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::configure(const WrapperStructInput& wrapperStructInput) |
| | { |
| | try |
| | { |
| | mWrapperStructInput = wrapperStructInput; |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | void WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::configure(const WrapperStructOutput& wrapperStructOutput) |
| | { |
| | try |
| | { |
| | mWrapperStructOutput = wrapperStructOutput; |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | void WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::configure(const WrapperStructGui& wrapperStructGui) |
| | { |
| | try |
| | { |
| | mWrapperStructGui = wrapperStructGui; |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | void WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::exec() |
| | { |
| | try |
| | { |
| | configureThreadManager<TDatum, TDatums, TDatumsSP, TWorker>( |
| | mThreadManager, mMultiThreadEnabled, mThreadManagerMode, mWrapperStructPose, mWrapperStructFace, |
| | mWrapperStructHand, mWrapperStructExtra, mWrapperStructInput, mWrapperStructOutput, mWrapperStructGui, |
| | mUserWs, mUserWsOnNewThread); |
| | opLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__); |
| | mThreadManager.exec(); |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | void WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::start() |
| | { |
| | try |
| | { |
| | configureThreadManager<TDatum, TDatums, TDatumsSP, TWorker>( |
| | mThreadManager, mMultiThreadEnabled, mThreadManagerMode, mWrapperStructPose, mWrapperStructFace, |
| | mWrapperStructHand, mWrapperStructExtra, mWrapperStructInput, mWrapperStructOutput, mWrapperStructGui, |
| | mUserWs, mUserWsOnNewThread); |
| | opLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__); |
| | mThreadManager.start(); |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | void WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::stop() |
| | { |
| | try |
| | { |
| | mThreadManager.stop(); |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | bool WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::isRunning() const |
| | { |
| | try |
| | { |
| | return mThreadManager.isRunning(); |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | return false; |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | void WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::setDefaultMaxSizeQueues(const long long defaultMaxSizeQueues) |
| | { |
| | try |
| | { |
| | mThreadManager.setDefaultMaxSizeQueues(defaultMaxSizeQueues); |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | bool WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::tryEmplace(TDatumsSP& tDatums) |
| | { |
| | try |
| | { |
| | if (!mUserWs[int(WorkerType::Input)].empty()) |
| | error("Emplace cannot be called if an input worker was already selected.", |
| | __LINE__, __FUNCTION__, __FILE__); |
| | |
| | if (tDatums->size() < 2) |
| | { |
| | return mThreadManager.tryEmplace(tDatums); |
| | } |
| | |
| | else |
| | { |
| | bool successfulEmplace = true; |
| | for (auto datumIndex = 0u; datumIndex < tDatums->size(); ++datumIndex) |
| | { |
| | auto tDatumsSingle = std::make_shared<TDatums>(TDatums({ tDatums->at(datumIndex) })); |
| | if (!tryEmplace(tDatumsSingle)) |
| | { |
| | successfulEmplace = false; |
| | break; |
| | } |
| | } |
| | return successfulEmplace; |
| | } |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | return false; |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | bool WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::waitAndEmplace(TDatumsSP& tDatums) |
| | { |
| | try |
| | { |
| | if (!mUserWs[int(WorkerType::Input)].empty()) |
| | error("Emplace cannot be called if an input worker was already selected.", |
| | __LINE__, __FUNCTION__, __FILE__); |
| | |
| | if (tDatums->size() < 2) |
| | { |
| | return mThreadManager.waitAndEmplace(tDatums); |
| | } |
| | |
| | else |
| | { |
| | bool successfulEmplace = true; |
| | for (auto datumIndex = 0u ; datumIndex < tDatums->size() ; ++datumIndex) |
| | { |
| | auto tDatumsSingle = std::make_shared<TDatums>(TDatums({tDatums->at(datumIndex)})); |
| | if (!waitAndEmplace(tDatumsSingle)) |
| | { |
| | successfulEmplace = false; |
| | opLog("Waiting to emplace for multi-camera failed.", |
| | Priority::High, __LINE__, __FUNCTION__, __FILE__); |
| | break; |
| | } |
| | } |
| | return successfulEmplace; |
| | } |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | return false; |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | bool WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::waitAndEmplace(Matrix& matrix) |
| | { |
| | try |
| | { |
| | |
| | auto datumsPtr = std::make_shared<std::vector<std::shared_ptr<TDatum>>>(); |
| | datumsPtr->emplace_back(); |
| | auto& tDatumPtr = datumsPtr->at(0); |
| | tDatumPtr = std::make_shared<TDatum>(); |
| | |
| | std::swap(tDatumPtr->cvInputData, matrix); |
| | |
| | return waitAndEmplace(datumsPtr); |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | return false; |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | bool WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::tryPush(const TDatumsSP& tDatums) |
| | { |
| | try |
| | { |
| | if (!mUserWs[int(WorkerType::Input)].empty()) |
| | error("Push cannot be called if an input worker was already selected.", |
| | __LINE__, __FUNCTION__, __FILE__); |
| | return mThreadManager.tryPush(tDatums); |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | return false; |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | bool WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::waitAndPush(const TDatumsSP& tDatums) |
| | { |
| | try |
| | { |
| | if (!mUserWs[int(WorkerType::Input)].empty()) |
| | error("Push cannot be called if an input worker was already selected.", |
| | __LINE__, __FUNCTION__, __FILE__); |
| | return mThreadManager.waitAndPush(tDatums); |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | return false; |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | bool WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::waitAndPush(const Matrix& matrix) |
| | { |
| | try |
| | { |
| | |
| | auto datumsPtr = std::make_shared<std::vector<std::shared_ptr<TDatum>>>(); |
| | datumsPtr->emplace_back(); |
| | auto& tDatumPtr = datumsPtr->at(0); |
| | tDatumPtr = std::make_shared<TDatum>(); |
| | |
| | tDatumPtr->cvInputData = matrix.clone(); |
| | |
| | return waitAndEmplace(datumsPtr); |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | return false; |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | bool WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::tryPop(TDatumsSP& tDatums) |
| | { |
| | try |
| | { |
| | if (!mUserWs[int(WorkerType::Output)].empty()) |
| | error("Pop cannot be called if an output worker was already selected.", |
| | __LINE__, __FUNCTION__, __FILE__); |
| | return mThreadManager.tryPop(tDatums); |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | return false; |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | bool WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::waitAndPop(TDatumsSP& tDatums) |
| | { |
| | try |
| | { |
| | if (!mUserWs[int(WorkerType::Output)].empty()) |
| | error("Pop cannot be called if an output worker was already selected.", |
| | __LINE__, __FUNCTION__, __FILE__); |
| | return mThreadManager.waitAndPop(tDatums); |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | return false; |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | bool WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::emplaceAndPop(TDatumsSP& tDatums) |
| | { |
| | try |
| | { |
| | |
| | if (waitAndEmplace(tDatums)) |
| | return waitAndPop(tDatums); |
| | return false; |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | return false; |
| | } |
| | } |
| |
|
| | template<typename TDatum, typename TDatums, typename TDatumsSP, typename TWorker> |
| | TDatumsSP WrapperT<TDatum, TDatums, TDatumsSP, TWorker>::emplaceAndPop(const Matrix& matrix) |
| | { |
| | try |
| | { |
| | |
| | auto datumsPtr = std::make_shared<std::vector<std::shared_ptr<TDatum>>>(); |
| | datumsPtr->emplace_back(); |
| | auto& tDatumPtr = datumsPtr->at(0); |
| | tDatumPtr = std::make_shared<TDatum>(); |
| | |
| | tDatumPtr->cvInputData = matrix; |
| | |
| | emplaceAndPop(datumsPtr); |
| | |
| | return datumsPtr; |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | return TDatumsSP{}; |
| | } |
| | } |
| |
|
| | extern template class WrapperT<BASE_DATUM>; |
| | } |
| |
|
| | #endif |
| |
|