1 #ifndef OPENPOSE_PRODUCER_DATUM_PRODUCER_HPP
2 #define OPENPOSE_PRODUCER_DATUM_PRODUCER_HPP
13 template<
typename TDatum>
18 const std::shared_ptr<Producer>& producerSharedPtr,
19 const unsigned long long frameFirst = 0,
const unsigned long long frameStep = 1,
20 const unsigned long long frameLast = std::numeric_limits<unsigned long long>::max(),
21 const std::shared_ptr<std::pair<std::atomic<bool>, std::atomic<int>>>& videoSeekSharedPtr =
nullptr);
28 const unsigned long long mNumberFramesToProcess;
29 std::shared_ptr<Producer> spProducer;
30 unsigned long long mGlobalCounter;
31 unsigned long long mFrameStep;
32 unsigned int mNumberConsecutiveEmptyFrames;
33 std::shared_ptr<std::pair<std::atomic<bool>, std::atomic<int>>> spVideoSeek;
35 void checkIfTooManyConsecutiveEmptyFrames(
36 unsigned int& numberConsecutiveEmptyFrames,
const bool emptyFrame)
const;
53 const std::shared_ptr<Producer>& producerSharedPtr,
const unsigned long long frameFirst,
54 const unsigned long long frameStep,
const unsigned long long frameLast);
56 unsigned int& numberConsecutiveEmptyFrames,
const bool emptyFrame);
58 const std::shared_ptr<Producer>& producerSharedPtr,
const unsigned long long numberFramesToProcess,
59 const unsigned long long globalCounter);
61 const std::shared_ptr<Producer>& producerSharedPtr,
62 const std::shared_ptr<std::pair<std::atomic<bool>, std::atomic<int>>>& videoSeekSharedPtr);
64 const std::shared_ptr<Producer>& producerSharedPtr);
67 template<
typename TDatum>
69 const std::shared_ptr<Producer>& producerSharedPtr,
70 const unsigned long long frameFirst,
const unsigned long long frameStep,
71 const unsigned long long frameLast,
72 const std::shared_ptr<std::pair<std::atomic<bool>, std::atomic<int>>>& videoSeekSharedPtr) :
73 mNumberFramesToProcess{(frameLast != std::numeric_limits<unsigned long long>::max()
74 ? frameLast - frameFirst : frameLast)},
75 spProducer{producerSharedPtr},
77 mFrameStep{frameStep},
78 mNumberConsecutiveEmptyFrames{0u},
79 spVideoSeek{videoSeekSharedPtr}
85 catch (
const std::exception& e)
87 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
91 template<
typename TDatum>
96 template<
typename TDatum>
103 spProducer, mNumberFramesToProcess, mGlobalCounter);
105 auto datums = std::make_shared<std::vector<std::shared_ptr<TDatum>>>();
106 if (datumProducerRunning)
111 std::string nextFrameName = spProducer->getNextFrameName();
114 const std::vector<Matrix> matrices = spProducer->getFrames();
116 checkIfTooManyConsecutiveEmptyFrames(
117 mNumberConsecutiveEmptyFrames, matrices.empty() || matrices[0].empty());
118 if (!matrices.empty())
121 const std::vector<Matrix> cameraMatrices = spProducer->getCameraMatrices();
122 const std::vector<Matrix> cameraExtrinsics = spProducer->getCameraExtrinsics();
123 const std::vector<Matrix> cameraIntrinsics = spProducer->getCameraIntrinsics();
125 datums->resize(matrices.size());
127 auto& datumPtr = (*datums)[0];
128 datumPtr = std::make_shared<TDatum>();
130 std::swap(datumPtr->name, nextFrameName);
131 datumPtr->frameNumber = nextFrameNumber;
132 datumPtr->cvInputData = matrices[0];
134 if (!cameraMatrices.empty())
136 datumPtr->cameraMatrix = cameraMatrices[0];
137 datumPtr->cameraExtrinsics = cameraExtrinsics[0];
138 datumPtr->cameraIntrinsics = cameraIntrinsics[0];
141 datumPtr->cvOutputData = datumPtr->cvInputData;
143 if (datums->size() > 1)
146 for (
auto i = 1u ; i < datums->size() ; i++)
148 auto& datumIPtr = (*datums)[i];
149 datumIPtr = std::make_shared<TDatum>();
150 datumIPtr->name = datumPtr->name;
151 datumIPtr->frameNumber = datumPtr->frameNumber;
152 datumIPtr->cvInputData = matrices[i];
154 datumIPtr->cvOutputData = datumIPtr->cvInputData;
155 if (cameraMatrices.size() > i)
157 datumIPtr->cameraMatrix = cameraMatrices[i];
158 datumIPtr->cameraExtrinsics = cameraExtrinsics[i];
159 datumIPtr->cameraIntrinsics = cameraIntrinsics[i];
164 if ((*datums)[0]->cvInputData.empty())
167 if (datums !=
nullptr)
168 mGlobalCounter += mFrameStep;
172 return std::make_pair(datumProducerRunning, datums);
174 catch (
const std::exception& e)
176 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
177 return std::make_pair(
false, std::make_shared<std::vector<std::shared_ptr<TDatum>>>());
181 template<
typename TDatum>
183 unsigned int& numberConsecutiveEmptyFrames,
const bool emptyFrame)
const
186 numberConsecutiveEmptyFrames, emptyFrame);
189 extern template class DatumProducer<BASE_DATUM>;
std::pair< bool, std::shared_ptr< std::vector< std::shared_ptr< TDatum > > > > checkIfRunningAndGetDatum()
DatumProducer(const std::shared_ptr< Producer > &producerSharedPtr, const unsigned long long frameFirst=0, const unsigned long long frameStep=1, const unsigned long long frameLast=std::numeric_limits< unsigned long long >::max(), const std::shared_ptr< std::pair< std::atomic< bool >, std::atomic< int >>> &videoSeekSharedPtr=nullptr)
OP_API void datumProducerConstructorRunningAndGetDatumApplyPlayerControls(const std::shared_ptr< Producer > &producerSharedPtr, const std::shared_ptr< std::pair< std::atomic< bool >, std::atomic< int >>> &videoSeekSharedPtr)
OP_API void datumProducerConstructorRunningAndGetDatumFrameIntegrity(Matrix &matrix)
OP_API void datumProducerConstructorTooManyConsecutiveEmptyFrames(unsigned int &numberConsecutiveEmptyFrames, const bool emptyFrame)
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
OP_API bool datumProducerConstructorRunningAndGetDatumIsDatumProducerRunning(const std::shared_ptr< Producer > &producerSharedPtr, const unsigned long long numberFramesToProcess, const unsigned long long globalCounter)
OP_API unsigned long long datumProducerConstructorRunningAndGetNextFrameNumber(const std::shared_ptr< Producer > &producerSharedPtr)
OP_API void datumProducerConstructor(const std::shared_ptr< Producer > &producerSharedPtr, const unsigned long long frameFirst, const unsigned long long frameStep, const unsigned long long frameLast)