1 #ifndef OPENPOSE_WRAPPER_WRAPPER_AUXILIARY_HPP
2 #define OPENPOSE_WRAPPER_WRAPPER_AUXILIARY_HPP
33 const WrapperStructGui& wrapperStructGui,
const bool renderOutput,
const bool userInputAndPreprocessingWsEmpty,
34 const bool userOutputWsEmpty,
const std::shared_ptr<Producer>& producerSharedPtr,
53 template<
typename TDatum,
54 typename TDatums = std::vector<std::shared_ptr<TDatum>>,
55 typename TDatumsSP = std::shared_ptr<TDatums>,
56 typename TWorker = std::shared_ptr<Worker<TDatumsSP>>>
70 template<
typename TDatum,
71 typename TDatums = std::vector<std::shared_ptr<TDatum>>,
72 typename TDatumsSP = std::shared_ptr<TDatums>>
74 TDatumsSP& tDatumsSP,
unsigned long long& frameCounter,
97 template<
typename TDatum,
typename TDatums,
typename TDatumsSP,
typename TWorker>
118 auto wrapperStructPose = wrapperStructPoseTemp;
119 auto multiThreadEnabled = multiThreadEnabledTemp;
132 const auto spVideoSeek = std::make_shared<std::pair<std::atomic<bool>, std::atomic<int>>>();
134 spVideoSeek->first =
false;
135 spVideoSeek->second = 0;
139 const auto renderModePose = (
143 const auto renderModeFace = (
147 const auto renderModeHand = (
170 const bool userInputAndPreprocessingWsEmpty = userInputWs.empty() && userPreProcessingWs.empty();
171 const bool userOutputWsEmpty = userOutputWs.empty();
173 wrapperStructPose, wrapperStructFace, wrapperStructHand, wrapperStructExtra, wrapperStructInput,
174 wrapperStructOutput, wrapperStructGui, renderOutput, userInputAndPreprocessingWsEmpty,
175 userOutputWsEmpty, producerSharedPtr, threadManagerMode);
176 opLog(
"userInputAndPreprocessingWsEmpty = " + std::to_string(
int(userInputAndPreprocessingWsEmpty)),
181 auto numberGpuThreads = wrapperStructPose.
gpuNumber;
188 numberGpuThreads = (wrapperStructPose.
gpuNumber == 0 ? 0 : 1);
193 multiThreadEnabled =
false;
201 if (numberGpuThreads < 0)
203 if (totalGpuNumber <= gpuNumberStart)
204 error(
"Number of initial GPU (`--number_gpu_start`) must be lower than the total number of"
205 " used GPUs (`--number_gpu`)", __LINE__, __FUNCTION__, __FILE__);
206 numberGpuThreads = totalGpuNumber - gpuNumberStart;
209 opLog(
"Auto-detecting all available GPUs... Detected " + std::to_string(totalGpuNumber)
210 +
" GPU(s), using " + std::to_string(numberGpuThreads) +
" of them starting at GPU "
214 if (gpuNumberStart + numberGpuThreads > totalGpuNumber)
215 error(
"Initial GPU selected (`--number_gpu_start`) + number GPUs to use (`--number_gpu`) must"
216 " be lower or equal than the total number of GPUs in your machine ("
217 + std::to_string(gpuNumberStart) +
" + "
218 + std::to_string(numberGpuThreads) +
" vs. "
219 + std::to_string(totalGpuNumber) +
").",
220 __LINE__, __FUNCTION__, __FILE__);
236 auto finalOutputSize = wrapperStructPose.
outputSize;
238 const auto oPProducer = (producerSharedPtr !=
nullptr);
244 producerSharedPtr->setProducerFpsMode(displayProducerFpsMode);
252 if (finalOutputSize.x == -1 || finalOutputSize.y == -1)
253 finalOutputSize = producerSize;
255 opLog(
"finalOutputSize = [" + std::to_string(finalOutputSize.x) +
"," + std::to_string(finalOutputSize.y)
259 TWorker datumProducerW;
262 const auto datumProducer = std::make_shared<DatumProducer<TDatum>>(
264 wrapperStructInput.
frameLast, spVideoSeek
266 datumProducerW = std::make_shared<WDatumProducer<TDatum>>(datumProducer);
269 datumProducerW =
nullptr;
271 std::vector<std::shared_ptr<PoseExtractorNet>> poseExtractorNets;
272 std::vector<std::shared_ptr<FaceExtractorNet>> faceExtractorNets;
273 std::vector<std::shared_ptr<HandExtractorNet>> handExtractorNets;
274 std::vector<std::shared_ptr<PoseGpuRenderer>> poseGpuRenderers;
276 std::vector<std::shared_ptr<CvMatToOpOutput>> cvMatToOpOutputs;
277 std::vector<std::shared_ptr<OpOutputToCvMat>> opOutputToCvMats;
278 std::shared_ptr<PoseCpuRenderer> poseCpuRenderer;
280 TWorker scaleAndSizeExtractorW;
281 TWorker cvMatToOpInputW;
282 TWorker cvMatToOpOutputW;
283 bool addCvMatToOpOutput = renderOutput;
284 bool addCvMatToOpOutputInCpu = addCvMatToOpOutput;
285 std::vector<std::vector<TWorker>> poseExtractorsWs;
286 std::vector<std::vector<TWorker>> poseTriangulationsWs;
287 std::vector<std::vector<TWorker>> jointAngleEstimationsWs;
288 std::vector<TWorker> postProcessingWs;
289 if (numberGpuThreads > 0)
292 const auto scaleAndSizeExtractor = std::make_shared<ScaleAndSizeExtractor>(
295 scaleAndSizeExtractorW = std::make_shared<WScaleAndSizeExtractor<TDatumsSP>>(scaleAndSizeExtractor);
299 bool resizeOnCpu =
true;
303 const auto gpuResize =
false;
304 const auto cvMatToOpInput = std::make_shared<CvMatToOpInput>(
306 cvMatToOpInputW = std::make_shared<WCvMatToOpInput<TDatumsSP>>(cvMatToOpInput);
310 addCvMatToOpOutputInCpu = addCvMatToOpOutput
314 if (addCvMatToOpOutputInCpu)
316 const auto gpuResize =
false;
317 const auto cvMatToOpOutput = std::make_shared<CvMatToOpOutput>(gpuResize);
318 cvMatToOpOutputW = std::make_shared<WCvMatToOpOutput<TDatumsSP>>(cvMatToOpOutput);
322 std::vector<TWorker> cpuRenderers;
323 poseExtractorsWs.clear();
324 poseExtractorsWs.resize(numberGpuThreads);
328 for (
auto gpuId = 0; gpuId < numberGpuThreads; gpuId++)
329 poseExtractorNets.emplace_back(std::make_shared<PoseExtractorCaffe>(
330 wrapperStructPose.
poseModel, modelFolder, gpuId + gpuNumberStart,
351 for (
const auto& poseExtractorNet : poseExtractorNets)
353 poseGpuRenderers.emplace_back(std::make_shared<PoseGpuRenderer>(
363 poseCpuRenderer = std::make_shared<PoseCpuRenderer>(
373 poseExtractorsWs.resize(poseExtractorNets.size());
375 ? std::make_shared<PersonIdExtractor>() :
nullptr);
386 auto personTrackers = std::make_shared<std::vector<std::shared_ptr<PersonTracker>>>();
387 if (wrapperStructExtra.
tracking > -1)
388 personTrackers->emplace_back(
389 std::make_shared<PersonTracker>(wrapperStructExtra.
tracking == 0));
390 for (
auto i = 0u; i < poseExtractorsWs.size(); i++)
394 const auto poseExtractor = std::make_shared<PoseExtractor>(
395 poseExtractorNets.at(i), keepTopNPeople, personIdExtractor, personTrackers,
398 if (cvMatToOpInputW ==
nullptr)
400 const auto gpuResize =
true;
401 const auto cvMatToOpInput = std::make_shared<CvMatToOpInput>(
403 poseExtractorsWs.at(i).emplace_back(
407 if (addCvMatToOpOutput && cvMatToOpOutputW ==
nullptr)
409 const auto gpuResize =
true;
410 cvMatToOpOutputs.emplace_back(std::make_shared<CvMatToOpOutput>(gpuResize));
411 poseExtractorsWs.at(i).emplace_back(
414 poseExtractorsWs.at(i).emplace_back(
438 if (!poseGpuRenderers.empty())
441 for (
auto i = 0u; i < poseExtractorsWs.size(); i++)
444 poseGpuRenderers.at(i)));
446 if (!cvMatToOpOutputs.empty())
447 poseGpuRenderers.at(i)->setSharedParameters(
448 cvMatToOpOutputs.at(i)->getSharedParameters());
454 if (wrapperStructFace.
enable)
463 error(
"Body keypoint detection is disabled but face Detector is set to Body. Either"
464 " re-enable OpenPose body or select a different face Detector (`--face_detector`).",
465 __LINE__, __FUNCTION__, __FILE__);
467 const auto faceDetector = std::make_shared<FaceDetector>(wrapperStructPose.
poseModel);
468 for (
auto& wPose : poseExtractorsWs)
474 opLog(
"Body keypoint detection is disabled. Hence, using OpenCV face detector (much less"
476 for (
auto& wPose : poseExtractorsWs)
479 const auto faceDetectorOpenCV = std::make_shared<FaceDetectorOpenCV>(modelFolder);
488 error(
"Unknown face Detector. Select a valid face Detector (`--face_detector`).",
489 __LINE__, __FUNCTION__, __FILE__);
491 for (
auto gpu = 0u; gpu < poseExtractorsWs.size(); gpu++)
494 const auto netOutputSize = wrapperStructFace.
netInputSize;
495 const auto faceExtractorNet = std::make_shared<FaceExtractorCaffe>(
496 wrapperStructFace.
netInputSize, netOutputSize, modelFolder,
500 faceExtractorNets.emplace_back(faceExtractorNet);
501 poseExtractorsWs.at(gpu).emplace_back(
508 if (wrapperStructHand.
enable)
511 const auto handDetector = std::make_shared<HandDetector>(wrapperStructPose.
poseModel);
512 for (
auto gpu = 0u; gpu < poseExtractorsWs.size(); gpu++)
518 error(
"Body keypoint detection is disabled but hand Detector is set to Body. Either"
519 " re-enable OpenPose body or select a different hand Detector (`--hand_detector`).",
520 __LINE__, __FUNCTION__, __FILE__);
525 poseExtractorsWs.at(gpu).emplace_back(
531 poseExtractorsWs.at(gpu).emplace_back(
537 error(
"Unknown hand Detector. Select a valid hand Detector (`--hand_detector`).",
538 __LINE__, __FUNCTION__, __FILE__);
540 const auto netOutputSize = wrapperStructHand.
netInputSize;
541 const auto handExtractorNet = std::make_shared<HandExtractorCaffe>(
542 wrapperStructHand.
netInputSize, netOutputSize, modelFolder,
547 handExtractorNets.emplace_back(handExtractorNet);
548 poseExtractorsWs.at(gpu).emplace_back(
553 poseExtractorsWs.at(gpu).emplace_back(
567 const auto faceRenderer = std::make_shared<FaceCpuRenderer>(
576 for (
auto i = 0u; i < poseExtractorsWs.size(); i++)
579 const auto faceRenderer = std::make_shared<FaceGpuRenderer>(
584 if (!poseGpuRenderers.empty())
587 const bool isLastRenderer = !renderHandGpu && !(addCvMatToOpOutput && !addCvMatToOpOutputInCpu);
588 const auto renderer = std::static_pointer_cast<PoseGpuRenderer>(
589 poseGpuRenderers.at(i));
590 faceRenderer->setSharedParametersAndIfLast(
591 renderer->getSharedParameters(), isLastRenderer);
594 poseExtractorsWs.at(i).emplace_back(
599 error(
"Unknown RenderMode.", __LINE__, __FUNCTION__, __FILE__);
611 const auto handRenderer = std::make_shared<HandCpuRenderer>(
620 for (
auto i = 0u; i < poseExtractorsWs.size(); i++)
623 const auto handRenderer = std::make_shared<HandGpuRenderer>(
628 if (!poseGpuRenderers.empty())
631 const bool isLastRenderer = !(addCvMatToOpOutput && !addCvMatToOpOutputInCpu);
632 const auto renderer = std::static_pointer_cast<PoseGpuRenderer>(
633 poseGpuRenderers.at(i));
634 handRenderer->setSharedParametersAndIfLast(
635 renderer->getSharedParameters(), isLastRenderer);
638 poseExtractorsWs.at(i).emplace_back(
643 error(
"Unknown RenderMode.", __LINE__, __FUNCTION__, __FILE__);
648 if (addCvMatToOpOutput && !addCvMatToOpOutputInCpu)
651 for (
auto i = 0u ; i < poseExtractorsWs.size() ; ++i)
653 const auto gpuResize =
true;
654 opOutputToCvMats.emplace_back(std::make_shared<OpOutputToCvMat>(gpuResize));
655 poseExtractorsWs.at(i).emplace_back(
658 opOutputToCvMats.back()->setSharedParameters(
659 cvMatToOpOutputs.at(i)->getSharedParameters());
665 poseTriangulationsWs.clear();
670 poseTriangulationsWs.resize(
fastMax(1,
int(poseExtractorsWs.size() / 4)));
671 for (
auto i = 0u ; i < poseTriangulationsWs.size() ; i++)
673 const auto poseTriangulation = std::make_shared<PoseTriangulation>(
675 poseTriangulationsWs.at(i) = {std::make_shared<WPoseTriangulation<TDatumsSP>>(
681 postProcessingWs.clear();
691 if (addCvMatToOpOutputInCpu)
694 postProcessingWs =
mergeVectors(postProcessingWs, cpuRenderers);
695 const auto opOutputToCvMat = std::make_shared<OpOutputToCvMat>();
704 (finalOutputSize == producerSize || finalOutputSize.x <= 0 || finalOutputSize.y <= 0))
710 auto keypointScaler = std::make_shared<KeypointScaler>(wrapperStructPose.
keypointScaleMode);
720 jointAngleEstimationsWs.clear();
721 #ifdef USE_3D_ADAM_MODEL
725 jointAngleEstimationsWs.resize(wrapperStructExtra.
ikThreads);
727 for (
auto i = 0u; i < jointAngleEstimationsWs.size(); i++)
729 const auto jointAngleEstimation = std::make_shared<JointAngleEstimation>(displayAdam);
730 jointAngleEstimationsWs.at(i) = {std::make_shared<WJointAngleEstimation<TDatumsSP>>(
731 jointAngleEstimation)};
738 std::vector<TWorker> outputWs;
740 if (wrapperStructOutput.
verbose > 0.)
743 const auto verbosePrinter = std::make_shared<VerbosePrinter>(
750 #ifdef USE_3D_ADAM_MODEL
754 const auto udpSender = std::make_shared<UdpSender>(wrapperStructOutput.
udpHost,
761 if (!writeKeypointCleaned.empty())
764 const auto keypointSaver = std::make_shared<KeypointSaver>(writeKeypointCleaned,
767 if (wrapperStructFace.
enable)
769 if (wrapperStructHand.
enable)
775 if (!writeJsonCleaned.empty())
778 const auto peopleJsonSaver = std::make_shared<PeopleJsonSaver>(writeJsonCleaned);
787 const auto humanFormat =
true;
788 const auto cocoJsonSaver = std::make_shared<CocoJsonSaver>(
800 if (!writeImagesCleaned.empty())
803 const auto imageSaver = std::make_shared<ImageSaver>(
808 auto originalVideoFps = 0.;
815 error(
"The frame rate of the frames producer is unknown. Set `--write_video_fps` to your desired"
816 " FPS if you wanna record video (`--write_video`). E.g., if it is a folder of images, you"
817 " will have to know or guess the frame rate; if it is a webcam, you should use the OpenPose"
818 " displayed FPS as desired value. If you do not care, simply add `--write_video_fps 30`.",
819 __LINE__, __FUNCTION__, __FILE__);
831 error(
"Video file can only be recorded inside `wrapper/wrapper.hpp` if the producer"
832 " is one of the default ones (e.g., video, webcam, ...).",
833 __LINE__, __FUNCTION__, __FILE__);
835 error(
"Audio can only be added to the output saved video if the input is also a video (either"
836 " disable `--write_video_with_audio` or use a video as input with `--video`).",
837 __LINE__, __FUNCTION__, __FILE__);
839 const auto videoSaver = std::make_shared<VideoSaver>(
846 #ifdef USE_3D_ADAM_MODEL
850 const auto bvhSaver = std::make_shared<BvhSaver>(
851 wrapperStructOutput.
writeBvh, JointAngleEstimation::getTotalModel(), originalVideoFps
853 outputWs.emplace_back(std::make_shared<WBvhSaver<TDatumsSP>>(bvhSaver));
858 if (!writeHeatMapsCleaned.empty())
861 const auto heatMapSaver = std::make_shared<HeatMapSaver>(
870 if (wrapperStructGui.
guiVerbose && (guiEnabled || !userOutputWs.empty()
875 const auto guiInfoAdder = std::make_shared<GuiInfoAdder>(numberGpuThreads, guiEnabled);
881 TWorker videoSaver3DW;
886 std::vector<std::shared_ptr<Renderer>> renderers;
888 renderers.emplace_back(std::static_pointer_cast<Renderer>(poseCpuRenderer));
890 for (
const auto& poseGpuRenderer : poseGpuRenderers)
891 renderers.emplace_back(std::static_pointer_cast<Renderer>(poseGpuRenderer));
893 const auto numberViews = (producerSharedPtr !=
nullptr
895 auto finalOutputSizeGui = finalOutputSize;
896 if (numberViews > 1 && finalOutputSizeGui.x > 0)
897 finalOutputSizeGui.x *= numberViews;
901 #ifdef USE_3D_ADAM_MODEL
904 const auto gui = std::make_shared<GuiAdam>(
906 spVideoSeek, poseExtractorNets, faceExtractorNets, handExtractorNets, renderers,
907 wrapperStructGui.
displayMode, JointAngleEstimation::getTotalModel(),
911 guiW = {std::make_shared<WGuiAdam<TDatumsSP>>(gui)};
914 error(
"3D video can only be recorded if 3D render is enabled.",
915 __LINE__, __FUNCTION__, __FILE__);
924 const auto gui = std::make_shared<Gui3D>(
926 spVideoSeek, poseExtractorNets, faceExtractorNets, handExtractorNets, renderers,
931 guiW = {std::make_shared<WGui3D<TDatumsSP>>(gui)};
935 const auto videoSaver = std::make_shared<VideoSaver>(
937 videoSaver3DW = std::make_shared<WVideoSaver3D<TDatumsSP>>(videoSaver);
945 const auto gui = std::make_shared<Gui>(
947 spVideoSeek, poseExtractorNets, faceExtractorNets, handExtractorNets, renderers
950 guiW = {std::make_shared<WGui<TDatumsSP>>(gui)};
953 error(
"3D video can only be recorded if 3D render is enabled.",
954 __LINE__, __FUNCTION__, __FILE__);
957 error(
"Unknown DisplayMode.", __LINE__, __FUNCTION__, __FILE__);
962 if (wrapperStructPose.
fpsMax > 0.)
963 wFpsMax = std::make_shared<WFpsMax<TDatumsSP>>(wrapperStructPose.
fpsMax);
974 if ((datumProducerW ==
nullptr) == (userInputWs.empty())
978 const auto message =
"You need to have 1 and only 1 producer selected. You can introduce your own"
979 " producer by using setWorker(WorkerType::Input, ...) or use the OpenPose"
980 " default producer by configuring it in the configure function) or use the"
981 " ThreadManagerMode::Asynchronous(In) mode.";
982 error(message, __LINE__, __FUNCTION__, __FILE__);
984 if (outputWs.empty() && userOutputWs.empty() && guiW ==
nullptr
988 error(
"No output selected.", __LINE__, __FUNCTION__, __FILE__);
993 threadManager.
reset();
994 unsigned long long threadId = 0ull;
996 auto queueOut = 1ull;
999 const auto wIdGenerator = std::make_shared<WIdGenerator<TDatumsSP>>();
1001 std::vector<TWorker> workersAux;
1002 if (!userPreProcessingWs.empty())
1005 if (userPreProcessingWsOnNewThread)
1006 opLog(
"You chose to add your pre-processing function in a new thread. However, OpenPose will"
1007 " add it in the same thread than the input frame producer.",
1009 workersAux =
mergeVectors(workersAux, {userPreProcessingWs});
1013 if (scaleAndSizeExtractorW !=
nullptr)
1014 workersAux =
mergeVectors(workersAux, {scaleAndSizeExtractorW});
1015 if (cvMatToOpInputW !=
nullptr)
1016 workersAux =
mergeVectors(workersAux, {cvMatToOpInputW});
1018 if (cvMatToOpOutputW !=
nullptr)
1019 workersAux =
mergeVectors(workersAux, {cvMatToOpOutputW});
1023 if (!userInputWs.empty() && userInputWsOnNewThread)
1027 threadManager.
add(threadId, userInputWs, queueIn++, queueOut++);
1031 else if (!userInputWs.empty())
1034 else if (datumProducerW !=
nullptr)
1035 workersAux =
mergeVectors({datumProducerW}, workersAux);
1039 error(
"No input selected.", __LINE__, __FUNCTION__, __FILE__);
1042 threadManager.
add(threadId, workersAux, queueIn++, queueOut++);
1048 if (!poseExtractorsWs.empty())
1050 if (multiThreadEnabled)
1052 for (
auto& wPose : poseExtractorsWs)
1055 threadManager.
add(threadId, wPose, queueIn, queueOut);
1061 if (poseExtractorsWs.size() > 1u)
1063 const auto wQueueOrderer = std::make_shared<WQueueOrderer<TDatumsSP>>();
1065 threadManager.
add(threadId, wQueueOrderer, queueIn++, queueOut++);
1071 if (poseExtractorsWs.size() > 1)
1072 opLog(
"Multi-threading disabled, only 1 thread running. All GPUs have been disabled but the"
1073 " first one, which is defined by gpuNumberStart (e.g., in the OpenPose demo, it is set"
1076 threadManager.
add(threadId, poseExtractorsWs.at(0), queueIn++, queueOut++);
1080 const auto wQueueAssembler = std::make_shared<WQueueAssembler<TDatums>>();
1082 if (!poseTriangulationsWs.empty())
1086 threadManager.
add(threadId, wQueueAssembler, queueIn++, queueOut++);
1089 if (multiThreadEnabled)
1091 for (
auto& wPoseTriangulations : poseTriangulationsWs)
1094 threadManager.
add(threadId, wPoseTriangulations, queueIn, queueOut);
1100 if (poseTriangulationsWs.size() > 1u)
1102 const auto wQueueOrderer = std::make_shared<WQueueOrderer<TDatumsSP>>();
1104 threadManager.
add(threadId, wQueueOrderer, queueIn++, queueOut++);
1110 if (poseTriangulationsWs.size() > 1)
1111 opLog(
"Multi-threading disabled, only 1 thread running for 3-D triangulation.",
1114 threadManager.
add(threadId, poseTriangulationsWs.at(0), queueIn++, queueOut++);
1118 postProcessingWs =
mergeVectors({wQueueAssembler}, postProcessingWs);
1120 if (!jointAngleEstimationsWs.empty())
1122 if (multiThreadEnabled)
1124 for (
auto& wJointAngleEstimator : jointAngleEstimationsWs)
1127 threadManager.
add(threadId, wJointAngleEstimator, queueIn, queueOut);
1133 if (jointAngleEstimationsWs.size() > 1)
1135 const auto wQueueOrderer = std::make_shared<WQueueOrderer<TDatumsSP>>();
1137 threadManager.
add(threadId, wQueueOrderer, queueIn++, queueOut++);
1143 if (jointAngleEstimationsWs.size() > 1)
1144 opLog(
"Multi-threading disabled, only 1 thread running for joint angle estimation.",
1147 threadManager.
add(threadId, jointAngleEstimationsWs.at(0), queueIn++, queueOut++);
1151 if (!postProcessingWs.empty())
1161 if (!userPostProcessingWs.empty())
1164 if (userPostProcessingWsOnNewThread)
1167 threadManager.
add(threadId, userPostProcessingWs, queueIn++, queueOut++);
1173 outputWs =
mergeVectors(outputWs, userPostProcessingWs);
1176 if (!outputWs.empty())
1180 threadManager.
add(threadId, outputWs, queueIn++, queueOut++);
1185 if (!userOutputWs.empty())
1187 if (userOutputWsOnNewThread)
1190 threadManager.
add(threadId, userOutputWs, queueIn++, queueOut++);
1196 threadManager.
add(threadId-1, userOutputWs, queueIn++, queueOut++);
1200 if (guiW !=
nullptr)
1204 threadManager.
add(threadId, guiW, queueIn++, queueOut++);
1206 if (videoSaver3DW !=
nullptr)
1207 threadManager.
add(threadId, videoSaver3DW, queueIn++, queueOut++);
1212 if (wFpsMax !=
nullptr)
1215 threadManager.
add(threadId, wFpsMax, queueIn++, queueOut++);
1219 catch (
const std::exception& e)
1221 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
1225 template<
typename TDatum,
typename TDatums,
typename TDatumsSP>
1227 TDatumsSP& tDatumsSP,
unsigned long long& frameCounter,
1233 if (tDatumsSP ==
nullptr)
1234 op::error(
"tDatumsSP was nullptr, it must be initialized.", __LINE__, __FUNCTION__, __FILE__);
1236 const std::vector<op::Matrix>& cameraMatrices = cameraParameterReader.
getCameraMatrices();
1237 const std::vector<op::Matrix>& cameraIntrinsics = cameraParameterReader.
getCameraIntrinsics();
1238 const std::vector<op::Matrix>& cameraExtrinsics = cameraParameterReader.
getCameraExtrinsics();
1239 const auto matrixesSize = cameraMatrices.size();
1241 if (cameraMatrices.size() < 2)
1242 op::error(
"There is less than 2 camera parameter matrices.",
1243 __LINE__, __FUNCTION__, __FILE__);
1244 if (cameraMatrices.size() != cameraIntrinsics.size() || cameraMatrices.size() != cameraExtrinsics.size())
1245 op::error(
"Camera parameters must have the same size.", __LINE__, __FUNCTION__, __FILE__);
1247 std::vector<op::Matrix> imagesToProcess(matrixesSize);
1250 tDatumsSP->resize(cameraMatrices.size());
1251 for (
auto datumIndex = 0 ; datumIndex < matrixesSize ; ++datumIndex)
1253 auto& datumPtr = tDatumsSP->at(datumIndex);
1254 datumPtr = std::make_shared<op::Datum>();
1255 datumPtr->frameNumber = frameCounter;
1256 datumPtr->cvInputData = imagesToProcess[datumIndex];
1257 if (matrixesSize > 1)
1259 datumPtr->subId = datumIndex;
1260 datumPtr->subIdMax = matrixesSize-1;
1261 datumPtr->cameraMatrix = cameraMatrices[datumIndex];
1262 datumPtr->cameraExtrinsics = cameraExtrinsics[datumIndex];
1263 datumPtr->cameraIntrinsics = cameraIntrinsics[datumIndex];
1268 catch (
const std::exception& e)
1270 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
const std::vector< Matrix > & getCameraIntrinsics() const
const std::vector< Matrix > & getCameraExtrinsics() const
const std::vector< Matrix > & getCameraMatrices() const
static void splitCvMatIntoVectorMatrix(std::vector< Matrix > &matrixesResized, const void *const cvMatPtr)
const std::string & getStdString() const
std::shared_ptr< std::atomic< bool > > getIsRunningSharedPtr()
void add(const unsigned long long threadId, const std::vector< TWorker > &tWorkers, const unsigned long long queueInId, const unsigned long long queueOutId)
OP_API int getCvCapPropFrameCount()
OP_API int getCvCapPropFrameHeight()
void createMultiviewTDatum(TDatumsSP &tDatumsSP, unsigned long long &frameCounter, const CameraParameterReader &cameraParameterReader, const void *const cvMatPtr)
OP_API int getCvFourcc(const char c1, const char c2, const char c3, const char c4)
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)
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
int positiveIntRound(const T a)
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 int numberViews=-1)
OP_API int getCvCapPropFrameWidth()
unsigned long long uLongLongRound(const T a)
OP_API GpuMode getGpuMode()
T fastMax(const T a, const T b)
std::vector< T > mergeVectors(const std::vector< T > &vectorA, const std::vector< T > &vectorB)
OP_API void opLog(const std::string &message, const Priority priority=Priority::Max, const int line=-1, const std::string &function="", const std::string &file="")
OP_API int getGpuNumber()
OP_API int getCvCapPropFrameFps()
OP_API std::string formatAsDirectory(const std::string &directoryPathString)
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 userInputAndPreprocessingWsEmpty, const bool userOutputWsEmpty, const std::shared_ptr< Producer > &producerSharedPtr, const ThreadManagerMode threadManagerMode)
OP_API void threadIdPP(unsigned long long &threadId, const bool multiThreadEnabled)
Point< int > netInputSize
Point< int > netInputSize
String writeHeatMapsFormat
int writeCocoJsonVariants
DataFormat writeKeypointFormat
ScaleMode keypointScaleMode
ScaleMode heatMapScaleMode
double netInputSizeDynamicBehavior
std::vector< HeatMapType > heatMapTypes
Point< int > netInputSize