OpenPose  1.0.0rc2
OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
op::Wrapper< TDatums, TWorker, TQueue > Class Template Reference

#include <wrapper.hpp>

Public Member Functions

 Wrapper (const ThreadManagerMode threadManagerMode=ThreadManagerMode::Synchronous)
 
 ~Wrapper ()
 
void disableMultiThreading ()
 
void setWorkerInput (const TWorker &worker, const bool workerOnNewThread=true)
 
void setWorkerPostProcessing (const TWorker &worker, const bool workerOnNewThread=true)
 
void setWorkerOutput (const TWorker &worker, const bool workerOnNewThread=true)
 
void configure (const WrapperStructPose &wrapperStructPose, const WrapperStructInput &wrapperStructInput, const WrapperStructOutput &wrapperStructOutput=WrapperStructOutput{})
 
void configure (const WrapperStructPose &wrapperStructPose, const WrapperStructHand &wrapperStructHand, const WrapperStructInput &wrapperStructInput, const WrapperStructOutput &wrapperStructOutput=WrapperStructOutput{})
 
void configure (const WrapperStructPose &wrapperStructPose, const WrapperStructFace &wrapperStructFace, const WrapperStructInput &wrapperStructInput, const WrapperStructOutput &wrapperStructOutput=WrapperStructOutput{})
 
void configure (const WrapperStructPose &wrapperStructPose=WrapperStructPose{}, const WrapperStructFace &wrapperStructFace=WrapperStructFace{}, const WrapperStructHand &wrapperStructHand=WrapperStructHand{}, const WrapperStructInput &wrapperStructInput=WrapperStructInput{}, const WrapperStructOutput &wrapperStructOutput=WrapperStructOutput{})
 
void exec ()
 
void start ()
 
void stop ()
 
bool isRunning () const
 
bool tryEmplace (std::shared_ptr< TDatums > &tDatums)
 
bool waitAndEmplace (std::shared_ptr< TDatums > &tDatums)
 
bool tryPush (const std::shared_ptr< TDatums > &tDatums)
 
bool waitAndPush (const std::shared_ptr< TDatums > &tDatums)
 
bool tryPop (std::shared_ptr< TDatums > &tDatums)
 
bool waitAndPop (std::shared_ptr< TDatums > &tDatums)
 

Detailed Description

template<typename TDatums, typename TWorker = std::shared_ptr<Worker<std::shared_ptr<TDatums>>>, typename TQueue = Queue<std::shared_ptr<TDatums>>>
class op::Wrapper< TDatums, TWorker, TQueue >

Wrapper: OpenPose all-in-one wrapper template class. Wrapper allows the user to set up the input (video, webcam, custom input, etc.), pose, face and/or hands estimation and rendering, and output (integrated small GUI, custom output, etc.).

This function can be used in 2 ways:

  • Synchronous mode: call the full constructor with your desired input and output workers.
  • Asynchronous mode: call the empty constructor Wrapper() + use the emplace and pop functions to push the original frames and retrieve the processed ones.
  • Mix of them:
    • Synchronous input + asynchronous output: call the constructor Wrapper(ThreadManagerMode::Synchronous, workersInput, {}, true)
    • Asynchronous input + synchronous output: call the constructor Wrapper(ThreadManagerMode::Synchronous, nullptr, workersOutput, irrelevantBoolean, true)

Constructor & Destructor Documentation

template<typename TDatums , typename TWorker , typename TQueue >
op::Wrapper< TDatums, TWorker, TQueue >::Wrapper ( const ThreadManagerMode  threadManagerMode = ThreadManagerMode::Synchronous)
explicit

Constructor.

Parameters
threadManagerModeThread syncronization mode. If set to ThreadManagerMode::Synchronous, everything will run inside the Wrapper. If ThreadManagerMode::Synchronous(In/Out), then input (frames producer) and/or output (GUI, writing results, etc.) will be controlled outside the Wrapper class by the user. See ThreadManagerMode for a detailed explanation of when to use each one.
template<typename TDatums , typename TWorker , typename TQueue >
op::Wrapper< TDatums, TWorker, TQueue >::~Wrapper ( )

Destructor. It automatically frees resources.

Member Function Documentation

template<typename TDatums , typename TWorker , typename TQueue >
void op::Wrapper< TDatums, TWorker, TQueue >::configure ( const WrapperStructPose wrapperStructPose,
const WrapperStructInput wrapperStructInput,
const WrapperStructOutput wrapperStructOutput = WrapperStructOutput{} 
)
template<typename TDatums , typename TWorker , typename TQueue >
void op::Wrapper< TDatums, TWorker, TQueue >::configure ( const WrapperStructPose wrapperStructPose,
const WrapperStructHand wrapperStructHand,
const WrapperStructInput wrapperStructInput,
const WrapperStructOutput wrapperStructOutput = WrapperStructOutput{} 
)
template<typename TDatums , typename TWorker , typename TQueue >
void op::Wrapper< TDatums, TWorker, TQueue >::configure ( const WrapperStructPose wrapperStructPose,
const WrapperStructFace wrapperStructFace,
const WrapperStructInput wrapperStructInput,
const WrapperStructOutput wrapperStructOutput = WrapperStructOutput{} 
)
template<typename TDatums , typename TWorker , typename TQueue >
void op::Wrapper< TDatums, TWorker, TQueue >::configure ( const WrapperStructPose wrapperStructPose = WrapperStructPose{},
const WrapperStructFace wrapperStructFace = WrapperStructFace{},
const WrapperStructHand wrapperStructHand = WrapperStructHand{},
const WrapperStructInput wrapperStructInput = WrapperStructInput{},
const WrapperStructOutput wrapperStructOutput = WrapperStructOutput{} 
)
template<typename TDatums , typename TWorker , typename TQueue >
void op::Wrapper< TDatums, TWorker, TQueue >::disableMultiThreading ( )

Disable multi-threading. Useful for debugging and logging, all the Workers will run in the same thread. Note that workerOnNewThread (argument for setWorkerInput, setWorkerPostProcessing and setWorkerOutput) will not make any effect.

template<typename TDatums , typename TWorker , typename TQueue >
void op::Wrapper< TDatums, TWorker, TQueue >::exec ( )

Function to start multi-threading. Similar to start(), but exec() blocks the thread that calls the function (it saves 1 thread). Use exec() instead of start() if the calling thread will otherwise be waiting for the Wrapper to end.

template<typename TDatums , typename TWorker , typename TQueue >
bool op::Wrapper< TDatums, TWorker, TQueue >::isRunning ( ) const

Whether the Wrapper is running. It will return true after exec() or start() and before stop(), and false otherwise.

Returns
Boolean specifying whether the Wrapper is running.
template<typename TDatums , typename TWorker , typename TQueue >
void op::Wrapper< TDatums, TWorker, TQueue >::setWorkerInput ( const TWorker &  worker,
const bool  workerOnNewThread = true 
)

Add an user-defined extra Worker as frames generator.

Parameters
workerTWorker to be added.
workerOnNewThreadWhether to add this TWorker on a new thread (if it is computationally demanding) or simply reuse existing threads (for light functions). Set to true if the performance time is unknown.
template<typename TDatums , typename TWorker , typename TQueue >
void op::Wrapper< TDatums, TWorker, TQueue >::setWorkerOutput ( const TWorker &  worker,
const bool  workerOnNewThread = true 
)

Add an user-defined extra Worker as frames consumer (custom display and/or saving).

Parameters
workerTWorker to be added.
workerOnNewThreadWhether to add this TWorker on a new thread (if it is computationally demanding) or simply reuse existing threads (for light functions). Set to true if the performance time is unknown.
template<typename TDatums , typename TWorker , typename TQueue >
void op::Wrapper< TDatums, TWorker, TQueue >::setWorkerPostProcessing ( const TWorker &  worker,
const bool  workerOnNewThread = true 
)

Add an user-defined extra Worker as frames post-processor.

Parameters
workerTWorker to be added.
workerOnNewThreadWhether to add this TWorker on a new thread (if it is computationally demanding) or simply reuse existing threads (for light functions). Set to true if the performance time is unknown.
template<typename TDatums , typename TWorker , typename TQueue >
void op::Wrapper< TDatums, TWorker, TQueue >::start ( )

Function to start multi-threading. Similar to exec(), but start() does not block the thread that calls the function. It just opens new threads, so it lets the user perform other tasks meanwhile on the calling thread. VERY IMPORTANT NOTE: if the GUI is selected and OpenCV is compiled with Qt support, this option will not work. Qt needs the main thread to plot visual results, so the final GUI (which uses OpenCV) would return an exception similar to: QMetaMethod::invoke: Unable to invoke methods with return values in queued connections. Use exec() in that case.

template<typename TDatums , typename TWorker , typename TQueue >
void op::Wrapper< TDatums, TWorker, TQueue >::stop ( )

Function to stop multi-threading. It can be called internally or externally.

template<typename TDatums , typename TWorker , typename TQueue >
bool op::Wrapper< TDatums, TWorker, TQueue >::tryEmplace ( std::shared_ptr< TDatums > &  tDatums)

Emplace (move) an element on the first (input) queue. Only valid if ThreadManagerMode::Asynchronous or ThreadManagerMode::AsynchronousIn. If the input queue is full or the Wrapper was stopped, it will return false and not emplace it.

Parameters
tDatumsstd::shared_ptr<TDatums> element to be emplaced.
Returns
Boolean specifying whether the tDatums could be emplaced.
template<typename TDatums , typename TWorker , typename TQueue >
bool op::Wrapper< TDatums, TWorker, TQueue >::tryPop ( std::shared_ptr< TDatums > &  tDatums)

Pop (retrieve) an element from the last (output) queue. Only valid if ThreadManagerMode::Asynchronous or ThreadManagerMode::AsynchronousOut. If the output queue is empty or the Wrapper was stopped, it will return false and not retrieve it.

Parameters
tDatumsstd::shared_ptr<TDatums> element where the retrieved element will be placed.
Returns
Boolean specifying whether the tDatums could be retrieved.
template<typename TDatums , typename TWorker , typename TQueue >
bool op::Wrapper< TDatums, TWorker, TQueue >::tryPush ( const std::shared_ptr< TDatums > &  tDatums)

Push (copy) an element on the first (input) queue. Same as tryEmplace, but it copies the data instead of moving it.

Parameters
tDatumsstd::shared_ptr<TDatums> element to be pushed.
Returns
Boolean specifying whether the tDatums could be pushed.
template<typename TDatums , typename TWorker , typename TQueue >
bool op::Wrapper< TDatums, TWorker, TQueue >::waitAndEmplace ( std::shared_ptr< TDatums > &  tDatums)

Emplace (move) an element on the first (input) queue. Similar to tryEmplace. However, if the input queue is full, it will wait until it can emplace it. If the Wrapper class is stopped before adding the element, it will return false and not emplace it.

Parameters
tDatumsstd::shared_ptr<TDatums> element to be emplaced.
Returns
Boolean specifying whether the tDatums could be emplaced.
template<typename TDatums , typename TWorker , typename TQueue >
bool op::Wrapper< TDatums, TWorker, TQueue >::waitAndPop ( std::shared_ptr< TDatums > &  tDatums)

Pop (retrieve) an element from the last (output) queue. Similar to tryPop. However, if the output queue is empty, it will wait until it can pop an element. If the Wrapper class is stopped before popping the element, it will return false and not retrieve it.

Parameters
tDatumsstd::shared_ptr<TDatums> element where the retrieved element will be placed.
Returns
Boolean specifying whether the tDatums could be retrieved.
template<typename TDatums , typename TWorker , typename TQueue >
bool op::Wrapper< TDatums, TWorker, TQueue >::waitAndPush ( const std::shared_ptr< TDatums > &  tDatums)

Push (copy) an element on the first (input) queue. Same as waitAndEmplace, but it copies the data instead of moving it.

Parameters
tDatumsstd::shared_ptr<TDatums> element to be pushed.
Returns
Boolean specifying whether the tDatums could be pushed.

The documentation for this class was generated from the following file: