OpenPose  1.0.0rc2
OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
wrapperAuxiliary.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_WRAPPER_WRAPPER_AUXILIARY_HPP
2 #define OPENPOSE_WRAPPER_WRAPPER_AUXILIARY_HPP
3 
13 
14 namespace op
15 {
30  WrapperStructPose& wrapperStructPose, const WrapperStructFace& wrapperStructFace,
31  const WrapperStructHand& wrapperStructHand, const WrapperStructExtra& wrapperStructExtra,
32  const WrapperStructInput& wrapperStructInput, const WrapperStructOutput& wrapperStructOutput,
33  const WrapperStructGui& wrapperStructGui, const bool renderOutput, const bool userOutputWsEmpty,
34  const std::shared_ptr<Producer>& producerSharedPtr, const ThreadManagerMode threadManagerMode);
35 
44  OP_API void threadIdPP(unsigned long long& threadId, const bool multiThreadEnabled);
45 
52  template<typename TDatums,
53  typename TDatumsSP = std::shared_ptr<TDatums>,
54  typename TWorker = std::shared_ptr<Worker<TDatumsSP>>>
56  ThreadManager<TDatumsSP>& threadManager, const bool multiThreadEnabled,
57  const ThreadManagerMode threadManagerMode, const WrapperStructPose& wrapperStructPose,
58  const WrapperStructFace& wrapperStructFace, const WrapperStructHand& wrapperStructHand,
59  const WrapperStructExtra& wrapperStructExtra, const WrapperStructInput& wrapperStructInput,
60  const WrapperStructOutput& wrapperStructOutput, const WrapperStructGui& wrapperStructGui,
61  const std::array<std::vector<TWorker>, int(WorkerType::Size)>& userWs,
62  const std::array<bool, int(WorkerType::Size)>& userWsOnNewThread);
63 }
64 
65 
66 
67 
68 
69 // Implementation
70 #include <openpose/3d/headers.hpp>
74 #include <openpose/gpu/gpu.hpp>
75 #include <openpose/gui/headers.hpp>
82 namespace op
83 {
84  template<typename TDatums, typename TDatumsSP, typename TWorker>
86  ThreadManager<TDatumsSP>& threadManager, const bool multiThreadEnabledTemp,
87  const ThreadManagerMode threadManagerMode, const WrapperStructPose& wrapperStructPoseTemp,
88  const WrapperStructFace& wrapperStructFace, const WrapperStructHand& wrapperStructHand,
89  const WrapperStructExtra& wrapperStructExtra, const WrapperStructInput& wrapperStructInput,
90  const WrapperStructOutput& wrapperStructOutput, const WrapperStructGui& wrapperStructGui,
91  const std::array<std::vector<TWorker>, int(WorkerType::Size)>& userWs,
92  const std::array<bool, int(WorkerType::Size)>& userWsOnNewThread)
93  {
94  try
95  {
96  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
97 
98  // Create producer
99  auto producerSharedPtr = createProducer(
100  wrapperStructInput.producerType, wrapperStructInput.producerString,
101  wrapperStructInput.cameraResolution, wrapperStructInput.cameraParameterPath,
102  wrapperStructInput.undistortImage, wrapperStructInput.imageDirectoryStereo);
103 
104  // Editable arguments
105  auto wrapperStructPose = wrapperStructPoseTemp;
106  auto multiThreadEnabled = multiThreadEnabledTemp;
107 
108  // Workers
109  TWorker datumProducerW;
110  TWorker scaleAndSizeExtractorW;
111  TWorker cvMatToOpInputW;
112  TWorker cvMatToOpOutputW;
113  std::vector<std::vector<TWorker>> poseExtractorsWs;
114  std::vector<std::vector<TWorker>> poseTriangulationsWs;
115  std::vector<std::vector<TWorker>> jointAngleEstimationsWs;
116  std::vector<TWorker> postProcessingWs;
117  std::vector<TWorker> outputWs;
118  TWorker guiW;
119 
120  // User custom workers
121  const auto& userInputWs = userWs[int(WorkerType::Input)];
122  const auto& userPostProcessingWs = userWs[int(WorkerType::PostProcessing)];
123  const auto& userOutputWs = userWs[int(WorkerType::Output)];
124  const auto userInputWsOnNewThread = userWsOnNewThread[int(WorkerType::Input)];
125  const auto userPostProcessingWsOnNewThread = userWsOnNewThread[int(WorkerType::PostProcessing)];
126  const auto userOutputWsOnNewThread = userWsOnNewThread[int(WorkerType::Output)];
127 
128  // Video seek
129  const auto spVideoSeek = std::make_shared<std::pair<std::atomic<bool>, std::atomic<int>>>();
130  // It cannot be directly included in the constructor (compiler error for copying std::atomic)
131  spVideoSeek->first = false;
132  spVideoSeek->second = 0;
133 
134  // Required parameters
135  const auto renderOutput = wrapperStructPose.renderMode != RenderMode::None
136  || wrapperStructFace.renderMode != RenderMode::None
137  || wrapperStructHand.renderMode != RenderMode::None;
138  const auto renderOutputGpu = wrapperStructPose.renderMode == RenderMode::Gpu
139  || wrapperStructFace.renderMode == RenderMode::Gpu
140  || wrapperStructHand.renderMode == RenderMode::Gpu;
141  const auto renderFace = wrapperStructFace.enable && wrapperStructFace.renderMode != RenderMode::None;
142  const auto renderHand = wrapperStructHand.enable && wrapperStructHand.renderMode != RenderMode::None;
143  const auto renderHandGpu = wrapperStructHand.enable && wrapperStructHand.renderMode == RenderMode::Gpu;
144 
145  // Check no wrong/contradictory flags enabled
146  const auto userOutputWsEmpty = userOutputWs.empty();
148  wrapperStructPose, wrapperStructFace, wrapperStructHand, wrapperStructExtra, wrapperStructInput,
149  wrapperStructOutput, wrapperStructGui, renderOutput, userOutputWsEmpty, producerSharedPtr,
150  threadManagerMode);
151 
152  // Get number threads
153  auto numberThreads = wrapperStructPose.gpuNumber;
154  auto gpuNumberStart = wrapperStructPose.gpuNumberStart;
155  // CPU --> 1 thread or no pose extraction
156  if (getGpuMode() == GpuMode::NoGpu)
157  {
158  numberThreads = (wrapperStructPose.gpuNumber == 0 ? 0 : 1);
159  gpuNumberStart = 0;
160  // Disabling multi-thread makes the code 400 ms faster (2.3 sec vs. 2.7 in i7-6850K)
161  // and fixes the bug that the screen was not properly displayed and only refreshed sometimes
162  // Note: The screen bug could be also fixed by using waitKey(30) rather than waitKey(1)
163  multiThreadEnabled = false;
164  }
165  // GPU --> user picks (<= #GPUs)
166  else
167  {
168  // Get total number GPUs
169  const auto totalGpuNumber = getGpuNumber();
170  // If number GPU < 0 --> set it to all the available GPUs
171  if (numberThreads < 0)
172  {
173  if (totalGpuNumber <= gpuNumberStart)
174  error("Number of initial GPU (`--number_gpu_start`) must be lower than the total number of"
175  " used GPUs (`--number_gpu`)", __LINE__, __FUNCTION__, __FILE__);
176  numberThreads = totalGpuNumber - gpuNumberStart;
177  // Reset initial GPU to 0 (we want them all)
178  // Logging message
179  log("Auto-detecting all available GPUs... Detected " + std::to_string(totalGpuNumber)
180  + " GPU(s), using " + std::to_string(numberThreads) + " of them starting at GPU "
181  + std::to_string(gpuNumberStart) + ".", Priority::High);
182  }
183  // Sanity check
184  if (gpuNumberStart + numberThreads > totalGpuNumber)
185  error("Initial GPU selected (`--number_gpu_start`) + number GPUs to use (`--number_gpu`) must"
186  " be lower or equal than the total number of GPUs in your machine ("
187  + std::to_string(gpuNumberStart) + " + "
188  + std::to_string(numberThreads) + " vs. "
189  + std::to_string(totalGpuNumber) + ").",
190  __LINE__, __FUNCTION__, __FILE__);
191  }
192 
193  // Proper format
194  const auto writeImagesCleaned = formatAsDirectory(wrapperStructOutput.writeImages);
195  const auto writeKeypointCleaned = formatAsDirectory(wrapperStructOutput.writeKeypoint);
196  const auto writeJsonCleaned = formatAsDirectory(wrapperStructOutput.writeJson);
197  const auto writeHeatMapsCleaned = formatAsDirectory(wrapperStructOutput.writeHeatMaps);
198  const auto modelFolder = formatAsDirectory(wrapperStructPose.modelFolder);
199 
200  // Common parameters
201  auto finalOutputSize = wrapperStructPose.outputSize;
202  Point<int> producerSize{-1,-1};
203  const auto oPProducer = (producerSharedPtr != nullptr);
204  if (oPProducer)
205  {
206  // 1. Set producer properties
207  const auto displayProducerFpsMode = (wrapperStructInput.realTimeProcessing
209  producerSharedPtr->setProducerFpsMode(displayProducerFpsMode);
210  producerSharedPtr->set(ProducerProperty::Flip, wrapperStructInput.frameFlip);
211  producerSharedPtr->set(ProducerProperty::Rotation, wrapperStructInput.frameRotate);
212  producerSharedPtr->set(ProducerProperty::AutoRepeat, wrapperStructInput.framesRepeat);
213  // 2. Set finalOutputSize
214  producerSize = Point<int>{(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_WIDTH),
215  (int)producerSharedPtr->get(CV_CAP_PROP_FRAME_HEIGHT)};
216  // Set finalOutputSize to input size if desired
217  if (finalOutputSize.x == -1 || finalOutputSize.y == -1)
218  finalOutputSize = producerSize;
219  }
220 
221  // Producer
222  if (oPProducer)
223  {
224  const auto datumProducer = std::make_shared<DatumProducer<TDatums>>(
225  producerSharedPtr, wrapperStructInput.frameFirst, wrapperStructInput.frameStep,
226  wrapperStructInput.frameLast, spVideoSeek
227  );
228  datumProducerW = std::make_shared<WDatumProducer<TDatumsSP, TDatums>>(datumProducer);
229  }
230  else
231  datumProducerW = nullptr;
232 
233  std::vector<std::shared_ptr<PoseExtractorNet>> poseExtractorNets;
234  std::vector<std::shared_ptr<FaceExtractorNet>> faceExtractorNets;
235  std::vector<std::shared_ptr<HandExtractorNet>> handExtractorNets;
236  std::vector<std::shared_ptr<PoseGpuRenderer>> poseGpuRenderers;
237  std::shared_ptr<PoseCpuRenderer> poseCpuRenderer;
238  if (numberThreads > 0)
239  {
240  // Get input scales and sizes
241  const auto scaleAndSizeExtractor = std::make_shared<ScaleAndSizeExtractor>(
242  wrapperStructPose.netInputSize, finalOutputSize, wrapperStructPose.scalesNumber,
243  wrapperStructPose.scaleGap
244  );
245  scaleAndSizeExtractorW = std::make_shared<WScaleAndSizeExtractor<TDatumsSP>>(scaleAndSizeExtractor);
246 
247  // Input cvMat to OpenPose input & output format
248  const auto cvMatToOpInput = std::make_shared<CvMatToOpInput>(wrapperStructPose.poseModel);
249  cvMatToOpInputW = std::make_shared<WCvMatToOpInput<TDatumsSP>>(cvMatToOpInput);
250  if (renderOutput)
251  {
252  const auto cvMatToOpOutput = std::make_shared<CvMatToOpOutput>();
253  cvMatToOpOutputW = std::make_shared<WCvMatToOpOutput<TDatumsSP>>(cvMatToOpOutput);
254  }
255 
256  // Pose estimators & renderers
257  std::vector<TWorker> cpuRenderers;
258  poseExtractorsWs.clear();
259  poseExtractorsWs.resize(numberThreads);
260  if (wrapperStructPose.enable)
261  {
262  // Pose estimators
263  for (auto gpuId = 0; gpuId < numberThreads; gpuId++)
264  poseExtractorNets.emplace_back(std::make_shared<PoseExtractorCaffe>(
265  wrapperStructPose.poseModel, modelFolder, gpuId + gpuNumberStart,
266  wrapperStructPose.heatMapTypes, wrapperStructPose.heatMapScale,
267  wrapperStructPose.addPartCandidates, wrapperStructPose.maximizePositives,
268  wrapperStructPose.enableGoogleLogging
269  ));
270 
271  // Pose renderers
272  if (renderOutputGpu || wrapperStructPose.renderMode == RenderMode::Cpu)
273  {
274  // If wrapperStructPose.renderMode != RenderMode::Gpu but renderOutput, then we create an
275  // alpha = 0 pose renderer in order to keep the removing background option
276  const auto alphaKeypoint = (wrapperStructPose.renderMode != RenderMode::None
277  ? wrapperStructPose.alphaKeypoint : 0.f);
278  const auto alphaHeatMap = (wrapperStructPose.renderMode != RenderMode::None
279  ? wrapperStructPose.alphaHeatMap : 0.f);
280  // GPU rendering
281  if (renderOutputGpu)
282  {
283  for (const auto& poseExtractorNet : poseExtractorNets)
284  {
285  poseGpuRenderers.emplace_back(std::make_shared<PoseGpuRenderer>(
286  wrapperStructPose.poseModel, poseExtractorNet, wrapperStructPose.renderThreshold,
287  wrapperStructPose.blendOriginalFrame, alphaKeypoint,
288  alphaHeatMap, wrapperStructPose.defaultPartToRender
289  ));
290  }
291  }
292  // CPU rendering
293  if (wrapperStructPose.renderMode == RenderMode::Cpu)
294  {
295  poseCpuRenderer = std::make_shared<PoseCpuRenderer>(
296  wrapperStructPose.poseModel, wrapperStructPose.renderThreshold,
297  wrapperStructPose.blendOriginalFrame, alphaKeypoint, alphaHeatMap,
298  wrapperStructPose.defaultPartToRender);
299  cpuRenderers.emplace_back(std::make_shared<WPoseRenderer<TDatumsSP>>(poseCpuRenderer));
300  }
301  }
302  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
303 
304  // Pose extractor(s)
305  poseExtractorsWs.resize(poseExtractorNets.size());
306  const auto personIdExtractor = (wrapperStructExtra.identification
307  ? std::make_shared<PersonIdExtractor>() : nullptr);
308  // Keep top N people
309  // Added right after PoseExtractorNet to avoid:
310  // 1) Rendering people that are later deleted (wrong visualization).
311  // 2) Processing faces and hands on people that will be deleted (speed up).
312  // 3) Running tracking before deleting the people.
313  // Add KeepTopNPeople for each PoseExtractorNet
314  const auto keepTopNPeople = (wrapperStructPose.numberPeopleMax > 0 ?
315  std::make_shared<KeepTopNPeople>(wrapperStructPose.numberPeopleMax)
316  : nullptr);
317  // Person tracker
318  auto personTrackers = std::make_shared<std::vector<std::shared_ptr<PersonTracker>>>();
319  if (wrapperStructExtra.tracking > -1)
320  personTrackers->emplace_back(
321  std::make_shared<PersonTracker>(wrapperStructExtra.tracking == 0));
322  for (auto i = 0u; i < poseExtractorsWs.size(); i++)
323  {
324  // OpenPose keypoint detector + keepTopNPeople
325  // + ID extractor (experimental) + tracking (experimental)
326  const auto poseExtractor = std::make_shared<PoseExtractor>(
327  poseExtractorNets.at(i), keepTopNPeople, personIdExtractor, personTrackers,
328  wrapperStructPose.numberPeopleMax, wrapperStructExtra.tracking);
329  poseExtractorsWs.at(i) = {std::make_shared<WPoseExtractor<TDatumsSP>>(poseExtractor)};
330  // // Just OpenPose keypoint detector
331  // poseExtractorsWs.at(i) = {std::make_shared<WPoseExtractorNet<TDatumsSP>>(
332  // poseExtractorNets.at(i))};
333  }
334 
335  // // (Before tracking / id extractor)
336  // // Added right after PoseExtractorNet to avoid:
337  // // 1) Rendering people that are later deleted (wrong visualization).
338  // // 2) Processing faces and hands on people that will be deleted (speed up).
339  // if (wrapperStructPose.numberPeopleMax > 0)
340  // {
341  // // Add KeepTopNPeople for each PoseExtractorNet
342  // const auto keepTopNPeople = std::make_shared<KeepTopNPeople>(
343  // wrapperStructPose.numberPeopleMax);
344  // for (auto& wPose : poseExtractorsWs)
345  // wPose.emplace_back(std::make_shared<WKeepTopNPeople<TDatumsSP>>(keepTopNPeople));
346  // }
347  }
348 
349 
350  // Face extractor(s)
351  if (wrapperStructFace.enable)
352  {
353  // Face detector
354  // OpenPose face detector
355  if (wrapperStructPose.enable)
356  {
357  const auto faceDetector = std::make_shared<FaceDetector>(wrapperStructPose.poseModel);
358  for (auto& wPose : poseExtractorsWs)
359  wPose.emplace_back(std::make_shared<WFaceDetector<TDatumsSP>>(faceDetector));
360  }
361  // OpenCV face detector
362  else
363  {
364  log("Body keypoint detection is disabled. Hence, using OpenCV face detector (much less"
365  " accurate but faster).", Priority::High);
366  for (auto& wPose : poseExtractorsWs)
367  {
368  // 1 FaceDetectorOpenCV per thread, OpenCV face detector is not thread-safe
369  const auto faceDetectorOpenCV = std::make_shared<FaceDetectorOpenCV>(modelFolder);
370  wPose.emplace_back(
371  std::make_shared<WFaceDetectorOpenCV<TDatumsSP>>(faceDetectorOpenCV)
372  );
373  }
374  }
375  // Face keypoint extractor
376  for (auto gpu = 0u; gpu < poseExtractorsWs.size(); gpu++)
377  {
378  // Face keypoint extractor
379  const auto netOutputSize = wrapperStructFace.netInputSize;
380  const auto faceExtractorNet = std::make_shared<FaceExtractorCaffe>(
381  wrapperStructFace.netInputSize, netOutputSize, modelFolder,
382  gpu + gpuNumberStart, wrapperStructPose.heatMapTypes, wrapperStructPose.heatMapScale,
383  wrapperStructPose.enableGoogleLogging
384  );
385  faceExtractorNets.emplace_back(faceExtractorNet);
386  poseExtractorsWs.at(gpu).emplace_back(
387  std::make_shared<WFaceExtractorNet<TDatumsSP>>(faceExtractorNet));
388  }
389  }
390 
391  // Hand extractor(s)
392  if (wrapperStructHand.enable)
393  {
394  const auto handDetector = std::make_shared<HandDetector>(wrapperStructPose.poseModel);
395  for (auto gpu = 0u; gpu < poseExtractorsWs.size(); gpu++)
396  {
397  // Hand detector
398  // If tracking
399  if (wrapperStructHand.tracking)
400  poseExtractorsWs.at(gpu).emplace_back(
401  std::make_shared<WHandDetectorTracking<TDatumsSP>>(handDetector)
402  );
403  // If detection
404  else
405  poseExtractorsWs.at(gpu).emplace_back(
406  std::make_shared<WHandDetector<TDatumsSP>>(handDetector));
407  // Hand keypoint extractor
408  const auto netOutputSize = wrapperStructHand.netInputSize;
409  const auto handExtractorNet = std::make_shared<HandExtractorCaffe>(
410  wrapperStructHand.netInputSize, netOutputSize, modelFolder,
411  gpu + gpuNumberStart, wrapperStructHand.scalesNumber, wrapperStructHand.scaleRange,
412  wrapperStructPose.heatMapTypes, wrapperStructPose.heatMapScale,
413  wrapperStructPose.enableGoogleLogging
414  );
415  handExtractorNets.emplace_back(handExtractorNet);
416  poseExtractorsWs.at(gpu).emplace_back(
417  std::make_shared<WHandExtractorNet<TDatumsSP>>(handExtractorNet)
418  );
419  // If tracking
420  if (wrapperStructHand.tracking)
421  poseExtractorsWs.at(gpu).emplace_back(
422  std::make_shared<WHandDetectorUpdate<TDatumsSP>>(handDetector)
423  );
424  }
425  }
426 
427  // Pose renderer(s)
428  if (!poseGpuRenderers.empty())
429  for (auto i = 0u; i < poseExtractorsWs.size(); i++)
430  poseExtractorsWs.at(i).emplace_back(std::make_shared<WPoseRenderer<TDatumsSP>>(
431  poseGpuRenderers.at(i)
432  ));
433 
434  // Face renderer(s)
435  if (renderFace)
436  {
437  // CPU rendering
438  if (wrapperStructFace.renderMode == RenderMode::Cpu)
439  {
440  // Construct face renderer
441  const auto faceRenderer = std::make_shared<FaceCpuRenderer>(wrapperStructFace.renderThreshold,
442  wrapperStructFace.alphaKeypoint,
443  wrapperStructFace.alphaHeatMap);
444  // Add worker
445  cpuRenderers.emplace_back(std::make_shared<WFaceRenderer<TDatumsSP>>(faceRenderer));
446  }
447  // GPU rendering
448  else if (wrapperStructFace.renderMode == RenderMode::Gpu)
449  {
450  for (auto i = 0u; i < poseExtractorsWs.size(); i++)
451  {
452  // Construct face renderer
453  const auto faceRenderer = std::make_shared<FaceGpuRenderer>(
454  wrapperStructFace.renderThreshold, wrapperStructFace.alphaKeypoint,
455  wrapperStructFace.alphaHeatMap
456  );
457  // Performance boost -> share spGpuMemory for all renderers
458  if (!poseGpuRenderers.empty())
459  {
460  const bool isLastRenderer = !renderHandGpu;
461  const auto renderer = std::static_pointer_cast<PoseGpuRenderer>(
462  poseGpuRenderers.at(i)
463  );
464  faceRenderer->setSharedParametersAndIfLast(renderer->getSharedParameters(),
465  isLastRenderer);
466  }
467  // Add worker
468  poseExtractorsWs.at(i).emplace_back(
469  std::make_shared<WFaceRenderer<TDatumsSP>>(faceRenderer));
470  }
471  }
472  else
473  error("Unknown RenderMode.", __LINE__, __FUNCTION__, __FILE__);
474  }
475 
476  // Hand renderer(s)
477  if (renderHand)
478  {
479  // CPU rendering
480  if (wrapperStructHand.renderMode == RenderMode::Cpu)
481  {
482  // Construct hand renderer
483  const auto handRenderer = std::make_shared<HandCpuRenderer>(wrapperStructHand.renderThreshold,
484  wrapperStructHand.alphaKeypoint,
485  wrapperStructHand.alphaHeatMap);
486  // Add worker
487  cpuRenderers.emplace_back(std::make_shared<WHandRenderer<TDatumsSP>>(handRenderer));
488  }
489  // GPU rendering
490  else if (wrapperStructHand.renderMode == RenderMode::Gpu)
491  {
492  for (auto i = 0u; i < poseExtractorsWs.size(); i++)
493  {
494  // Construct hands renderer
495  const auto handRenderer = std::make_shared<HandGpuRenderer>(
496  wrapperStructHand.renderThreshold, wrapperStructHand.alphaKeypoint,
497  wrapperStructHand.alphaHeatMap
498  );
499  // Performance boost -> share spGpuMemory for all renderers
500  if (!poseGpuRenderers.empty())
501  {
502  const bool isLastRenderer = true;
503  const auto renderer = std::static_pointer_cast<PoseGpuRenderer>(
504  poseGpuRenderers.at(i)
505  );
506  handRenderer->setSharedParametersAndIfLast(renderer->getSharedParameters(),
507  isLastRenderer);
508  }
509  // Add worker
510  poseExtractorsWs.at(i).emplace_back(
511  std::make_shared<WHandRenderer<TDatumsSP>>(handRenderer));
512  }
513  }
514  else
515  error("Unknown RenderMode.", __LINE__, __FUNCTION__, __FILE__);
516  }
517 
518  // 3-D reconstruction
519  poseTriangulationsWs.clear();
520  if (wrapperStructExtra.reconstruct3d)
521  {
522  // For all (body/face/hands): PoseTriangulations ~30 msec, 8 GPUS ~30 msec for keypoint estimation
523  poseTriangulationsWs.resize(fastMax(1, int(poseExtractorsWs.size() / 4)));
524  for (auto i = 0u ; i < poseTriangulationsWs.size() ; i++)
525  {
526  const auto poseTriangulation = std::make_shared<PoseTriangulation>(
527  wrapperStructExtra.minViews3d);
528  poseTriangulationsWs.at(i) = {std::make_shared<WPoseTriangulation<TDatumsSP>>(
529  poseTriangulation)};
530  }
531  }
532  // Itermediate workers (e.g., OpenPose format to cv::Mat, json & frames recorder, ...)
533  postProcessingWs.clear();
534  // // Person ID identification (when no multi-thread and no dependency on tracking)
535  // if (wrapperStructExtra.identification)
536  // {
537  // const auto personIdExtractor = std::make_shared<PersonIdExtractor>();
538  // postProcessingWs.emplace_back(
539  // std::make_shared<WPersonIdExtractor<TDatumsSP>>(personIdExtractor)
540  // );
541  // }
542  // Frames processor (OpenPose format -> cv::Mat format)
543  if (renderOutput)
544  {
545  postProcessingWs = mergeVectors(postProcessingWs, cpuRenderers);
546  const auto opOutputToCvMat = std::make_shared<OpOutputToCvMat>();
547  postProcessingWs.emplace_back(std::make_shared<WOpOutputToCvMat<TDatumsSP>>(opOutputToCvMat));
548  }
549  // Re-scale pose if desired
550  // If desired scale is not the current input
551  if (wrapperStructPose.keypointScale != ScaleMode::InputResolution
552  // and desired scale is not output when size(input) = size(output)
553  && !(wrapperStructPose.keypointScale == ScaleMode::OutputResolution &&
554  (finalOutputSize == producerSize || finalOutputSize.x <= 0 || finalOutputSize.y <= 0))
555  // and desired scale is not net output when size(input) = size(net output)
556  && !(wrapperStructPose.keypointScale == ScaleMode::NetOutputResolution
557  && producerSize == wrapperStructPose.netInputSize))
558  {
559  // Then we must rescale the keypoints
560  auto keypointScaler = std::make_shared<KeypointScaler>(wrapperStructPose.keypointScale);
561  postProcessingWs.emplace_back(std::make_shared<WKeypointScaler<TDatumsSP>>(keypointScaler));
562  }
563  }
564 
565  // IK/Adam
566  const auto displayAdam = wrapperStructGui.displayMode == DisplayMode::DisplayAdam
567  || (wrapperStructGui.displayMode == DisplayMode::DisplayAll
568  && wrapperStructExtra.ikThreads > 0);
569  jointAngleEstimationsWs.clear();
570 #ifdef USE_3D_ADAM_MODEL
571  if (wrapperStructExtra.ikThreads > 0)
572  {
573  jointAngleEstimationsWs.resize(wrapperStructExtra.ikThreads);
574  // Pose extractor(s)
575  for (auto i = 0u; i < jointAngleEstimationsWs.size(); i++)
576  {
577  const auto jointAngleEstimation = std::make_shared<JointAngleEstimation>(displayAdam);
578  jointAngleEstimationsWs.at(i) = {std::make_shared<WJointAngleEstimation<TDatumsSP>>(
579  jointAngleEstimation)};
580  }
581  }
582 #endif
583 
584  // Output workers
585  outputWs.clear();
586  // Print verbose
587  if (wrapperStructOutput.verbose > 0.)
588  {
589  const auto verbosePrinter = std::make_shared<VerbosePrinter>(
590  wrapperStructOutput.verbose, producerSharedPtr->get(CV_CAP_PROP_FRAME_COUNT));
591  outputWs.emplace_back(std::make_shared<WVerbosePrinter<TDatumsSP>>(verbosePrinter));
592  }
593  // Send information (e.g., to Unity) though UDP client-server communication
594 
595 #ifdef USE_3D_ADAM_MODEL
596  if (!wrapperStructOutput.udpHost.empty() && !wrapperStructOutput.udpPort.empty())
597  {
598  const auto udpSender = std::make_shared<UdpSender>(wrapperStructOutput.udpHost,
599  wrapperStructOutput.udpPort);
600  outputWs.emplace_back(std::make_shared<WUdpSender<TDatumsSP>>(udpSender));
601  }
602 #endif
603  // Write people pose data on disk (json for OpenCV >= 3, xml, yml...)
604  if (!writeKeypointCleaned.empty())
605  {
606  const auto keypointSaver = std::make_shared<KeypointSaver>(writeKeypointCleaned,
607  wrapperStructOutput.writeKeypointFormat);
608  outputWs.emplace_back(std::make_shared<WPoseSaver<TDatumsSP>>(keypointSaver));
609  if (wrapperStructFace.enable)
610  outputWs.emplace_back(std::make_shared<WFaceSaver<TDatumsSP>>(keypointSaver));
611  if (wrapperStructHand.enable)
612  outputWs.emplace_back(std::make_shared<WHandSaver<TDatumsSP>>(keypointSaver));
613  }
614  // Write OpenPose output data on disk in json format (body/hand/face keypoints, body part locations if
615  // enabled, etc.)
616  if (!writeJsonCleaned.empty())
617  {
618  const auto peopleJsonSaver = std::make_shared<PeopleJsonSaver>(writeJsonCleaned);
619  outputWs.emplace_back(std::make_shared<WPeopleJsonSaver<TDatumsSP>>(peopleJsonSaver));
620  }
621  // Write people pose data on disk (COCO validation json format)
622  if (!wrapperStructOutput.writeCocoJson.empty())
623  {
624  // If humanFormat: bigger size (& maybe slower to process), but easier for user to read it
625  const auto humanFormat = true;
626  const auto cocoJsonSaver = std::make_shared<CocoJsonSaver>(
627  wrapperStructOutput.writeCocoJson, humanFormat,
628  (wrapperStructPose.poseModel != PoseModel::CAR_22
629  && wrapperStructPose.poseModel != PoseModel::CAR_12
631  wrapperStructOutput.writeCocoJsonVariant);
632  outputWs.emplace_back(std::make_shared<WCocoJsonSaver<TDatumsSP>>(cocoJsonSaver));
633  }
634  // Write people foot pose data on disk (COCO validation json format for foot data)
635  if (!wrapperStructOutput.writeCocoFootJson.empty())
636  {
637  // If humanFormat: bigger size (& maybe slower to process), but easier for user to read it
638  const auto humanFormat = true;
639  const auto cocoJsonSaver = std::make_shared<CocoJsonSaver>(wrapperStructOutput.writeCocoFootJson,
640  humanFormat, CocoJsonFormat::Foot);
641  outputWs.emplace_back(std::make_shared<WCocoJsonSaver<TDatumsSP>>(cocoJsonSaver));
642  }
643  // Write frames as desired image format on hard disk
644  if (!writeImagesCleaned.empty())
645  {
646  const auto imageSaver = std::make_shared<ImageSaver>(writeImagesCleaned,
647  wrapperStructOutput.writeImagesFormat);
648  outputWs.emplace_back(std::make_shared<WImageSaver<TDatumsSP>>(imageSaver));
649  }
650  // Write frames as *.avi video on hard disk
651  if (!wrapperStructOutput.writeVideo.empty() || !wrapperStructOutput.writeBvh.empty())
652  {
653  if (wrapperStructOutput.writeVideoFps <= 0
654  && (producerSharedPtr == nullptr || producerSharedPtr->get(CV_CAP_PROP_FPS) <= 0))
655  error("The frame rate of the frames producer is unknown. Set `--write_video_fps` to your desired"
656  " FPS if you wanna record video (`--write_video`). E.g., if it is a folder of images, you"
657  " will have to know or guess the frame rate; if it is a webcam, you should use the OpenPose"
658  " displayed FPS as desired value. If you do not care, simply add `--write_video_fps 30`.",
659  __LINE__, __FUNCTION__, __FILE__);
660  const auto originalVideoFps = (
661  wrapperStructOutput.writeVideoFps > 0 ?
662  wrapperStructOutput.writeVideoFps : producerSharedPtr->get(CV_CAP_PROP_FPS));
663  if (!wrapperStructOutput.writeVideo.empty())
664  {
665  if (!oPProducer)
666  error("Video file can only be recorded inside `wrapper/wrapper.hpp` if the producer"
667  " is one of the default ones (e.g., video, webcam, ...).",
668  __LINE__, __FUNCTION__, __FILE__);
669  if (finalOutputSize.x <= 0 || finalOutputSize.y <= 0)
670  error("Video can only be recorded if outputSize is fixed (e.g., video, webcam, IP camera),"
671  " but not for a image directory.", __LINE__, __FUNCTION__, __FILE__);
672  const auto videoSaver = std::make_shared<VideoSaver>(
673  wrapperStructOutput.writeVideo, CV_FOURCC('M','J','P','G'), originalVideoFps, finalOutputSize
674  );
675  outputWs.emplace_back(std::make_shared<WVideoSaver<TDatumsSP>>(videoSaver));
676  }
677  // Write joint angles as *.bvh file on hard disk
678 #ifdef USE_3D_ADAM_MODEL
679  if (!wrapperStructOutput.writeBvh.empty())
680  {
681  const auto bvhSaver = std::make_shared<BvhSaver>(
682  wrapperStructOutput.writeBvh, JointAngleEstimation::getTotalModel(), originalVideoFps
683  );
684  outputWs.emplace_back(std::make_shared<WBvhSaver<TDatumsSP>>(bvhSaver));
685  }
686 #endif
687  }
688  // Write heat maps as desired image format on hard disk
689  if (!writeHeatMapsCleaned.empty())
690  {
691  const auto heatMapSaver = std::make_shared<HeatMapSaver>(writeHeatMapsCleaned,
692  wrapperStructOutput.writeHeatMapsFormat);
693  outputWs.emplace_back(std::make_shared<WHeatMapSaver<TDatumsSP>>(heatMapSaver));
694  }
695  // Add frame information for GUI
696  const bool guiEnabled = (wrapperStructGui.displayMode != DisplayMode::NoDisplay);
697  // If this WGuiInfoAdder instance is placed before the WImageSaver or WVideoSaver, then the resulting
698  // recorded frames will look exactly as the final displayed image by the GUI
699  if (wrapperStructGui.guiVerbose && (guiEnabled || !userOutputWs.empty()
700  || threadManagerMode == ThreadManagerMode::Asynchronous
701  || threadManagerMode == ThreadManagerMode::AsynchronousOut))
702  {
703  const auto guiInfoAdder = std::make_shared<GuiInfoAdder>(numberThreads, guiEnabled);
704  outputWs.emplace_back(std::make_shared<WGuiInfoAdder<TDatumsSP>>(guiInfoAdder));
705  }
706  // Minimal graphical user interface (GUI)
707  guiW = nullptr;
708  if (guiEnabled)
709  {
710  // PoseRenderers to Renderers
711  std::vector<std::shared_ptr<Renderer>> renderers;
712  if (wrapperStructPose.renderMode == RenderMode::Cpu)
713  renderers.emplace_back(std::static_pointer_cast<Renderer>(poseCpuRenderer));
714  else
715  for (const auto& poseGpuRenderer : poseGpuRenderers)
716  renderers.emplace_back(std::static_pointer_cast<Renderer>(poseGpuRenderer));
717  // Display
718  // Adam (+3-D/2-D) display
719  if (displayAdam)
720  {
721 #ifdef USE_3D_ADAM_MODEL
722  // Gui
723  const auto gui = std::make_shared<GuiAdam>(
724  finalOutputSize, wrapperStructGui.fullScreen, threadManager.getIsRunningSharedPtr(),
725  spVideoSeek, poseExtractorNets, faceExtractorNets, handExtractorNets, renderers,
726  wrapperStructGui.displayMode, JointAngleEstimation::getTotalModel(),
727  wrapperStructOutput.writeVideoAdam
728  );
729  // WGui
730  guiW = {std::make_shared<WGuiAdam<TDatumsSP>>(gui)};
731 #endif
732  }
733  // 3-D (+2-D) display
734  else if (wrapperStructGui.displayMode == DisplayMode::Display3D
735  || wrapperStructGui.displayMode == DisplayMode::DisplayAll)
736  {
737  // Gui
738  const auto gui = std::make_shared<Gui3D>(
739  finalOutputSize, wrapperStructGui.fullScreen, threadManager.getIsRunningSharedPtr(),
740  spVideoSeek, poseExtractorNets, faceExtractorNets, handExtractorNets, renderers,
741  wrapperStructPose.poseModel, wrapperStructGui.displayMode
742  );
743  // WGui
744  guiW = {std::make_shared<WGui3D<TDatumsSP>>(gui)};
745  }
746  // 2-D display
747  else if (wrapperStructGui.displayMode == DisplayMode::Display2D)
748  {
749  // Gui
750  const auto gui = std::make_shared<Gui>(
751  finalOutputSize, wrapperStructGui.fullScreen, threadManager.getIsRunningSharedPtr(),
752  spVideoSeek, poseExtractorNets, faceExtractorNets, handExtractorNets, renderers
753  );
754  // WGui
755  guiW = {std::make_shared<WGui<TDatumsSP>>(gui)};
756  }
757  else
758  error("Unknown DisplayMode.", __LINE__, __FUNCTION__, __FILE__);
759  }
760  // Set wrapper as configured
761  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
762 
763 
764 
765 
766 
767  // The less number of queues -> the less threads opened, and potentially the less lag
768 
769  // Sanity checks
770  if ((datumProducerW == nullptr) == (userInputWs.empty())
771  && threadManagerMode != ThreadManagerMode::Asynchronous
772  && threadManagerMode != ThreadManagerMode::AsynchronousIn)
773  {
774  const auto message = "You need to have 1 and only 1 producer selected. You can introduce your own"
775  " producer by using setWorker(WorkerType::Input, ...) or use the OpenPose"
776  " default producer by configuring it in the configure function) or use the"
777  " ThreadManagerMode::Asynchronous(In) mode.";
778  error(message, __LINE__, __FUNCTION__, __FILE__);
779  }
780  if (outputWs.empty() && userOutputWs.empty() && guiW == nullptr
781  && threadManagerMode != ThreadManagerMode::Asynchronous
782  && threadManagerMode != ThreadManagerMode::AsynchronousOut)
783  {
784  error("No output selected.", __LINE__, __FUNCTION__, __FILE__);
785  }
786 
787  // Thread Manager
788  // Clean previous thread manager (avoid configure to crash the program if used more than once)
789  threadManager.reset();
790  unsigned long long threadId = 0ull;
791  auto queueIn = 0ull;
792  auto queueOut = 1ull;
793  // After producer
794  // ID generator (before any multi-threading or any function that requires the ID)
795  const auto wIdGenerator = std::make_shared<WIdGenerator<TDatumsSP>>();
796  std::vector<TWorker> workersAux{wIdGenerator};
797  // Scale & cv::Mat to OP format
798  if (scaleAndSizeExtractorW != nullptr)
799  workersAux = mergeVectors(workersAux, {scaleAndSizeExtractorW});
800  if (cvMatToOpInputW != nullptr)
801  workersAux = mergeVectors(workersAux, {cvMatToOpInputW});
802  // cv::Mat to output format
803  if (cvMatToOpOutputW != nullptr)
804  workersAux = mergeVectors(workersAux, {cvMatToOpOutputW});
805 
806  // Producer
807  // If custom user Worker and uses its own thread
808  if (!userInputWs.empty() && userInputWsOnNewThread)
809  {
810  // Thread 0, queues 0 -> 1
811  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
812  threadManager.add(threadId, userInputWs, queueIn++, queueOut++);
813  threadIdPP(threadId, multiThreadEnabled);
814  }
815  // If custom user Worker in same thread
816  else if (!userInputWs.empty())
817  workersAux = mergeVectors(userInputWs, workersAux);
818  // If OpenPose producer (same thread)
819  else if (datumProducerW != nullptr)
820  workersAux = mergeVectors({datumProducerW}, workersAux);
821  // Otherwise
822  else if (threadManagerMode != ThreadManagerMode::Asynchronous
823  && threadManagerMode != ThreadManagerMode::AsynchronousIn)
824  error("No input selected.", __LINE__, __FUNCTION__, __FILE__);
825  // Thread 0 or 1, queues 0 -> 1
826  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
827  threadManager.add(threadId, workersAux, queueIn++, queueOut++);
828  // Increase thread
829  threadIdPP(threadId, multiThreadEnabled);
830 
831  // Pose estimation & rendering
832  // Thread 1 or 2...X, queues 1 -> 2, X = 2 + #GPUs
833  if (!poseExtractorsWs.empty())
834  {
835  if (multiThreadEnabled)
836  {
837  for (auto& wPose : poseExtractorsWs)
838  {
839  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
840  threadManager.add(threadId, wPose, queueIn, queueOut);
841  threadIdPP(threadId, multiThreadEnabled);
842  }
843  queueIn++;
844  queueOut++;
845  // Sort frames - Required own thread
846  if (poseExtractorsWs.size() > 1u)
847  {
848  const auto wQueueOrderer = std::make_shared<WQueueOrderer<TDatumsSP>>();
849  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
850  threadManager.add(threadId, wQueueOrderer, queueIn++, queueOut++);
851  threadIdPP(threadId, multiThreadEnabled);
852  }
853  }
854  else
855  {
856  if (poseExtractorsWs.size() > 1)
857  log("Multi-threading disabled, only 1 thread running. All GPUs have been disabled but the"
858  " first one, which is defined by gpuNumberStart (e.g., in the OpenPose demo, it is set"
859  " with the `--num_gpu_start` flag).", Priority::High);
860  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
861  threadManager.add(threadId, poseExtractorsWs.at(0), queueIn++, queueOut++);
862  }
863  }
864  // Assemble all frames from same time instant (3-D module)
865  const auto wQueueAssembler = std::make_shared<WQueueAssembler<TDatumsSP, TDatums>>();
866  // 3-D reconstruction
867  if (!poseTriangulationsWs.empty())
868  {
869  // Assemble frames
870  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
871  threadManager.add(threadId, wQueueAssembler, queueIn++, queueOut++);
872  threadIdPP(threadId, multiThreadEnabled);
873  // 3-D reconstruction
874  if (multiThreadEnabled)
875  {
876  for (auto& wPoseTriangulations : poseTriangulationsWs)
877  {
878  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
879  threadManager.add(threadId, wPoseTriangulations, queueIn, queueOut);
880  threadIdPP(threadId, multiThreadEnabled);
881  }
882  queueIn++;
883  queueOut++;
884  // Sort frames
885  if (poseTriangulationsWs.size() > 1u)
886  {
887  const auto wQueueOrderer = std::make_shared<WQueueOrderer<TDatumsSP>>();
888  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
889  threadManager.add(threadId, wQueueOrderer, queueIn++, queueOut++);
890  threadIdPP(threadId, multiThreadEnabled);
891  }
892  }
893  else
894  {
895  if (poseTriangulationsWs.size() > 1)
896  log("Multi-threading disabled, only 1 thread running for 3-D triangulation.",
898  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
899  threadManager.add(threadId, poseTriangulationsWs.at(0), queueIn++, queueOut++);
900  }
901  }
902  else
903  postProcessingWs = mergeVectors({wQueueAssembler}, postProcessingWs);
904  // Adam/IK step
905  if (!jointAngleEstimationsWs.empty())
906  {
907  if (multiThreadEnabled)
908  {
909  for (auto& wJointAngleEstimator : jointAngleEstimationsWs)
910  {
911  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
912  threadManager.add(threadId, wJointAngleEstimator, queueIn, queueOut);
913  threadIdPP(threadId, multiThreadEnabled);
914  }
915  queueIn++;
916  queueOut++;
917  // Sort frames
918  if (jointAngleEstimationsWs.size() > 1)
919  {
920  const auto wQueueOrderer = std::make_shared<WQueueOrderer<TDatumsSP>>();
921  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
922  threadManager.add(threadId, wQueueOrderer, queueIn++, queueOut++);
923  threadIdPP(threadId, multiThreadEnabled);
924  }
925  }
926  else
927  {
928  if (jointAngleEstimationsWs.size() > 1)
929  log("Multi-threading disabled, only 1 thread running for joint angle estimation.",
931  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
932  threadManager.add(threadId, jointAngleEstimationsWs.at(0), queueIn++, queueOut++);
933  }
934  }
935  // Post processing workers
936  if (!postProcessingWs.empty())
937  {
938  // Combining postProcessingWs and outputWs
939  outputWs = mergeVectors(postProcessingWs, outputWs);
940  // // If I wanna split them
941  // log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
942  // threadManager.add(threadId, postProcessingWs, queueIn++, queueOut++);
943  // threadIdPP(threadId, multiThreadEnabled);
944  }
945  // If custom user Worker and uses its own thread
946  if (!userPostProcessingWs.empty())
947  {
948  // If custom user Worker in its own thread
949  if (userPostProcessingWsOnNewThread)
950  {
951  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
952  threadManager.add(threadId, userPostProcessingWs, queueIn++, queueOut++);
953  threadIdPP(threadId, multiThreadEnabled);
954  }
955  // If custom user Worker in same thread
956  // Merge with outputWs
957  else
958  outputWs = mergeVectors(outputWs, userPostProcessingWs);
959  }
960  // Output workers
961  if (!outputWs.empty())
962  {
963  // Thread 4 or 5, queues 4 -> 5
964  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
965  threadManager.add(threadId, outputWs, queueIn++, queueOut++);
966  threadIdPP(threadId, multiThreadEnabled);
967  }
968  // User output worker
969  // Thread Y, queues Q -> Q+1
970  if (!userOutputWs.empty())
971  {
972  if (userOutputWsOnNewThread)
973  {
974  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
975  threadManager.add(threadId, userOutputWs, queueIn++, queueOut++);
976  threadIdPP(threadId, multiThreadEnabled);
977  }
978  else
979  {
980  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
981  threadManager.add(threadId-1, userOutputWs, queueIn++, queueOut++);
982  }
983  }
984  // OpenPose GUI
985  if (guiW != nullptr)
986  {
987  // Thread Y+1, queues Q+1 -> Q+2
988  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
989  threadManager.add(threadId, guiW, queueIn++, queueOut++);
990  threadIdPP(threadId, multiThreadEnabled);
991  }
992  log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
993  }
994  catch (const std::exception& e)
995  {
996  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
997  }
998  }
999 }
1000 
1001 #endif // OPENPOSE_WRAPPER_WRAPPER_AUXILIARY_HPP
OP_API void threadIdPP(unsigned long long &threadId, const bool multiThreadEnabled)
int writeCocoJsonVariant
Definition: wrapperStructOutput.hpp:62
Definition: wHandDetectorTracking.hpp:11
Definition: wGuiInfoAdder.hpp:11
std::array< T, N > array
Definition: cl2.hpp:594
float alphaHeatMap
Definition: wrapperStructFace.hpp:46
std::string writeHeatMapsFormat
Definition: wrapperStructOutput.hpp:96
Definition: wPoseSaver.hpp:12
std::string cameraParameterPath
Definition: wrapperStructInput.hpp:77
Definition: wrapperStructPose.hpp:17
std::string writeKeypoint
Definition: wrapperStructOutput.hpp:28
float alphaKeypoint
Definition: wrapperStructFace.hpp:39
bool frameFlip
Definition: wrapperStructInput.hpp:56
Definition: wFaceSaver.hpp:12
float alphaKeypoint
Definition: wrapperStructHand.hpp:61
OP_API void wrapperConfigureSanityChecks(WrapperStructPose &wrapperStructPose, const WrapperStructFace &wrapperStructFace, const WrapperStructHand &wrapperStructHand, const WrapperStructExtra &wrapperStructExtra, const WrapperStructInput &wrapperStructInput, const WrapperStructOutput &wrapperStructOutput, const WrapperStructGui &wrapperStructGui, const bool renderOutput, const bool userOutputWsEmpty, const std::shared_ptr< Producer > &producerSharedPtr, const ThreadManagerMode threadManagerMode)
int tracking
Definition: wrapperStructExtra.hpp:39
Definition: wPeopleJsonSaver.hpp:11
Definition: wHandRenderer.hpp:11
double writeVideoFps
Definition: wrapperStructOutput.hpp:105
Definition: wImageSaver.hpp:11
std::string udpPort
Definition: wrapperStructOutput.hpp:129
std::string writeImages
Definition: wrapperStructOutput.hpp:68
std::shared_ptr< std::atomic< bool > > getIsRunningSharedPtr()
Definition: threadManager.hpp:40
T fastMax(const T a, const T b)
Definition: fastMath.hpp:70
float alphaHeatMap
Definition: wrapperStructHand.hpp:68
bool framesRepeat
Definition: wrapperStructInput.hpp:67
Definition: wKeypointScaler.hpp:11
int minViews3d
Definition: wrapperStructExtra.hpp:27
std::string writeHeatMaps
Definition: wrapperStructOutput.hpp:90
std::string writeCocoJson
Definition: wrapperStructOutput.hpp:51
DisplayMode displayMode
Definition: wrapperStructGui.hpp:23
void add(const unsigned long long threadId, const std::vector< TWorker > &tWorkers, const unsigned long long queueInId, const unsigned long long queueOutId)
Definition: threadManager.hpp:125
Definition: wFaceDetector.hpp:11
void reset()
Definition: threadManager.hpp:157
Definition: wrapperStructFace.hpp:15
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
OP_API std::shared_ptr< Producer > createProducer(const ProducerType producerType=ProducerType::None, const std::string &producerString="", const Point< int > &cameraResolution=Point< int >{-1,-1}, const std::string &cameraParameterPath="models/cameraParameters/", const bool undistortImage=true, const unsigned int imageDirectoryStereo=-1)
Definition: wVerbosePrinter.hpp:11
std::string udpHost
Definition: wrapperStructOutput.hpp:124
DataFormat writeKeypointFormat
Definition: wrapperStructOutput.hpp:35
Definition: wFaceExtractorNet.hpp:11
std::string writeCocoFootJson
Definition: wrapperStructOutput.hpp:56
RenderMode renderMode
Definition: wrapperStructPose.hpp:81
float scaleRange
Definition: wrapperStructHand.hpp:41
OP_API GpuMode getGpuMode()
RenderMode renderMode
Definition: wrapperStructFace.hpp:33
bool tracking
Definition: wrapperStructHand.hpp:49
bool enable
Definition: wrapperStructFace.hpp:20
Definition: wFaceDetectorOpenCV.hpp:11
Definition: wVideoSaver.hpp:11
Definition: wUdpSender.hpp:11
Definition: wOpOutputToCvMat.hpp:11
int ikThreads
Definition: wrapperStructExtra.hpp:46
bool realTimeProcessing
Definition: wrapperStructInput.hpp:51
OP_API std::string formatAsDirectory(const std::string &directoryPathString)
Definition: wHandDetectorUpdate.hpp:11
Definition: wrapperStructInput.hpp:14
unsigned long long frameStep
Definition: wrapperStructInput.hpp:40
Definition: wrapperStructGui.hpp:12
Definition: wHandExtractorNet.hpp:11
std::string writeBvh
Definition: wrapperStructOutput.hpp:119
Definition: wFaceRenderer.hpp:11
bool undistortImage
Definition: wrapperStructInput.hpp:82
Definition: wPoseRenderer.hpp:11
std::string writeJson
Definition: wrapperStructOutput.hpp:45
OP_API void log(const std::string &message, const Priority priority=Priority::Max, const int line=-1, const std::string &function="", const std::string &file="")
Definition: wCocoJsonSaver.hpp:11
double verbose
Definition: wrapperStructOutput.hpp:21
bool guiVerbose
Definition: wrapperStructGui.hpp:29
Definition: wrapperStructExtra.hpp:13
Definition: wrapperStructHand.hpp:15
float renderThreshold
Definition: wrapperStructHand.hpp:76
Definition: poseGpuRenderer.hpp:13
Definition: wHandDetector.hpp:11
std::string writeVideoAdam
Definition: wrapperStructOutput.hpp:112
std::vector< T > mergeVectors(const std::vector< T > &vectorA, const std::vector< T > &vectorB)
Definition: standard.hpp:40
Point< int > cameraResolution
Definition: wrapperStructInput.hpp:72
Definition: wHandSaver.hpp:12
ProducerType producerType
Definition: wrapperStructInput.hpp:20
std::string writeVideo
Definition: wrapperStructOutput.hpp:83
unsigned long long frameLast
Definition: wrapperStructInput.hpp:46
bool identification
Definition: wrapperStructExtra.hpp:32
Point< int > netInputSize
Definition: wrapperStructFace.hpp:27
void setSharedParametersAndIfLast(const std::tuple< std::shared_ptr< float * >, std::shared_ptr< bool >, std::shared_ptr< std::atomic< unsigned int >>, std::shared_ptr< std::atomic< unsigned long long >>, std::shared_ptr< const unsigned int >> &tuple, const bool isLast)
Definition: wHeatMapSaver.hpp:11
std::string producerString
Definition: wrapperStructInput.hpp:27
bool enable
Definition: wrapperStructHand.hpp:20
ThreadManagerMode
Definition: enumClasses.hpp:9
unsigned int imageDirectoryStereo
Definition: wrapperStructInput.hpp:87
#define OP_API
Definition: macros.hpp:19
float renderThreshold
Definition: wrapperStructFace.hpp:54
int frameRotate
Definition: wrapperStructInput.hpp:62
std::string writeImagesFormat
Definition: wrapperStructOutput.hpp:76
unsigned long long frameFirst
Definition: wrapperStructInput.hpp:33
Definition: wrapperStructOutput.hpp:13
bool reconstruct3d
Definition: wrapperStructExtra.hpp:21
OP_API int getGpuNumber()
Point< int > netInputSize
Definition: wrapperStructHand.hpp:27
void configureThreadManager(ThreadManager< TDatumsSP > &threadManager, const bool multiThreadEnabled, const ThreadManagerMode threadManagerMode, const WrapperStructPose &wrapperStructPose, const WrapperStructFace &wrapperStructFace, const WrapperStructHand &wrapperStructHand, const WrapperStructExtra &wrapperStructExtra, const WrapperStructInput &wrapperStructInput, const WrapperStructOutput &wrapperStructOutput, const WrapperStructGui &wrapperStructGui, const std::array< std::vector< TWorker >, int(WorkerType::Size)> &userWs, const std::array< bool, int(WorkerType::Size)> &userWsOnNewThread)
Definition: wrapperAuxiliary.hpp:85
int scalesNumber
Definition: wrapperStructHand.hpp:35
RenderMode renderMode
Definition: wrapperStructHand.hpp:55
bool fullScreen
Definition: wrapperStructGui.hpp:35