From ea771954ea39bf92b70ab3573ad53b78bb4f749c Mon Sep 17 00:00:00 2001 From: gineshidalgo99 Date: Tue, 8 Jan 2019 20:05:08 -0500 Subject: [PATCH] Wrapper template simplified --- doc/library_add_new_module.md | 2 +- doc/library_overview.md | 8 +- doc/release_notes.md | 1 + examples/tests/handFromJsonTest.cpp | 2 +- examples/tests/wrapperHandFromJsonTest.hpp | 46 ++++---- .../1_custom_post_processing.cpp | 4 +- .../wUserPostProcessing.hpp | 2 +- .../tutorial_api_cpp/1_body_from_image.cpp | 8 +- .../2_whole_body_from_image.cpp | 14 +-- .../3_keypoints_from_image_configurable.cpp | 14 +-- ...nchronous_loop_custom_input_and_output.cpp | 41 +++---- .../5_asynchronous_loop_custom_output.cpp | 31 ++--- .../6_synchronous_custom_postprocessing.cpp | 17 +-- .../7_synchronous_custom_input.cpp | 17 +-- .../8_synchronous_custom_output.cpp | 29 ++--- .../9_synchronous_custom_all.cpp | 53 ++++----- .../thread_1_openpose_read_and_display.cpp | 12 +- .../thread_2_user_processing_function.cpp | 24 ++-- ...ead_3_user_input_processing_and_output.cpp | 40 +++---- ...user_input_processing_output_and_datum.cpp | 43 +++---- include/openpose/3d/wJointAngleEstimation.hpp | 12 +- include/openpose/3d/wPoseTriangulation.hpp | 26 ++--- include/openpose/core/datum.hpp | 9 +- include/openpose/core/wCvMatToOpInput.hpp | 7 +- include/openpose/core/wCvMatToOpOutput.hpp | 6 +- include/openpose/core/wKeepTopNPeople.hpp | 16 +-- include/openpose/core/wKeypointScaler.hpp | 17 +-- include/openpose/core/wOpOutputToCvMat.hpp | 4 +- .../openpose/core/wScaleAndSizeExtractor.hpp | 8 +- include/openpose/core/wVerbosePrinter.hpp | 4 +- include/openpose/face/wFaceDetector.hpp | 4 +- include/openpose/face/wFaceDetectorOpenCV.hpp | 4 +- include/openpose/face/wFaceExtractorNet.hpp | 8 +- include/openpose/face/wFaceRenderer.hpp | 6 +- include/openpose/filestream/wBvhSaver.hpp | 6 +- .../openpose/filestream/wCocoJsonSaver.hpp | 4 +- include/openpose/filestream/wFaceSaver.hpp | 5 +- include/openpose/filestream/wHandSaver.hpp | 7 +- include/openpose/filestream/wHeatMapSaver.hpp | 6 +- include/openpose/filestream/wImageSaver.hpp | 5 +- .../openpose/filestream/wPeopleJsonSaver.hpp | 26 ++--- include/openpose/filestream/wPoseSaver.hpp | 5 +- include/openpose/filestream/wUdpSender.hpp | 24 ++-- include/openpose/filestream/wVideoSaver.hpp | 2 +- include/openpose/filestream/wVideoSaver3D.hpp | 2 +- include/openpose/gui/wGui.hpp | 4 +- include/openpose/gui/wGui3D.hpp | 15 +-- include/openpose/gui/wGuiAdam.hpp | 16 +-- include/openpose/gui/wGuiInfoAdder.hpp | 11 +- include/openpose/hand/wHandDetector.hpp | 4 +- .../openpose/hand/wHandDetectorFromTxt.hpp | 4 +- .../openpose/hand/wHandDetectorTracking.hpp | 4 +- include/openpose/hand/wHandDetectorUpdate.hpp | 4 +- include/openpose/hand/wHandExtractorNet.hpp | 8 +- include/openpose/hand/wHandRenderer.hpp | 6 +- include/openpose/pose/wPoseExtractor.hpp | 26 ++--- include/openpose/pose/wPoseExtractorNet.hpp | 18 +-- include/openpose/pose/wPoseRenderer.hpp | 8 +- include/openpose/producer/datumProducer.hpp | 92 ++++++++------- include/openpose/producer/wDatumProducer.hpp | 50 ++++---- include/openpose/thread/queueBase.hpp | 7 +- include/openpose/thread/wIdGenerator.hpp | 10 +- include/openpose/thread/wQueueAssembler.hpp | 36 +++--- include/openpose/thread/wQueueOrderer.hpp | 20 ++-- .../openpose/tracking/wPersonIdExtractor.hpp | 5 +- include/openpose/wrapper/wrapper.hpp | 110 +++++++++--------- include/openpose/wrapper/wrapperAuxiliary.hpp | 11 +- scripts/ubuntu/Makefile.example | 1 + src/openpose/producer/defineTemplates.cpp | 4 +- src/openpose/thread/defineTemplates.cpp | 9 +- src/openpose/wrapper/defineTemplates.cpp | 2 +- 71 files changed, 576 insertions(+), 540 deletions(-) diff --git a/doc/library_add_new_module.md b/doc/library_add_new_module.md index 09228b37..ae023360 100644 --- a/doc/library_add_new_module.md +++ b/doc/library_add_new_module.md @@ -8,7 +8,7 @@ In order to add a new module, these are the recommended steps in order to develo 2. Implement all the functionality in one `Worker`. I.e., inherit from `Worker` and implement all the functionality on that class (copy the examples from any Worker subclass). 1. The first letter of the class name should be `W` (e.g., `WHairExtractor`). 2. To initially simplify development: - 1. Optionally (higher debug info), you might initially create the Worker as a non-templated class, assuming it uses std::shared_ptr> instead of directly using a template class (following the `examples/tutorial_api_cpp` synchronous examples). While developing, templates provide more confusing debugging info. Turn the class into a template after being initially developed. + 1. Optionally (higher debug info), you might initially create the Worker as a non-templated class, assuming it uses std::shared_ptr>> instead of directly using a template class (following the `examples/tutorial_api_cpp` synchronous examples). While developing, templates provide more confusing debugging info. Turn the class into a template after being initially developed. 2. Optionally (for development speed), use op::Datum as unique argument of your auxiliary functions within that worker. 3. Use the OpenPose Wrapper class in ThreadManagerMode::SingleThread mode (e.g., it allows you to directly use cv::imshow). 4. If you are using your own custom Caffe -> initially change the Caffe for your version. It should directly work. diff --git a/doc/library_overview.md b/doc/library_overview.md index 92363ca9..428a8b79 100644 --- a/doc/library_overview.md +++ b/doc/library_overview.md @@ -70,8 +70,8 @@ The `Datum` class has all the variables that our Workers need to share to each o UserDatum : public op::Datum {/* op::Datum + extra variables */} // Worker and ThreadManager example initialization -op::WGui> userGUI(/* constructor arguments */); -op::ThreadManager> userThreadManager; +op::WGui>> userGUI(/* constructor arguments */); +op::ThreadManager>> userThreadManager; ``` Since `UserDatum` inherits from `op::Datum`, all the original OpenPose code will compile and run with your inherited version of `op::Datum`. @@ -83,7 +83,7 @@ Since `UserDatum` inherits from `op::Datum`, all the original OpenPose code will It manages and automates the multi-threading configuration and execution. The user just needs to add the desired Worker classes to be executed and the parallelization mode, and this class will take care of it. #### Constructor -Just call `op::ThreadManager threadManager`. +Just call `op::ThreadManager threadManager`. #### Adding a Worker Sequence There are 4 ways to add sequence of workers: @@ -171,7 +171,7 @@ All Workers wrap and call a non-Worker non-template equivalent which actually pe By separating functionality and their `Worker` wrappers, we get the good of both points, eliminating the cons. In this way, the user is able to: -1. Change `std::shared_ptr>` for a custom class, implementing his own `Worker` templates, but using the already implemented functionality to create new custom `Worker` templates. +1. Change `std::shared_ptr>>` for a custom class, implementing his own `Worker` templates, but using the already implemented functionality to create new custom `Worker` templates. 2. Create a `Worker` which wraps several non-`Worker`s classes. diff --git a/doc/release_notes.md b/doc/release_notes.md index c6a9d927..9cc66c43 100644 --- a/doc/release_notes.md +++ b/doc/release_notes.md @@ -316,6 +316,7 @@ OpenPose Library - Release Notes 10. Renamed `--camera_parameter_folder` as `--camera_parameter_path` because it could also take a whole XML file path rather than its parent folder. 11. Default value of flag `--scale_gap` changed from 0.3 to 0.25. 12. Moved most sh scripts into the `scripts/` folder. Only models/getModels.sh and the *.bat files are kept under `models/` and `3rdparty/windows`. + 13. For Python compatibility and scalability increase, template `TDatums` used for `include/openpose/wrapper/wrapper.hpp` has changed from `std::vector` to `std::vector>`, including the respective changes in all the worker classes. In addition, some template classes have been simplified to only take 1 template parameter for user simplicity. 3. Main bugs fixed: 1. CMake-GUI was forcing to Release mode, allowed Debug modes too. 2. NMS returns in index 0 the number of found peaks. However, while the number of peaks was truncated to a maximum of 127, this index 0 was saving the real number instead of the truncated one. diff --git a/examples/tests/handFromJsonTest.cpp b/examples/tests/handFromJsonTest.cpp index a17db9c1..acd763c5 100644 --- a/examples/tests/handFromJsonTest.cpp +++ b/examples/tests/handFromJsonTest.cpp @@ -49,7 +49,7 @@ int handFromJsonTest() // OpenPose wrapper op::log("Configuring OpenPose...", op::Priority::High); - op::WrapperHandFromJsonTest> opWrapper; + op::WrapperHandFromJsonTest opWrapper; // Pose configuration (use WrapperStructPose{} for default and recommended configuration) op::WrapperStructPose wrapperStructPose{false, op::flagsToPoint("656x368"), op::flagsToPoint("1280x720"), op::ScaleMode::InputResolution, FLAGS_num_gpu, FLAGS_num_gpu_start, diff --git a/examples/tests/wrapperHandFromJsonTest.hpp b/examples/tests/wrapperHandFromJsonTest.hpp index 12a484cb..3e4250af 100644 --- a/examples/tests/wrapperHandFromJsonTest.hpp +++ b/examples/tests/wrapperHandFromJsonTest.hpp @@ -5,7 +5,8 @@ namespace op { - template>, typename TWorker = std::shared_ptr>>, typename TQueue = Queue>> class WrapperHandFromJsonTest @@ -95,13 +96,13 @@ namespace op #include namespace op { - template - WrapperHandFromJsonTest::WrapperHandFromJsonTest() + template + WrapperHandFromJsonTest::WrapperHandFromJsonTest() { } - template - WrapperHandFromJsonTest::~WrapperHandFromJsonTest() + template + WrapperHandFromJsonTest::~WrapperHandFromJsonTest() { try { @@ -114,13 +115,14 @@ namespace op } } - template - void WrapperHandFromJsonTest::configure(const WrapperStructPose& wrapperStructPose, - const WrapperStructHand& wrapperStructHand, - const std::shared_ptr& producerSharedPtr, - const std::string& handGroundTruth, - const std::string& writeJson, - const DisplayMode displayMode) + template + void WrapperHandFromJsonTest::configure( + const WrapperStructPose& wrapperStructPose, + const WrapperStructHand& wrapperStructHand, + const std::shared_ptr& producerSharedPtr, + const std::string& handGroundTruth, + const std::string& writeJson, + const DisplayMode displayMode) { try { @@ -172,8 +174,8 @@ namespace op } // Producer - const auto datumProducer = std::make_shared>(producerSharedPtr); - wDatumProducer = std::make_shared>(datumProducer); + const auto datumProducer = std::make_shared>(producerSharedPtr); + wDatumProducer = std::make_shared>(datumProducer); // Get input scales and sizes const auto scaleAndSizeExtractor = std::make_shared( @@ -269,8 +271,8 @@ namespace op } } - template - void WrapperHandFromJsonTest::exec() + template + void WrapperHandFromJsonTest::exec() { try { @@ -283,8 +285,8 @@ namespace op } } - template - void WrapperHandFromJsonTest::reset() + template + void WrapperHandFromJsonTest::reset() { try { @@ -305,8 +307,8 @@ namespace op } } - template - void WrapperHandFromJsonTest::configureThreadManager() + template + void WrapperHandFromJsonTest::configureThreadManager() { try { @@ -365,8 +367,8 @@ namespace op } } - template - std::vector WrapperHandFromJsonTest::mergeWorkers(const std::vector& workersA, const std::vector& workersB) + template + std::vector WrapperHandFromJsonTest::mergeWorkers(const std::vector& workersA, const std::vector& workersB) { try { diff --git a/examples/tutorial_add_module/1_custom_post_processing.cpp b/examples/tutorial_add_module/1_custom_post_processing.cpp index 65c2d2f1..c428c941 100644 --- a/examples/tutorial_add_module/1_custom_post_processing.cpp +++ b/examples/tutorial_add_module/1_custom_post_processing.cpp @@ -78,7 +78,7 @@ int tutorialAddModule1() // OpenPose wrapper op::log("Configuring OpenPose...", op::Priority::High); - op::WrapperT> opWrapperT; + op::WrapperT opWrapperT; // Pose configuration (use WrapperStructPose{} for default and recommended configuration) const op::WrapperStructPose wrapperStructPose{ !FLAGS_body_disable, netInputSize, outputSize, keypointScale, FLAGS_num_gpu, FLAGS_num_gpu_start, @@ -124,7 +124,7 @@ int tutorialAddModule1() // Custom post-processing auto userPostProcessing = std::make_shared(/* Your class arguments here */); - auto wUserPostProcessing = std::make_shared>>>( + auto wUserPostProcessing = std::make_shared>>>>( userPostProcessing ); // Add custom processing diff --git a/examples/tutorial_add_module/wUserPostProcessing.hpp b/examples/tutorial_add_module/wUserPostProcessing.hpp index 79a62d45..9c32e792 100644 --- a/examples/tutorial_add_module/wUserPostProcessing.hpp +++ b/examples/tutorial_add_module/wUserPostProcessing.hpp @@ -58,7 +58,7 @@ namespace op for (auto& datum : *tDatums) // THIS IS THE ONLY LINE THAT THE USER MUST MODIFY ON THIS HPP FILE, by using the proper function // and datum elements - spUserPostProcessing->doSomething(datum.cvOutputData, datum.cvOutputData); + spUserPostProcessing->doSomething(datum->cvOutputData, datum->cvOutputData); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/examples/tutorial_api_cpp/1_body_from_image.cpp b/examples/tutorial_api_cpp/1_body_from_image.cpp index d74ae171..2651f369 100644 --- a/examples/tutorial_api_cpp/1_body_from_image.cpp +++ b/examples/tutorial_api_cpp/1_body_from_image.cpp @@ -13,7 +13,7 @@ DEFINE_string(image_path, "examples/media/COCO_val2014_000000000192.jpg", "Process an image. Read all standard formats (jpg, png, bmp, etc.)."); // This worker will just read and return all the jpg files in a directory -void display(const std::shared_ptr>& datumsPtr) +void display(const std::shared_ptr>>& datumsPtr) { // User's displaying/saving/other processing here // datum.cvOutputData: rendered frame with pose or heatmaps @@ -21,20 +21,20 @@ void display(const std::shared_ptr>& datumsPtr) if (datumsPtr != nullptr && !datumsPtr->empty()) { // Display image - cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData); + cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData); cv::waitKey(0); } else op::log("Nullptr or empty datumsPtr found.", op::Priority::High); } -void printKeypoints(const std::shared_ptr>& datumsPtr) +void printKeypoints(const std::shared_ptr>>& datumsPtr) { // Example: How to use the pose keypoints if (datumsPtr != nullptr && !datumsPtr->empty()) { // Alternative 1 - op::log("Body keypoints: " + datumsPtr->at(0).poseKeypoints.toString()); + op::log("Body keypoints: " + datumsPtr->at(0)->poseKeypoints.toString()); // // Alternative 2 // op::log(datumsPtr->at(0).poseKeypoints); diff --git a/examples/tutorial_api_cpp/2_whole_body_from_image.cpp b/examples/tutorial_api_cpp/2_whole_body_from_image.cpp index 61746322..df2e9ce8 100644 --- a/examples/tutorial_api_cpp/2_whole_body_from_image.cpp +++ b/examples/tutorial_api_cpp/2_whole_body_from_image.cpp @@ -13,7 +13,7 @@ DEFINE_string(image_path, "examples/media/COCO_val2014_000000000241.jpg", "Process an image. Read all standard formats (jpg, png, bmp, etc.)."); // This worker will just read and return all the jpg files in a directory -void display(const std::shared_ptr>& datumsPtr) +void display(const std::shared_ptr>>& datumsPtr) { // User's displaying/saving/other processing here // datum.cvOutputData: rendered frame with pose or heatmaps @@ -21,22 +21,22 @@ void display(const std::shared_ptr>& datumsPtr) if (datumsPtr != nullptr && !datumsPtr->empty()) { // Display image - cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData); + cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData); cv::waitKey(0); } else op::log("Nullptr or empty datumsPtr found.", op::Priority::High); } -void printKeypoints(const std::shared_ptr>& datumsPtr) +void printKeypoints(const std::shared_ptr>>& datumsPtr) { // Example: How to use the pose keypoints if (datumsPtr != nullptr && !datumsPtr->empty()) { - op::log("Body keypoints: " + datumsPtr->at(0).poseKeypoints.toString()); - op::log("Face keypoints: " + datumsPtr->at(0).faceKeypoints.toString()); - op::log("Left hand keypoints: " + datumsPtr->at(0).handKeypoints[0].toString()); - op::log("Right hand keypoints: " + datumsPtr->at(0).handKeypoints[1].toString()); + op::log("Body keypoints: " + datumsPtr->at(0)->poseKeypoints.toString()); + op::log("Face keypoints: " + datumsPtr->at(0)->faceKeypoints.toString()); + op::log("Left hand keypoints: " + datumsPtr->at(0)->handKeypoints[0].toString()); + op::log("Right hand keypoints: " + datumsPtr->at(0)->handKeypoints[1].toString()); } else op::log("Nullptr or empty datumsPtr found.", op::Priority::High); diff --git a/examples/tutorial_api_cpp/3_keypoints_from_image_configurable.cpp b/examples/tutorial_api_cpp/3_keypoints_from_image_configurable.cpp index c2fe8810..c1285fbc 100644 --- a/examples/tutorial_api_cpp/3_keypoints_from_image_configurable.cpp +++ b/examples/tutorial_api_cpp/3_keypoints_from_image_configurable.cpp @@ -15,7 +15,7 @@ DEFINE_string(image_path, "examples/media/COCO_val2014_000000000294.jpg", "Process an image. Read all standard formats (jpg, png, bmp, etc.)."); // This worker will just read and return all the jpg files in a directory -void display(const std::shared_ptr>& datumsPtr) +void display(const std::shared_ptr>>& datumsPtr) { // User's displaying/saving/other processing here // datum.cvOutputData: rendered frame with pose or heatmaps @@ -23,22 +23,22 @@ void display(const std::shared_ptr>& datumsPtr) if (datumsPtr != nullptr && !datumsPtr->empty()) { // Display image - cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData); + cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData); cv::waitKey(0); } else op::log("Nullptr or empty datumsPtr found.", op::Priority::High); } -void printKeypoints(const std::shared_ptr>& datumsPtr) +void printKeypoints(const std::shared_ptr>>& datumsPtr) { // Example: How to use the pose keypoints if (datumsPtr != nullptr && !datumsPtr->empty()) { - op::log("Body keypoints: " + datumsPtr->at(0).poseKeypoints.toString()); - op::log("Face keypoints: " + datumsPtr->at(0).faceKeypoints.toString()); - op::log("Left hand keypoints: " + datumsPtr->at(0).handKeypoints[0].toString()); - op::log("Right hand keypoints: " + datumsPtr->at(0).handKeypoints[1].toString()); + op::log("Body keypoints: " + datumsPtr->at(0)->poseKeypoints.toString()); + op::log("Face keypoints: " + datumsPtr->at(0)->faceKeypoints.toString()); + op::log("Left hand keypoints: " + datumsPtr->at(0)->handKeypoints[0].toString()); + op::log("Right hand keypoints: " + datumsPtr->at(0)->handKeypoints[1].toString()); } else op::log("Nullptr or empty datumsPtr found.", op::Priority::High); diff --git a/examples/tutorial_api_cpp/4_asynchronous_loop_custom_input_and_output.cpp b/examples/tutorial_api_cpp/4_asynchronous_loop_custom_input_and_output.cpp index e0102024..5b27be8b 100644 --- a/examples/tutorial_api_cpp/4_asynchronous_loop_custom_input_and_output.cpp +++ b/examples/tutorial_api_cpp/4_asynchronous_loop_custom_input_and_output.cpp @@ -29,7 +29,8 @@ DEFINE_string(image_dir, "examples/media/", // If the user needs his own variables, he can inherit the op::Datum struct and add them in there. // UserDatum can be directly used by the OpenPose wrapper because it inherits from op::Datum, just define -// WrapperT> instead of Wrapper (or equivalently WrapperT>) +// WrapperT>> instead of Wrapper +// (or equivalently WrapperT>>) struct UserDatum : public op::Datum { bool boolThatUserNeedsForSomeReason; @@ -58,7 +59,7 @@ public: op::error("No images found on: " + directoryPath, __LINE__, __FUNCTION__, __FILE__); } - std::shared_ptr> createDatum() + std::shared_ptr>> createDatum() { // Close program when empty frame if (mClosed || mImageFiles.size() <= mCounter) @@ -72,15 +73,15 @@ public: else // if (!mClosed) { // Create new datum - auto datumsPtr = std::make_shared>(); + auto datumsPtr = std::make_shared>>(); datumsPtr->emplace_back(); - auto& datum = datumsPtr->at(0); + auto& datumPtr = datumsPtr->at(0); // Fill datum - datum.cvInputData = cv::imread(mImageFiles.at(mCounter++)); + datumPtr->cvInputData = cv::imread(mImageFiles.at(mCounter++)); // If empty frame -> return nullptr - if (datum.cvInputData.empty()) + if (datumPtr->cvInputData.empty()) { op::log("Empty frame detected on path: " + mImageFiles.at(mCounter-1) + ". Closing program.", op::Priority::High); @@ -107,15 +108,15 @@ private: class UserOutputClass { public: - bool display(const std::shared_ptr>& datumsPtr) + bool display(const std::shared_ptr>>& datumsPtr) { // User's displaying/saving/other processing here - // datum.cvOutputData: rendered frame with pose or heatmaps - // datum.poseKeypoints: Array with the estimated pose + // datumPtr->cvOutputData: rendered frame with pose or heatmaps + // datumPtr->poseKeypoints: Array with the estimated pose char key = ' '; if (datumsPtr != nullptr && !datumsPtr->empty()) { - cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData); + cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData); // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) key = (char)cv::waitKey(1); } @@ -123,14 +124,14 @@ public: op::log("Nullptr or empty datumsPtr found.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); return (key == 27); } - void printKeypoints(const std::shared_ptr>& datumsPtr) + void printKeypoints(const std::shared_ptr>>& datumsPtr) { // Example: How to use the pose keypoints if (datumsPtr != nullptr && !datumsPtr->empty()) { op::log("\nKeypoints:"); // Accesing each element of the keypoints - const auto& poseKeypoints = datumsPtr->at(0).poseKeypoints; + const auto& poseKeypoints = datumsPtr->at(0)->poseKeypoints; op::log("Person pose keypoints:"); for (auto person = 0 ; person < poseKeypoints.getSize(0) ; person++) { @@ -145,22 +146,22 @@ public: } op::log(" "); // Alternative: just getting std::string equivalent - op::log("Face keypoints: " + datumsPtr->at(0).faceKeypoints.toString()); - op::log("Left hand keypoints: " + datumsPtr->at(0).handKeypoints[0].toString()); - op::log("Right hand keypoints: " + datumsPtr->at(0).handKeypoints[1].toString()); + op::log("Face keypoints: " + datumsPtr->at(0)->faceKeypoints.toString()); + op::log("Left hand keypoints: " + datumsPtr->at(0)->handKeypoints[0].toString()); + op::log("Right hand keypoints: " + datumsPtr->at(0)->handKeypoints[1].toString()); // Heatmaps - const auto& poseHeatMaps = datumsPtr->at(0).poseHeatMaps; + const auto& poseHeatMaps = datumsPtr->at(0)->poseHeatMaps; if (!poseHeatMaps.empty()) { op::log("Pose heatmaps size: [" + std::to_string(poseHeatMaps.getSize(0)) + ", " + std::to_string(poseHeatMaps.getSize(1)) + ", " + std::to_string(poseHeatMaps.getSize(2)) + "]"); - const auto& faceHeatMaps = datumsPtr->at(0).faceHeatMaps; + const auto& faceHeatMaps = datumsPtr->at(0)->faceHeatMaps; op::log("Face heatmaps size: [" + std::to_string(faceHeatMaps.getSize(0)) + ", " + std::to_string(faceHeatMaps.getSize(1)) + ", " + std::to_string(faceHeatMaps.getSize(2)) + ", " + std::to_string(faceHeatMaps.getSize(3)) + "]"); - const auto& handHeatMaps = datumsPtr->at(0).handHeatMaps; + const auto& handHeatMaps = datumsPtr->at(0)->handHeatMaps; op::log("Left hand heatmaps size: [" + std::to_string(handHeatMaps[0].getSize(0)) + ", " + std::to_string(handHeatMaps[0].getSize(1)) + ", " + std::to_string(handHeatMaps[0].getSize(2)) + ", " @@ -217,7 +218,7 @@ int tutorialApiCpp4() // Configuring OpenPose op::log("Configuring OpenPose...", op::Priority::High); - op::WrapperT> opWrapperT{op::ThreadManagerMode::Asynchronous}; + op::WrapperT opWrapperT{op::ThreadManagerMode::Asynchronous}; // Pose configuration (use WrapperStructPose{} for default and recommended configuration) const op::WrapperStructPose wrapperStructPose{ !FLAGS_body_disable, netInputSize, outputSize, keypointScale, FLAGS_num_gpu, FLAGS_num_gpu_start, @@ -271,7 +272,7 @@ int tutorialApiCpp4() { auto successfullyEmplaced = opWrapperT.waitAndEmplace(datumToProcess); // Pop frame - std::shared_ptr> datumProcessed; + std::shared_ptr>> datumProcessed; if (successfullyEmplaced && opWrapperT.waitAndPop(datumProcessed)) { userWantsToExit = userOutputClass.display(datumProcessed); diff --git a/examples/tutorial_api_cpp/5_asynchronous_loop_custom_output.cpp b/examples/tutorial_api_cpp/5_asynchronous_loop_custom_output.cpp index 104b6cb9..34636217 100644 --- a/examples/tutorial_api_cpp/5_asynchronous_loop_custom_output.cpp +++ b/examples/tutorial_api_cpp/5_asynchronous_loop_custom_output.cpp @@ -23,7 +23,8 @@ // If the user needs his own variables, he can inherit the op::Datum struct and add them in there. // UserDatum can be directly used by the OpenPose wrapper because it inherits from op::Datum, just define -// WrapperT> instead of Wrapper (or equivalently WrapperT>) +// WrapperT>> instead of Wrapper +// (or equivalently WrapperT>>) struct UserDatum : public op::Datum { bool boolThatUserNeedsForSomeReason; @@ -41,15 +42,15 @@ struct UserDatum : public op::Datum class UserOutputClass { public: - bool display(const std::shared_ptr>& datumsPtr) + bool display(const std::shared_ptr>>& datumsPtr) { // User's displaying/saving/other processing here - // datum.cvOutputData: rendered frame with pose or heatmaps - // datum.poseKeypoints: Array with the estimated pose + // datumPtr->cvOutputData: rendered frame with pose or heatmaps + // datumPtr->poseKeypoints: Array with the estimated pose char key = ' '; if (datumsPtr != nullptr && !datumsPtr->empty()) { - cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData); + cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData); // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) key = (char)cv::waitKey(1); } @@ -57,14 +58,14 @@ public: op::log("Nullptr or empty datumsPtr found.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); return (key == 27); } - void printKeypoints(const std::shared_ptr>& datumsPtr) + void printKeypoints(const std::shared_ptr>>& datumsPtr) { // Example: How to use the pose keypoints if (datumsPtr != nullptr && !datumsPtr->empty()) { op::log("\nKeypoints:"); // Accesing each element of the keypoints - const auto& poseKeypoints = datumsPtr->at(0).poseKeypoints; + const auto& poseKeypoints = datumsPtr->at(0)->poseKeypoints; op::log("Person pose keypoints:"); for (auto person = 0 ; person < poseKeypoints.getSize(0) ; person++) { @@ -81,22 +82,22 @@ public: } op::log(" "); // Alternative: just getting std::string equivalent - op::log("Face keypoints: " + datumsPtr->at(0).faceKeypoints.toString()); - op::log("Left hand keypoints: " + datumsPtr->at(0).handKeypoints[0].toString()); - op::log("Right hand keypoints: " + datumsPtr->at(0).handKeypoints[1].toString()); + op::log("Face keypoints: " + datumsPtr->at(0)->faceKeypoints.toString()); + op::log("Left hand keypoints: " + datumsPtr->at(0)->handKeypoints[0].toString()); + op::log("Right hand keypoints: " + datumsPtr->at(0)->handKeypoints[1].toString()); // Heatmaps - const auto& poseHeatMaps = datumsPtr->at(0).poseHeatMaps; + const auto& poseHeatMaps = datumsPtr->at(0)->poseHeatMaps; if (!poseHeatMaps.empty()) { op::log("Pose heatmaps size: [" + std::to_string(poseHeatMaps.getSize(0)) + ", " + std::to_string(poseHeatMaps.getSize(1)) + ", " + std::to_string(poseHeatMaps.getSize(2)) + "]"); - const auto& faceHeatMaps = datumsPtr->at(0).faceHeatMaps; + const auto& faceHeatMaps = datumsPtr->at(0)->faceHeatMaps; op::log("Face heatmaps size: [" + std::to_string(faceHeatMaps.getSize(0)) + ", " + std::to_string(faceHeatMaps.getSize(1)) + ", " + std::to_string(faceHeatMaps.getSize(2)) + ", " + std::to_string(faceHeatMaps.getSize(3)) + "]"); - const auto& handHeatMaps = datumsPtr->at(0).handHeatMaps; + const auto& handHeatMaps = datumsPtr->at(0)->handHeatMaps; op::log("Left hand heatmaps size: [" + std::to_string(handHeatMaps[0].getSize(0)) + ", " + std::to_string(handHeatMaps[0].getSize(1)) + ", " + std::to_string(handHeatMaps[0].getSize(2)) + ", " @@ -160,7 +161,7 @@ int tutorialApiCpp5() // Configuring OpenPose op::log("Configuring OpenPose...", op::Priority::High); - op::WrapperT> opWrapperT{op::ThreadManagerMode::AsynchronousOut}; + op::WrapperT opWrapperT{op::ThreadManagerMode::AsynchronousOut}; // Pose configuration (use WrapperStructPose{} for default and recommended configuration) const op::WrapperStructPose wrapperStructPose{ !FLAGS_body_disable, netInputSize, outputSize, keypointScale, FLAGS_num_gpu, FLAGS_num_gpu_start, @@ -214,7 +215,7 @@ int tutorialApiCpp5() while (!userWantsToExit) { // Pop frame - std::shared_ptr> datumProcessed; + std::shared_ptr>> datumProcessed; if (opWrapperT.waitAndPop(datumProcessed)) { userWantsToExit = userOutputClass.display(datumProcessed);; diff --git a/examples/tutorial_api_cpp/6_synchronous_custom_postprocessing.cpp b/examples/tutorial_api_cpp/6_synchronous_custom_postprocessing.cpp index 143cfe9d..5b235ab5 100644 --- a/examples/tutorial_api_cpp/6_synchronous_custom_postprocessing.cpp +++ b/examples/tutorial_api_cpp/6_synchronous_custom_postprocessing.cpp @@ -23,7 +23,8 @@ // If the user needs his own variables, he can inherit the op::Datum struct and add them in there. // UserDatum can be directly used by the OpenPose wrapper because it inherits from op::Datum, just define -// WrapperT> instead of Wrapper (or equivalently WrapperT>) +// WrapperT>> instead of Wrapper +// (or equivalently WrapperT>>) struct UserDatum : public op::Datum { bool boolThatUserNeedsForSomeReason; @@ -38,7 +39,7 @@ struct UserDatum : public op::Datum // in this case we assume a std::shared_ptr of a std::vector of UserDatum // This worker will just invert the image -class WUserPostProcessing : public op::Worker>> +class WUserPostProcessing : public op::Worker>>> { public: WUserPostProcessing() @@ -48,16 +49,16 @@ public: void initializationOnThread() {} - void work(std::shared_ptr>& datumsPtr) + void work(std::shared_ptr>>& datumsPtr) { // User's post-processing (after OpenPose processing & before OpenPose outputs) here - // datum.cvOutputData: rendered frame with pose or heatmaps - // datum.poseKeypoints: Array with the estimated pose + // datumPtr->cvOutputData: rendered frame with pose or heatmaps + // datumPtr->poseKeypoints: Array with the estimated pose try { if (datumsPtr != nullptr && !datumsPtr->empty()) - for (auto& datum : *datumsPtr) - cv::bitwise_not(datum.cvOutputData, datum.cvOutputData); + for (auto& datumPtr : *datumsPtr) + cv::bitwise_not(datumPtr->cvOutputData, datumPtr->cvOutputData); } catch (const std::exception& e) { @@ -120,7 +121,7 @@ int tutorialApiCpp6() // OpenPose wrapper op::log("Configuring OpenPose...", op::Priority::High); - op::WrapperT> opWrapperT; + op::WrapperT opWrapperT; // Initializing the user custom classes // Processing diff --git a/examples/tutorial_api_cpp/7_synchronous_custom_input.cpp b/examples/tutorial_api_cpp/7_synchronous_custom_input.cpp index 8e61c20e..0e88a28a 100644 --- a/examples/tutorial_api_cpp/7_synchronous_custom_input.cpp +++ b/examples/tutorial_api_cpp/7_synchronous_custom_input.cpp @@ -29,7 +29,8 @@ DEFINE_string(image_dir, "examples/media/", // If the user needs his own variables, he can inherit the op::Datum struct and add them in there. // UserDatum can be directly used by the OpenPose wrapper because it inherits from op::Datum, just define -// WrapperT> instead of Wrapper (or equivalently WrapperT>) +// WrapperT>> instead of Wrapper +// (or equivalently WrapperT>>) struct UserDatum : public op::Datum { bool boolThatUserNeedsForSomeReason; @@ -44,7 +45,7 @@ struct UserDatum : public op::Datum // in this case we assume a std::shared_ptr of a std::vector of UserDatum // This worker will just read and return all the jpg files in a directory -class WUserInput : public op::WorkerProducer>> +class WUserInput : public op::WorkerProducer>>> { public: WUserInput(const std::string& directoryPath) : @@ -59,7 +60,7 @@ public: void initializationOnThread() {} - std::shared_ptr> workProducer() + std::shared_ptr>> workProducer() { try { @@ -76,15 +77,15 @@ public: else { // Create new datum - auto datumsPtr = std::make_shared>(); + auto datumsPtr = std::make_shared>>(); datumsPtr->emplace_back(); - auto& datum = datumsPtr->at(0); + auto& datumPtr = datumsPtr->at(0); // Fill datum - datum.cvInputData = cv::imread(mImageFiles.at(mCounter++)); + datumPtr->cvInputData = cv::imread(mImageFiles.at(mCounter++)); // If empty frame -> return nullptr - if (datum.cvInputData.empty()) + if (datumPtr->cvInputData.empty()) { op::log("Empty frame detected on path: " + mImageFiles.at(mCounter-1) + ". Closing program.", op::Priority::High); @@ -155,7 +156,7 @@ int tutorialApiCpp7() // OpenPose wrapper op::log("Configuring OpenPose...", op::Priority::High); - op::WrapperT> opWrapperT; + op::WrapperT opWrapperT; // Initializing the user custom classes // Frames producer (e.g., video, webcam, ...) diff --git a/examples/tutorial_api_cpp/8_synchronous_custom_output.cpp b/examples/tutorial_api_cpp/8_synchronous_custom_output.cpp index f4bffa9d..40afd846 100644 --- a/examples/tutorial_api_cpp/8_synchronous_custom_output.cpp +++ b/examples/tutorial_api_cpp/8_synchronous_custom_output.cpp @@ -24,7 +24,8 @@ // If the user needs his own variables, he can inherit the op::Datum struct and add them in there. // UserDatum can be directly used by the OpenPose wrapper because it inherits from op::Datum, just define -// WrapperT> instead of Wrapper (or equivalently WrapperT>) +// WrapperT>> instead of Wrapper +// (or equivalently WrapperT>>) struct UserDatum : public op::Datum { bool boolThatUserNeedsForSomeReason; @@ -39,24 +40,24 @@ struct UserDatum : public op::Datum // in this case we assume a std::shared_ptr of a std::vector of UserDatum // This worker will just read and return all the jpg files in a directory -class WUserOutput : public op::WorkerConsumer>> +class WUserOutput : public op::WorkerConsumer>>> { public: void initializationOnThread() {} - void workConsumer(const std::shared_ptr>& datumsPtr) + void workConsumer(const std::shared_ptr>>& datumsPtr) { try { // User's displaying/saving/other processing here - // datum.cvOutputData: rendered frame with pose or heatmaps - // datum.poseKeypoints: Array with the estimated pose + // datumPtr->cvOutputData: rendered frame with pose or heatmaps + // datumPtr->poseKeypoints: Array with the estimated pose if (datumsPtr != nullptr && !datumsPtr->empty()) { // Show in command line the resulting pose keypoints for body, face and hands op::log("\nKeypoints:"); // Accesing each element of the keypoints - const auto& poseKeypoints = datumsPtr->at(0).poseKeypoints; + const auto& poseKeypoints = datumsPtr->at(0)->poseKeypoints; op::log("Person pose keypoints:"); for (auto person = 0 ; person < poseKeypoints.getSize(0) ; person++) { @@ -73,22 +74,22 @@ public: } op::log(" "); // Alternative: just getting std::string equivalent - op::log("Face keypoints: " + datumsPtr->at(0).faceKeypoints.toString()); - op::log("Left hand keypoints: " + datumsPtr->at(0).handKeypoints[0].toString()); - op::log("Right hand keypoints: " + datumsPtr->at(0).handKeypoints[1].toString()); + op::log("Face keypoints: " + datumsPtr->at(0)->faceKeypoints.toString()); + op::log("Left hand keypoints: " + datumsPtr->at(0)->handKeypoints[0].toString()); + op::log("Right hand keypoints: " + datumsPtr->at(0)->handKeypoints[1].toString()); // Heatmaps - const auto& poseHeatMaps = datumsPtr->at(0).poseHeatMaps; + const auto& poseHeatMaps = datumsPtr->at(0)->poseHeatMaps; if (!poseHeatMaps.empty()) { op::log("Pose heatmaps size: [" + std::to_string(poseHeatMaps.getSize(0)) + ", " + std::to_string(poseHeatMaps.getSize(1)) + ", " + std::to_string(poseHeatMaps.getSize(2)) + "]"); - const auto& faceHeatMaps = datumsPtr->at(0).faceHeatMaps; + const auto& faceHeatMaps = datumsPtr->at(0)->faceHeatMaps; op::log("Face heatmaps size: [" + std::to_string(faceHeatMaps.getSize(0)) + ", " + std::to_string(faceHeatMaps.getSize(1)) + ", " + std::to_string(faceHeatMaps.getSize(2)) + ", " + std::to_string(faceHeatMaps.getSize(3)) + "]"); - const auto& handHeatMaps = datumsPtr->at(0).handHeatMaps; + const auto& handHeatMaps = datumsPtr->at(0)->handHeatMaps; op::log("Left hand heatmaps size: [" + std::to_string(handHeatMaps[0].getSize(0)) + ", " + std::to_string(handHeatMaps[0].getSize(1)) + ", " + std::to_string(handHeatMaps[0].getSize(2)) + ", " @@ -100,7 +101,7 @@ public: } // Display rendered output image - cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData); + cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData); // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) const char key = (char)cv::waitKey(1); if (key == 27) @@ -168,7 +169,7 @@ int tutorialApiCpp8() // OpenPose wrapper op::log("Configuring OpenPose...", op::Priority::High); - op::WrapperT> opWrapperT; + op::WrapperT opWrapperT; // Initializing the user custom classes // GUI (Display) diff --git a/examples/tutorial_api_cpp/9_synchronous_custom_all.cpp b/examples/tutorial_api_cpp/9_synchronous_custom_all.cpp index 291ca08b..f40b993f 100644 --- a/examples/tutorial_api_cpp/9_synchronous_custom_all.cpp +++ b/examples/tutorial_api_cpp/9_synchronous_custom_all.cpp @@ -29,7 +29,8 @@ DEFINE_string(image_dir, "examples/media/", // If the user needs his own variables, he can inherit the op::Datum struct and add them in there. // UserDatum can be directly used by the OpenPose wrapper because it inherits from op::Datum, just define -// WrapperT> instead of Wrapper (or equivalently WrapperT>) +// WrapperT>> instead of Wrapper +// (or equivalently WrapperT>>) struct UserDatum : public op::Datum { bool boolThatUserNeedsForSomeReason; @@ -44,7 +45,7 @@ struct UserDatum : public op::Datum // in this case we assume a std::shared_ptr of a std::vector of UserDatum // This worker will just read and return all the jpg files in a directory -class WUserInput : public op::WorkerProducer>> +class WUserInput : public op::WorkerProducer>>> { public: WUserInput(const std::string& directoryPath) : @@ -59,7 +60,7 @@ public: void initializationOnThread() {} - std::shared_ptr> workProducer() + std::shared_ptr>> workProducer() { try { @@ -76,15 +77,15 @@ public: else { // Create new datum - auto datumsPtr = std::make_shared>(); + auto datumsPtr = std::make_shared>>(); datumsPtr->emplace_back(); - auto& datum = datumsPtr->at(0); + auto& datumPtr = datumsPtr->at(0); // Fill datum - datum.cvInputData = cv::imread(mImageFiles.at(mCounter++)); + datumPtr->cvInputData = cv::imread(mImageFiles.at(mCounter++)); // If empty frame -> return nullptr - if (datum.cvInputData.empty()) + if (datumPtr->cvInputData.empty()) { op::log("Empty frame detected on path: " + mImageFiles.at(mCounter-1) + ". Closing program.", op::Priority::High); @@ -109,7 +110,7 @@ private: }; // This worker will just invert the image -class WUserPostProcessing : public op::Worker>> +class WUserPostProcessing : public op::Worker>>> { public: WUserPostProcessing() @@ -119,16 +120,16 @@ public: void initializationOnThread() {} - void work(std::shared_ptr>& datumsPtr) + void work(std::shared_ptr>>& datumsPtr) { // User's post-processing (after OpenPose processing & before OpenPose outputs) here - // datum.cvOutputData: rendered frame with pose or heatmaps - // datum.poseKeypoints: Array with the estimated pose + // datumPtr->cvOutputData: rendered frame with pose or heatmaps + // datumPtr->poseKeypoints: Array with the estimated pose try { if (datumsPtr != nullptr && !datumsPtr->empty()) - for (auto& datum : *datumsPtr) - cv::bitwise_not(datum.cvOutputData, datum.cvOutputData); + for (auto& datumPtr : *datumsPtr) + cv::bitwise_not(datumPtr->cvOutputData, datumPtr->cvOutputData); } catch (const std::exception& e) { @@ -139,24 +140,24 @@ public: }; // This worker will just read and return all the jpg files in a directory -class WUserOutput : public op::WorkerConsumer>> +class WUserOutput : public op::WorkerConsumer>>> { public: void initializationOnThread() {} - void workConsumer(const std::shared_ptr>& datumsPtr) + void workConsumer(const std::shared_ptr>>& datumsPtr) { try { // User's displaying/saving/other processing here - // datum.cvOutputData: rendered frame with pose or heatmaps - // datum.poseKeypoints: Array with the estimated pose + // datumPtr->cvOutputData: rendered frame with pose or heatmaps + // datumPtr->poseKeypoints: Array with the estimated pose if (datumsPtr != nullptr && !datumsPtr->empty()) { // Show in command line the resulting pose keypoints for body, face and hands op::log("\nKeypoints:"); // Accesing each element of the keypoints - const auto& poseKeypoints = datumsPtr->at(0).poseKeypoints; + const auto& poseKeypoints = datumsPtr->at(0)->poseKeypoints; op::log("Person pose keypoints:"); for (auto person = 0 ; person < poseKeypoints.getSize(0) ; person++) { @@ -173,22 +174,22 @@ public: } op::log(" "); // Alternative: just getting std::string equivalent - op::log("Face keypoints: " + datumsPtr->at(0).faceKeypoints.toString()); - op::log("Left hand keypoints: " + datumsPtr->at(0).handKeypoints[0].toString()); - op::log("Right hand keypoints: " + datumsPtr->at(0).handKeypoints[1].toString()); + op::log("Face keypoints: " + datumsPtr->at(0)->faceKeypoints.toString()); + op::log("Left hand keypoints: " + datumsPtr->at(0)->handKeypoints[0].toString()); + op::log("Right hand keypoints: " + datumsPtr->at(0)->handKeypoints[1].toString()); // Heatmaps - const auto& poseHeatMaps = datumsPtr->at(0).poseHeatMaps; + const auto& poseHeatMaps = datumsPtr->at(0)->poseHeatMaps; if (!poseHeatMaps.empty()) { op::log("Pose heatmaps size: [" + std::to_string(poseHeatMaps.getSize(0)) + ", " + std::to_string(poseHeatMaps.getSize(1)) + ", " + std::to_string(poseHeatMaps.getSize(2)) + "]"); - const auto& faceHeatMaps = datumsPtr->at(0).faceHeatMaps; + const auto& faceHeatMaps = datumsPtr->at(0)->faceHeatMaps; op::log("Face heatmaps size: [" + std::to_string(faceHeatMaps.getSize(0)) + ", " + std::to_string(faceHeatMaps.getSize(1)) + ", " + std::to_string(faceHeatMaps.getSize(2)) + ", " + std::to_string(faceHeatMaps.getSize(3)) + "]"); - const auto& handHeatMaps = datumsPtr->at(0).handHeatMaps; + const auto& handHeatMaps = datumsPtr->at(0)->handHeatMaps; op::log("Left hand heatmaps size: [" + std::to_string(handHeatMaps[0].getSize(0)) + ", " + std::to_string(handHeatMaps[0].getSize(1)) + ", " + std::to_string(handHeatMaps[0].getSize(2)) + ", " @@ -200,7 +201,7 @@ public: } // Display rendered output image - cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData); + cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData); // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) const char key = (char)cv::waitKey(1); if (key == 27) @@ -264,7 +265,7 @@ int tutorialApiCpp9() // OpenPose wrapper op::log("Configuring OpenPose...", op::Priority::High); - op::WrapperT> opWrapperT; + op::WrapperT opWrapperT; // Add custom input const auto workerInputOnNewThread = false; opWrapperT.setWorker(op::WorkerType::Input, wUserInput, workerInputOnNewThread); diff --git a/examples/tutorial_developer/thread_1_openpose_read_and_display.cpp b/examples/tutorial_developer/thread_1_openpose_read_and_display.cpp index 9b04abf7..217a49b1 100644 --- a/examples/tutorial_developer/thread_1_openpose_read_and_display.cpp +++ b/examples/tutorial_developer/thread_1_openpose_read_and_display.cpp @@ -99,16 +99,16 @@ int tutorialDeveloperThread1() (int)producerSharedPtr->get(CV_CAP_PROP_FRAME_WIDTH), (int)producerSharedPtr->get(CV_CAP_PROP_FRAME_HEIGHT)}; // Step 4 - Setting thread workers && manager - typedef std::vector TypedefDatumsNoPtr; - typedef std::shared_ptr TypedefDatums; - op::ThreadManager threadManager; + typedef op::Datum TypedefDatum; + typedef std::shared_ptr>> TypedefDatumsSP; + op::ThreadManager threadManager; // Step 5 - Initializing the worker classes // Frames producer (e.g., video, webcam, ...) - auto DatumProducer = std::make_shared>(producerSharedPtr); - auto wDatumProducer = std::make_shared>(DatumProducer); + auto DatumProducer = std::make_shared>(producerSharedPtr); + auto wDatumProducer = std::make_shared>(DatumProducer); // GUI (Display) auto gui = std::make_shared(outputSize, FLAGS_fullscreen, threadManager.getIsRunningSharedPtr()); - auto wGui = std::make_shared>(gui); + auto wGui = std::make_shared>(gui); // ------------------------- CONFIGURING THREADING ------------------------- // In this simple multi-thread example, we will do the following: diff --git a/examples/tutorial_developer/thread_2_user_processing_function.cpp b/examples/tutorial_developer/thread_2_user_processing_function.cpp index 16f7116f..4c810d64 100644 --- a/examples/tutorial_developer/thread_2_user_processing_function.cpp +++ b/examples/tutorial_developer/thread_2_user_processing_function.cpp @@ -64,7 +64,7 @@ DEFINE_bool(fullscreen, false, "Run in full-screen mode // This class can be implemented either as a template or as a simple class given // that the user usually knows which kind of data he will move between the queues, // in this case we assume a std::shared_ptr of a std::vector of op::Datum -class WUserClass : public op::Worker>> +class WUserClass : public op::Worker>>> { public: WUserClass() @@ -74,16 +74,16 @@ public: void initializationOnThread() {} - void work(std::shared_ptr>& datumsPtr) + void work(std::shared_ptr>>& datumsPtr) { try { // User's processing here - // datum.cvInputData: initial cv::Mat obtained from the frames producer (video, webcam, etc.) - // datum.cvOutputData: final cv::Mat to be displayed + // datumPtr->cvInputData: initial cv::Mat obtained from the frames producer (video, webcam, etc.) + // datumPtr->cvOutputData: final cv::Mat to be displayed if (datumsPtr != nullptr) - for (auto& datum : *datumsPtr) - cv::bitwise_not(datum.cvInputData, datum.cvOutputData); + for (auto& datumPtr : *datumsPtr) + cv::bitwise_not(datumPtr->cvInputData, datumPtr->cvOutputData); } catch (const std::exception& e) { @@ -133,18 +133,18 @@ int tutorialDeveloperThread2() (int)producerSharedPtr->get(CV_CAP_PROP_FRAME_WIDTH), (int)producerSharedPtr->get(CV_CAP_PROP_FRAME_HEIGHT)}; // Step 4 - Setting thread workers && manager - typedef std::vector TypedefDatumsNoPtr; - typedef std::shared_ptr TypedefDatums; - op::ThreadManager threadManager; + typedef op::Datum TypedefDatum; + typedef std::shared_ptr>> TypedefDatumsSP; + op::ThreadManager threadManager; // Step 5 - Initializing the worker classes // Frames producer (e.g., video, webcam, ...) - auto DatumProducer = std::make_shared>(producerSharedPtr); - auto wDatumProducer = std::make_shared>(DatumProducer); + auto DatumProducer = std::make_shared>(producerSharedPtr); + auto wDatumProducer = std::make_shared>(DatumProducer); // Specific WUserClass auto wUserClass = std::make_shared(); // GUI (Display) auto gui = std::make_shared(outputSize, FLAGS_fullscreen, threadManager.getIsRunningSharedPtr()); - auto wGui = std::make_shared>(gui); + auto wGui = std::make_shared>(gui); // ------------------------- CONFIGURING THREADING ------------------------- // In this simple multi-thread example, we will do the following: diff --git a/examples/tutorial_developer/thread_3_user_input_processing_and_output.cpp b/examples/tutorial_developer/thread_3_user_input_processing_and_output.cpp index 0e148adc..8b91fd95 100644 --- a/examples/tutorial_developer/thread_3_user_input_processing_and_output.cpp +++ b/examples/tutorial_developer/thread_3_user_input_processing_and_output.cpp @@ -44,7 +44,7 @@ DEFINE_bool(fullscreen, false, "Run in full-screen mode // in this case we assume a std::shared_ptr of a std::vector of op::Datum // This worker will just read and return all the jpg files in a directory -class WUserInput : public op::WorkerProducer>> +class WUserInput : public op::WorkerProducer>>> { public: WUserInput(const std::string& directoryPath) : @@ -59,7 +59,7 @@ public: void initializationOnThread() {} - std::shared_ptr> workProducer() + std::shared_ptr>> workProducer() { try { @@ -76,15 +76,15 @@ public: else { // Create new datum - auto datumsPtr = std::make_shared>(); + auto datumsPtr = std::make_shared>>(); datumsPtr->emplace_back(); - auto& datum = datumsPtr->at(0); + auto& datumPtr = datumsPtr->at(0); // Fill datum - datum.cvInputData = cv::imread(mImageFiles.at(mCounter++)); + datumPtr->cvInputData = cv::imread(mImageFiles.at(mCounter++)); // If empty frame -> return nullptr - if (datum.cvInputData.empty()) + if (datumPtr->cvInputData.empty()) { op::log("Empty frame detected on path: " + mImageFiles.at(mCounter-1) + ". Closing program.", op::Priority::High); @@ -110,7 +110,7 @@ private: }; // This worker will just invert the image -class WUserPostProcessing : public op::Worker>> +class WUserPostProcessing : public op::Worker>>> { public: WUserPostProcessing() @@ -120,16 +120,16 @@ public: void initializationOnThread() {} - void work(std::shared_ptr>& datumsPtr) + void work(std::shared_ptr>>& datumsPtr) { // User's post-processing (after OpenPose processing & before OpenPose outputs) here - // datum.cvOutputData: rendered frame with pose or heatmaps - // datum.poseKeypoints: Array with the estimated pose + // datumPtr->cvOutputData: rendered frame with pose or heatmaps + // datumPtr->poseKeypoints: Array with the estimated pose try { if (datumsPtr != nullptr && !datumsPtr->empty()) - for (auto& datum : *datumsPtr) - cv::bitwise_not(datum.cvInputData, datum.cvOutputData); + for (auto& datumPtr : *datumsPtr) + cv::bitwise_not(datumPtr->cvInputData, datumPtr->cvOutputData); } catch (const std::exception& e) { @@ -141,21 +141,21 @@ public: }; // This worker will just read and return all the jpg files in a directory -class WUserOutput : public op::WorkerConsumer>> +class WUserOutput : public op::WorkerConsumer>>> { public: void initializationOnThread() {} - void workConsumer(const std::shared_ptr>& datumsPtr) + void workConsumer(const std::shared_ptr>>& datumsPtr) { try { // User's displaying/saving/other processing here - // datum.cvOutputData: rendered frame with pose or heatmaps - // datum.poseKeypoints: Array with the estimated pose + // datumPtr->cvOutputData: rendered frame with pose or heatmaps + // datumPtr->poseKeypoints: Array with the estimated pose if (datumsPtr != nullptr && !datumsPtr->empty()) { - cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData); + cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData); // It displays the image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) cv::waitKey(1); } @@ -184,9 +184,9 @@ int openPoseTutorialThread3() __LINE__, __FUNCTION__, __FILE__); op::ConfigureLog::setPriorityThreshold((op::Priority)FLAGS_logging_level); // Step 2 - Setting thread workers && manager - typedef std::shared_ptr> TypedefDatums; - typedef std::shared_ptr> TypedefWorker; - op::ThreadManager threadManager; + typedef std::shared_ptr>> TypedefDatumsSP; + typedef std::shared_ptr> TypedefWorker; + op::ThreadManager threadManager; // Step 3 - Initializing the worker classes // Frames producer (e.g., video, webcam, ...) TypedefWorker wUserInput = std::make_shared(FLAGS_image_dir); diff --git a/examples/tutorial_developer/thread_4_user_input_processing_output_and_datum.cpp b/examples/tutorial_developer/thread_4_user_input_processing_output_and_datum.cpp index 1bce5ba2..23dc91fc 100644 --- a/examples/tutorial_developer/thread_4_user_input_processing_output_and_datum.cpp +++ b/examples/tutorial_developer/thread_4_user_input_processing_output_and_datum.cpp @@ -42,7 +42,8 @@ DEFINE_bool(fullscreen, false, "Run in full-screen mode // If the user needs his own variables, he can inherit the op::Datum struct and add them in there. // UserDatum can be directly used by the OpenPose wrapper because it inherits from op::Datum, just define -// WrapperT> instead of Wrapper (or equivalently WrapperT>) +// WrapperT>> instead of Wrapper +// (or equivalently WrapperT>>) struct UserDatum : public op::Datum { bool boolThatUserNeedsForSomeReason; @@ -57,7 +58,7 @@ struct UserDatum : public op::Datum // in this case we assume a std::shared_ptr of a std::vector of UserDatum // This worker will just read and return all the jpg files in a directory -class WUserInput : public op::WorkerProducer>> +class WUserInput : public op::WorkerProducer>>> { public: WUserInput(const std::string& directoryPath) : @@ -72,7 +73,7 @@ public: void initializationOnThread() {} - std::shared_ptr> workProducer() + std::shared_ptr>> workProducer() { try { @@ -89,15 +90,15 @@ public: else { // Create new datum - auto datumsPtr = std::make_shared>(); + auto datumsPtr = std::make_shared>>(); datumsPtr->emplace_back(); - auto& datum = datumsPtr->at(0); + auto& datumPtr = datumsPtr->at(0); // Fill datum - datum.cvInputData = cv::imread(mImageFiles.at(mCounter++)); + datumPtr->cvInputData = cv::imread(mImageFiles.at(mCounter++)); // If empty frame -> return nullptr - if (datum.cvInputData.empty()) + if (datumPtr->cvInputData.empty()) { op::log("Empty frame detected on path: " + mImageFiles.at(mCounter-1) + ". Closing program.", op::Priority::High); @@ -123,7 +124,7 @@ private: }; // This worker will just invert the image -class WUserPostProcessing : public op::Worker>> +class WUserPostProcessing : public op::Worker>>> { public: WUserPostProcessing() @@ -133,16 +134,16 @@ public: void initializationOnThread() {} - void work(std::shared_ptr>& datumsPtr) + void work(std::shared_ptr>>& datumsPtr) { // User's post-processing (after OpenPose processing & before OpenPose outputs) here - // datum.cvOutputData: rendered frame with pose or heatmaps - // datum.poseKeypoints: Array with the estimated pose + // datumPtr->cvOutputData: rendered frame with pose or heatmaps + // datumPtr->poseKeypoints: Array with the estimated pose try { if (datumsPtr != nullptr && !datumsPtr->empty()) - for (auto& datum : *datumsPtr) - cv::bitwise_not(datum.cvInputData, datum.cvOutputData); + for (auto& datumPtr : *datumsPtr) + cv::bitwise_not(datumPtr->cvInputData, datumPtr->cvOutputData); } catch (const std::exception& e) { @@ -154,21 +155,21 @@ public: }; // This worker will just read and return all the jpg files in a directory -class WUserOutput : public op::WorkerConsumer>> +class WUserOutput : public op::WorkerConsumer>>> { public: void initializationOnThread() {} - void workConsumer(const std::shared_ptr>& datumsPtr) + void workConsumer(const std::shared_ptr>>& datumsPtr) { try { // User's displaying/saving/other processing here - // datum.cvOutputData: rendered frame with pose or heatmaps - // datum.poseKeypoints: Array with the estimated pose + // datumPtr->cvOutputData: rendered frame with pose or heatmaps + // datumPtr->poseKeypoints: Array with the estimated pose if (datumsPtr != nullptr && !datumsPtr->empty()) { - cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData); + cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData); // It displays the image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) cv::waitKey(1); } @@ -197,9 +198,9 @@ int openPoseTutorialThread4() __LINE__, __FUNCTION__, __FILE__); op::ConfigureLog::setPriorityThreshold((op::Priority)FLAGS_logging_level); // Step 2 - Setting thread workers && manager - typedef std::shared_ptr> TypedefDatums; - typedef std::shared_ptr> TypedefWorker; - op::ThreadManager threadManager; + typedef std::shared_ptr>> TypedefDatumsSP; + typedef std::shared_ptr> TypedefWorker; + op::ThreadManager threadManager; // Step 3 - Initializing the worker classes // Frames producer (e.g., video, webcam, ...) TypedefWorker wUserInput = std::make_shared(FLAGS_image_dir); diff --git a/include/openpose/3d/wJointAngleEstimation.hpp b/include/openpose/3d/wJointAngleEstimation.hpp index e41bb342..3cc60d7a 100644 --- a/include/openpose/3d/wJointAngleEstimation.hpp +++ b/include/openpose/3d/wJointAngleEstimation.hpp @@ -71,14 +71,14 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Input - auto& datum = tDatums->at(0); - const auto& poseKeypoints3D = datum.poseKeypoints3D; - const auto& faceKeypoints3D = datum.faceKeypoints3D; - const auto& handKeypoints3D = datum.handKeypoints3D; + auto& tDatumPtr = tDatums->at(0); + const auto& poseKeypoints3D = tDatumPtr->poseKeypoints3D; + const auto& faceKeypoints3D = tDatumPtr->faceKeypoints3D; + const auto& handKeypoints3D = tDatumPtr->handKeypoints3D; // Running Adam model spJointAngleEstimation->adamFastFit( - datum.adamPose, datum.adamTranslation, datum.vtVec, datum.j0Vec, - datum.adamFaceCoeffsExp, poseKeypoints3D, faceKeypoints3D, handKeypoints3D); + tDatumPtr->adamPose, tDatumPtr->adamTranslation, tDatumPtr->vtVec, tDatumPtr->j0Vec, + tDatumPtr->adamFaceCoeffsExp, poseKeypoints3D, faceKeypoints3D, handKeypoints3D); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/3d/wPoseTriangulation.hpp b/include/openpose/3d/wPoseTriangulation.hpp index d2e49bae..f49ac904 100644 --- a/include/openpose/3d/wPoseTriangulation.hpp +++ b/include/openpose/3d/wPoseTriangulation.hpp @@ -76,27 +76,27 @@ namespace op std::vector> leftHandKeypointVector; std::vector> rightHandKeypointVector; std::vector> imageSizes; - for (auto& datumsElement : *tDatums) + for (auto& tDatumPtr : *tDatums) { - poseKeypointVector.emplace_back(datumsElement.poseKeypoints); - faceKeypointVector.emplace_back(datumsElement.faceKeypoints); - leftHandKeypointVector.emplace_back(datumsElement.handKeypoints[0]); - rightHandKeypointVector.emplace_back(datumsElement.handKeypoints[1]); - cameraMatrices.emplace_back(datumsElement.cameraMatrix); - imageSizes.emplace_back(Point{datumsElement.cvInputData.cols, - datumsElement.cvInputData.rows}); + poseKeypointVector.emplace_back(tDatumPtr->poseKeypoints); + faceKeypointVector.emplace_back(tDatumPtr->faceKeypoints); + leftHandKeypointVector.emplace_back(tDatumPtr->handKeypoints[0]); + rightHandKeypointVector.emplace_back(tDatumPtr->handKeypoints[1]); + cameraMatrices.emplace_back(tDatumPtr->cameraMatrix); + imageSizes.emplace_back( + Point{tDatumPtr->cvInputData.cols, tDatumPtr->cvInputData.rows}); } // Pose 3-D reconstruction auto poseKeypoints3Ds = spPoseTriangulation->reconstructArray( {poseKeypointVector, faceKeypointVector, leftHandKeypointVector, rightHandKeypointVector}, cameraMatrices, imageSizes); // Assign to all tDatums - for (auto& datumsElement : *tDatums) + for (auto& tDatumPtr : *tDatums) { - datumsElement.poseKeypoints3D = poseKeypoints3Ds[0]; - datumsElement.faceKeypoints3D = poseKeypoints3Ds[1]; - datumsElement.handKeypoints3D[0] = poseKeypoints3Ds[2]; - datumsElement.handKeypoints3D[1] = poseKeypoints3Ds[3]; + tDatumPtr->poseKeypoints3D = poseKeypoints3Ds[0]; + tDatumPtr->faceKeypoints3D = poseKeypoints3Ds[1]; + tDatumPtr->handKeypoints3D[0] = poseKeypoints3Ds[2]; + tDatumPtr->handKeypoints3D[1] = poseKeypoints3Ds[3]; } // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/core/datum.hpp b/include/openpose/core/datum.hpp index 472f6ab2..0aca8018 100644 --- a/include/openpose/core/datum.hpp +++ b/include/openpose/core/datum.hpp @@ -389,10 +389,11 @@ namespace op }; // Defines for Datum. Added here rather than in `macros.hpp` to avoid circular dependencies - #define DATUM_BASE_NO_PTR std::vector - #define DATUM_BASE std::shared_ptr - #define DEFINE_TEMPLATE_DATUM(templateName) template class OP_API templateName - #define COMPILE_TEMPLATE_DATUM(templateName) extern template class templateName + #define BASE_DATUM Datum + #define BASE_DATUMS std::vector> + #define BASE_DATUMS_SH std::shared_ptr + #define DEFINE_TEMPLATE_DATUM(templateName) template class OP_API templateName + #define COMPILE_TEMPLATE_DATUM(templateName) extern template class templateName } #endif // OPENPOSE_CORE_DATUM_HPP diff --git a/include/openpose/core/wCvMatToOpInput.hpp b/include/openpose/core/wCvMatToOpInput.hpp index c8b7b7be..5a317595 100644 --- a/include/openpose/core/wCvMatToOpInput.hpp +++ b/include/openpose/core/wCvMatToOpInput.hpp @@ -62,10 +62,9 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // cv::Mat -> float* - for (auto& tDatum : *tDatums) - tDatum.inputNetData = spCvMatToOpInput->createArray(tDatum.cvInputData, - tDatum.scaleInputToNetInputs, - tDatum.netInputSizes); + for (auto& tDatumPtr : *tDatums) + tDatumPtr->inputNetData = spCvMatToOpInput->createArray( + tDatumPtr->cvInputData, tDatumPtr->scaleInputToNetInputs, tDatumPtr->netInputSizes); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/core/wCvMatToOpOutput.hpp b/include/openpose/core/wCvMatToOpOutput.hpp index da2c3452..ec93515b 100644 --- a/include/openpose/core/wCvMatToOpOutput.hpp +++ b/include/openpose/core/wCvMatToOpOutput.hpp @@ -65,9 +65,9 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // cv::Mat -> float* - for (auto& tDatum : tDatumsNoPtr) - tDatum.outputData = spCvMatToOpOutput->createArray(tDatum.cvInputData, tDatum.scaleInputToOutput, - tDatum.netOutputSize); + for (auto& tDatumPtr : tDatumsNoPtr) + tDatumPtr->outputData = spCvMatToOpOutput->createArray( + tDatumPtr->cvInputData, tDatumPtr->scaleInputToOutput, tDatumPtr->netOutputSize); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/core/wKeepTopNPeople.hpp b/include/openpose/core/wKeepTopNPeople.hpp index a8413e89..1628e821 100644 --- a/include/openpose/core/wKeepTopNPeople.hpp +++ b/include/openpose/core/wKeepTopNPeople.hpp @@ -60,14 +60,16 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Rescale pose data - for (auto& tDatum : *tDatums) + for (auto& tDatumPtr : *tDatums) { - tDatum.poseKeypoints = spKeepTopNPeople->keepTopPeople(tDatum.poseKeypoints, tDatum.poseScores); - tDatum.faceKeypoints = spKeepTopNPeople->keepTopPeople(tDatum.faceKeypoints, tDatum.poseScores); - tDatum.handKeypoints[0] = spKeepTopNPeople->keepTopPeople(tDatum.handKeypoints[0], - tDatum.poseScores); - tDatum.handKeypoints[1] = spKeepTopNPeople->keepTopPeople(tDatum.handKeypoints[1], - tDatum.poseScores); + tDatumPtr->poseKeypoints = spKeepTopNPeople->keepTopPeople( + tDatumPtr->poseKeypoints, tDatumPtr->poseScores); + tDatumPtr->faceKeypoints = spKeepTopNPeople->keepTopPeople( + tDatumPtr->faceKeypoints, tDatumPtr->poseScores); + tDatumPtr->handKeypoints[0] = spKeepTopNPeople->keepTopPeople( + tDatumPtr->handKeypoints[0], tDatumPtr->poseScores); + tDatumPtr->handKeypoints[1] = spKeepTopNPeople->keepTopPeople( + tDatumPtr->handKeypoints[1], tDatumPtr->poseScores); } // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/core/wKeypointScaler.hpp b/include/openpose/core/wKeypointScaler.hpp index 1ee196e3..9930207d 100644 --- a/include/openpose/core/wKeypointScaler.hpp +++ b/include/openpose/core/wKeypointScaler.hpp @@ -60,15 +60,18 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Rescale pose data - for (auto& tDatum : *tDatums) + for (auto& tDatumPtr : *tDatums) { - std::vector> arraysToScale{tDatum.poseKeypoints, tDatum.handKeypoints[0], - tDatum.handKeypoints[1], tDatum.faceKeypoints}; - spKeypointScaler->scale(arraysToScale, tDatum.scaleInputToOutput, tDatum.scaleNetToOutput, - Point{tDatum.cvInputData.cols, tDatum.cvInputData.rows}); + std::vector> arraysToScale{ + tDatumPtr->poseKeypoints, tDatumPtr->handKeypoints[0], + tDatumPtr->handKeypoints[1], tDatumPtr->faceKeypoints}; + spKeypointScaler->scale( + arraysToScale, tDatumPtr->scaleInputToOutput, tDatumPtr->scaleNetToOutput, + Point{tDatumPtr->cvInputData.cols, tDatumPtr->cvInputData.rows}); // Rescale part candidates - spKeypointScaler->scale(tDatum.poseCandidates, tDatum.scaleInputToOutput, tDatum.scaleNetToOutput, - Point{tDatum.cvInputData.cols, tDatum.cvInputData.rows}); + spKeypointScaler->scale( + tDatumPtr->poseCandidates, tDatumPtr->scaleInputToOutput, tDatumPtr->scaleNetToOutput, + Point{tDatumPtr->cvInputData.cols, tDatumPtr->cvInputData.rows}); } // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/core/wOpOutputToCvMat.hpp b/include/openpose/core/wOpOutputToCvMat.hpp index b575cad7..215c6bbc 100644 --- a/include/openpose/core/wOpOutputToCvMat.hpp +++ b/include/openpose/core/wOpOutputToCvMat.hpp @@ -62,8 +62,8 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // float* -> cv::Mat - for (auto& tDatum : *tDatums) - tDatum.cvOutputData = spOpOutputToCvMat->formatToCvMat(tDatum.outputData); + for (auto& tDatumPtr : *tDatums) + tDatumPtr->cvOutputData = spOpOutputToCvMat->formatToCvMat(tDatumPtr->outputData); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/core/wScaleAndSizeExtractor.hpp b/include/openpose/core/wScaleAndSizeExtractor.hpp index 23d22e7b..57c526ec 100644 --- a/include/openpose/core/wScaleAndSizeExtractor.hpp +++ b/include/openpose/core/wScaleAndSizeExtractor.hpp @@ -63,11 +63,11 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // cv::Mat -> float* - for (auto& tDatum : *tDatums) + for (auto& tDatumPtr : *tDatums) { - const Point inputSize{tDatum.cvInputData.cols, tDatum.cvInputData.rows}; - std::tie(tDatum.scaleInputToNetInputs, tDatum.netInputSizes, tDatum.scaleInputToOutput, - tDatum.netOutputSize) = spScaleAndSizeExtractor->extract(inputSize); + const Point inputSize{tDatumPtr->cvInputData.cols, tDatumPtr->cvInputData.rows}; + std::tie(tDatumPtr->scaleInputToNetInputs, tDatumPtr->netInputSizes, tDatumPtr->scaleInputToOutput, + tDatumPtr->netOutputSize) = spScaleAndSizeExtractor->extract(inputSize); } // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/core/wVerbosePrinter.hpp b/include/openpose/core/wVerbosePrinter.hpp index 8159270e..84c0bae2 100644 --- a/include/openpose/core/wVerbosePrinter.hpp +++ b/include/openpose/core/wVerbosePrinter.hpp @@ -65,8 +65,8 @@ namespace op // Print verbose if (checkNoNullNorEmpty(tDatums)) { - const auto tDatum = (*tDatums)[0]; - spVerbosePrinter->printVerbose(tDatum.frameNumber); + const auto tDatumPtr = (*tDatums)[0]; + spVerbosePrinter->printVerbose(tDatumPtr->frameNumber); } // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/face/wFaceDetector.hpp b/include/openpose/face/wFaceDetector.hpp index 3f5e43c5..3a5c904b 100644 --- a/include/openpose/face/wFaceDetector.hpp +++ b/include/openpose/face/wFaceDetector.hpp @@ -62,8 +62,8 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Detect people face - for (auto& tDatum : *tDatums) - tDatum.faceRectangles = spFaceDetector->detectFaces(tDatum.poseKeypoints); + for (auto& tDatumPtr : *tDatums) + tDatumPtr->faceRectangles = spFaceDetector->detectFaces(tDatumPtr->poseKeypoints); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/face/wFaceDetectorOpenCV.hpp b/include/openpose/face/wFaceDetectorOpenCV.hpp index c5023f2c..8e53615e 100644 --- a/include/openpose/face/wFaceDetectorOpenCV.hpp +++ b/include/openpose/face/wFaceDetectorOpenCV.hpp @@ -62,8 +62,8 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Detect people face - for (auto& tDatum : *tDatums) - tDatum.faceRectangles = spFaceDetectorOpenCV->detectFaces(tDatum.cvInputData); + for (auto& tDatumPtr : *tDatums) + tDatumPtr->faceRectangles = spFaceDetectorOpenCV->detectFaces(tDatumPtr->cvInputData); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/face/wFaceExtractorNet.hpp b/include/openpose/face/wFaceExtractorNet.hpp index 2675331c..ce9fb0dd 100644 --- a/include/openpose/face/wFaceExtractorNet.hpp +++ b/include/openpose/face/wFaceExtractorNet.hpp @@ -63,11 +63,11 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Extract people face - for (auto& tDatum : *tDatums) + for (auto& tDatumPtr : *tDatums) { - spFaceExtractorNet->forwardPass(tDatum.faceRectangles, tDatum.cvInputData); - tDatum.faceHeatMaps = spFaceExtractorNet->getHeatMaps().clone(); - tDatum.faceKeypoints = spFaceExtractorNet->getFaceKeypoints().clone(); + spFaceExtractorNet->forwardPass(tDatumPtr->faceRectangles, tDatumPtr->cvInputData); + tDatumPtr->faceHeatMaps = spFaceExtractorNet->getHeatMaps().clone(); + tDatumPtr->faceKeypoints = spFaceExtractorNet->getFaceKeypoints().clone(); } // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/face/wFaceRenderer.hpp b/include/openpose/face/wFaceRenderer.hpp index e33d1922..de981856 100644 --- a/include/openpose/face/wFaceRenderer.hpp +++ b/include/openpose/face/wFaceRenderer.hpp @@ -63,9 +63,9 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Render people face - for (auto& tDatum : *tDatums) - spFaceRenderer->renderFace(tDatum.outputData, tDatum.faceKeypoints, - (float)tDatum.scaleInputToOutput); + for (auto& tDatumPtr : *tDatums) + spFaceRenderer->renderFace( + tDatumPtr->outputData, tDatumPtr->faceKeypoints, (float)tDatumPtr->scaleInputToOutput); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/filestream/wBvhSaver.hpp b/include/openpose/filestream/wBvhSaver.hpp index c025b8ac..337e96f0 100644 --- a/include/openpose/filestream/wBvhSaver.hpp +++ b/include/openpose/filestream/wBvhSaver.hpp @@ -63,9 +63,9 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Record BVH file - const auto& tDatum = (*tDatums)[0]; - if (!tDatum.poseKeypoints3D.empty()) - spBvhSaver->updateBvh(tDatum.adamPose, tDatum.adamTranslation, tDatum.j0Vec); + const auto& tDatumPtr = (*tDatums)[0]; + if (!tDatumPtr->poseKeypoints3D.empty()) + spBvhSaver->updateBvh(tDatumPtr->adamPose, tDatumPtr->adamTranslation, tDatumPtr->j0Vec); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/filestream/wCocoJsonSaver.hpp b/include/openpose/filestream/wCocoJsonSaver.hpp index 01940940..3010ce2b 100644 --- a/include/openpose/filestream/wCocoJsonSaver.hpp +++ b/include/openpose/filestream/wCocoJsonSaver.hpp @@ -65,9 +65,9 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // T* to T - const auto& tDatum = tDatums->at(0); + const auto& tDatumPtr = tDatums->at(0); // Record json in COCO format - spCocoJsonSaver->record(tDatum.poseKeypoints, tDatum.poseScores, tDatum.name); + spCocoJsonSaver->record(tDatumPtr->poseKeypoints, tDatumPtr->poseScores, tDatumPtr->name); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/filestream/wFaceSaver.hpp b/include/openpose/filestream/wFaceSaver.hpp index 6afe70f0..6d34d3ad 100644 --- a/include/openpose/filestream/wFaceSaver.hpp +++ b/include/openpose/filestream/wFaceSaver.hpp @@ -67,8 +67,9 @@ namespace op // Record people face keypoint data std::vector> keypointVector(tDatumsNoPtr.size()); for (auto i = 0u; i < tDatumsNoPtr.size(); i++) - keypointVector[i] = tDatumsNoPtr[i].faceKeypoints; - const auto fileName = (!tDatumsNoPtr[0].name.empty() ? tDatumsNoPtr[0].name : std::to_string(tDatumsNoPtr[0].id)); + keypointVector[i] = tDatumsNoPtr[i]->faceKeypoints; + const auto fileName = (!tDatumsNoPtr[0]->name.empty() + ? tDatumsNoPtr[0]->name : std::to_string(tDatumsNoPtr[0]->id)); spKeypointSaver->saveKeypoints(keypointVector, fileName, "face"); // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/filestream/wHandSaver.hpp b/include/openpose/filestream/wHandSaver.hpp index eb7431ec..ebaea19b 100644 --- a/include/openpose/filestream/wHandSaver.hpp +++ b/include/openpose/filestream/wHandSaver.hpp @@ -65,15 +65,16 @@ namespace op // T* to T auto& tDatumsNoPtr = *tDatums; // Record people hand keypoint data - const auto fileName = (!tDatumsNoPtr[0].name.empty() ? tDatumsNoPtr[0].name : std::to_string(tDatumsNoPtr[0].id)); + const auto fileName = (!tDatumsNoPtr[0]->name.empty() + ? tDatumsNoPtr[0]->name : std::to_string(tDatumsNoPtr[0]->id)); std::vector> keypointVector(tDatumsNoPtr.size()); // Left hand for (auto i = 0u; i < tDatumsNoPtr.size(); i++) - keypointVector[i] = tDatumsNoPtr[i].handKeypoints[0]; + keypointVector[i] = tDatumsNoPtr[i]->handKeypoints[0]; spKeypointSaver->saveKeypoints(keypointVector, fileName, "hand_left"); // Right hand for (auto i = 0u; i < tDatumsNoPtr.size(); i++) - keypointVector[i] = tDatumsNoPtr[i].handKeypoints[1]; + keypointVector[i] = tDatumsNoPtr[i]->handKeypoints[1]; spKeypointSaver->saveKeypoints(keypointVector, fileName, "hand_right"); // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/filestream/wHeatMapSaver.hpp b/include/openpose/filestream/wHeatMapSaver.hpp index 8ac8f38e..2f4226b4 100644 --- a/include/openpose/filestream/wHeatMapSaver.hpp +++ b/include/openpose/filestream/wHeatMapSaver.hpp @@ -66,9 +66,9 @@ namespace op // Record pose heatmap image(s) on disk std::vector> poseHeatMaps(tDatumsNoPtr.size()); for (auto i = 0u; i < tDatumsNoPtr.size(); i++) - poseHeatMaps[i] = tDatumsNoPtr[i].poseHeatMaps; - const auto fileName = (!tDatumsNoPtr[0].name.empty() - ? tDatumsNoPtr[0].name : std::to_string(tDatumsNoPtr[0].id)) + "_pose_heatmaps"; + poseHeatMaps[i] = tDatumsNoPtr[i]->poseHeatMaps; + const auto fileName = (!tDatumsNoPtr[0]->name.empty() + ? tDatumsNoPtr[0]->name : std::to_string(tDatumsNoPtr[0]->id)) + "_pose_heatmaps"; spHeatMapSaver->saveHeatMaps(poseHeatMaps, fileName); // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/filestream/wImageSaver.hpp b/include/openpose/filestream/wImageSaver.hpp index 93b539fd..d663b847 100644 --- a/include/openpose/filestream/wImageSaver.hpp +++ b/include/openpose/filestream/wImageSaver.hpp @@ -66,8 +66,9 @@ namespace op // Record image(s) on disk std::vector cvOutputDatas(tDatumsNoPtr.size()); for (auto i = 0u; i < tDatumsNoPtr.size(); i++) - cvOutputDatas[i] = tDatumsNoPtr[i].cvOutputData; - const auto fileName = (!tDatumsNoPtr[0].name.empty() ? tDatumsNoPtr[0].name : std::to_string(tDatumsNoPtr[0].id)); + cvOutputDatas[i] = tDatumsNoPtr[i]->cvOutputData; + const auto fileName = (!tDatumsNoPtr[0]->name.empty() + ? tDatumsNoPtr[0]->name : std::to_string(tDatumsNoPtr[0]->id)); spImageSaver->saveImages(cvOutputDatas, fileName); // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/filestream/wPeopleJsonSaver.hpp b/include/openpose/filestream/wPeopleJsonSaver.hpp index 16dc1fba..7d2a8535 100644 --- a/include/openpose/filestream/wPeopleJsonSaver.hpp +++ b/include/openpose/filestream/wPeopleJsonSaver.hpp @@ -62,30 +62,30 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Save body/face/hand keypoints to JSON file - const auto& tDatumFirst = (*tDatums)[0]; - const auto baseFileName = (!tDatumFirst.name.empty() ? tDatumFirst.name - : std::to_string(tDatumFirst.id)) + "_keypoints"; + const auto& tDatumFirstPtr = (*tDatums)[0]; + const auto baseFileName = (!tDatumFirstPtr->name.empty() ? tDatumFirstPtr->name + : std::to_string(tDatumFirstPtr->id)) + "_keypoints"; const bool humanReadable = false; for (auto i = 0u ; i < tDatums->size() ; i++) { - const auto& tDatum = (*tDatums)[i]; + const auto& tDatumPtr = (*tDatums)[i]; // const auto fileName = baseFileName; const auto fileName = baseFileName + (i != 0 ? "_" + std::to_string(i) : ""); const std::vector, std::string>> keypointVector{ // 2D - std::make_pair(tDatum.poseKeypoints, "pose_keypoints_2d"), - std::make_pair(tDatum.faceKeypoints, "face_keypoints_2d"), - std::make_pair(tDatum.handKeypoints[0], "hand_left_keypoints_2d"), - std::make_pair(tDatum.handKeypoints[1], "hand_right_keypoints_2d"), + std::make_pair(tDatumPtr->poseKeypoints, "pose_keypoints_2d"), + std::make_pair(tDatumPtr->faceKeypoints, "face_keypoints_2d"), + std::make_pair(tDatumPtr->handKeypoints[0], "hand_left_keypoints_2d"), + std::make_pair(tDatumPtr->handKeypoints[1], "hand_right_keypoints_2d"), // 3D - std::make_pair(tDatum.poseKeypoints3D, "pose_keypoints_3d"), - std::make_pair(tDatum.faceKeypoints3D, "face_keypoints_3d"), - std::make_pair(tDatum.handKeypoints3D[0], "hand_left_keypoints_3d"), - std::make_pair(tDatum.handKeypoints3D[1], "hand_right_keypoints_3d") + std::make_pair(tDatumPtr->poseKeypoints3D, "pose_keypoints_3d"), + std::make_pair(tDatumPtr->faceKeypoints3D, "face_keypoints_3d"), + std::make_pair(tDatumPtr->handKeypoints3D[0], "hand_left_keypoints_3d"), + std::make_pair(tDatumPtr->handKeypoints3D[1], "hand_right_keypoints_3d") }; // Save keypoints - spPeopleJsonSaver->save(keypointVector, tDatum.poseCandidates, fileName, humanReadable); + spPeopleJsonSaver->save(keypointVector, tDatumPtr->poseCandidates, fileName, humanReadable); } // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/filestream/wPoseSaver.hpp b/include/openpose/filestream/wPoseSaver.hpp index cbcab029..0edf6ef0 100644 --- a/include/openpose/filestream/wPoseSaver.hpp +++ b/include/openpose/filestream/wPoseSaver.hpp @@ -67,8 +67,9 @@ namespace op // Record people pose keypoint data std::vector> keypointVector(tDatumsNoPtr.size()); for (auto i = 0u; i < tDatumsNoPtr.size(); i++) - keypointVector[i] = tDatumsNoPtr[i].poseKeypoints; - const auto fileName = (!tDatumsNoPtr[0].name.empty() ? tDatumsNoPtr[0].name : std::to_string(tDatumsNoPtr[0].id)); + keypointVector[i] = tDatumsNoPtr[i]->poseKeypoints; + const auto fileName = (!tDatumsNoPtr[0]->name.empty() + ? tDatumsNoPtr[0]->name : std::to_string(tDatumsNoPtr[0]->id)); spKeypointSaver->saveKeypoints(keypointVector, fileName, "pose"); // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/filestream/wUdpSender.hpp b/include/openpose/filestream/wUdpSender.hpp index 57ac4e9f..14f0ba71 100644 --- a/include/openpose/filestream/wUdpSender.hpp +++ b/include/openpose/filestream/wUdpSender.hpp @@ -63,24 +63,24 @@ namespace op const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Send though UDP communication #ifdef USE_3D_ADAM_MODEL - const auto& tDatum = (*tDatums)[0]; - if (!tDatum.poseKeypoints3D.empty()) + const auto& tDatumPtr = (*tDatums)[0]; + if (!tDatumPtr->poseKeypoints3D.empty()) { - const auto& adamPose = tDatum.adamPose; // Eigen::Matrix - const auto& adamTranslation = tDatum.adamTranslation; // Eigen::Vector3d(3, 1) - const auto adamFaceCoeffsExp = tDatum.adamFaceCoeffsExp; // Eigen::VectorXd resized to (200, 1) - //const float mouth_open = tDatum.mouthOpening; // tDatum.mouth_open; - //const float leye_open = tDatum.rightEyeOpening; // tDatum.leye_open; - //const float reye_open = tDatum.leftEyeOpening; // tDatum.reye_open; - //const float dist_root_foot = Datum.distanceRootFoot; // tDatum.dist_root_foot; + const auto& adamPose = tDatumPtr->adamPose; // Eigen::Matrix + const auto& adamTranslation = tDatumPtr->adamTranslation; // Eigen::Vector3d(3, 1) + const auto adamFaceCoeffsExp = tDatumPtr->adamFaceCoeffsExp; // Eigen::VectorXd resized to (200, 1) + //const float mouth_open = tDatumPtr->mouthOpening; // tDatumPtr->mouth_open; + //const float leye_open = tDatumPtr->rightEyeOpening; // tDatumPtr->leye_open; + //const float reye_open = tDatumPtr->leftEyeOpening; // tDatumPtr->reye_open; + //const float dist_root_foot = Datum.distanceRootFoot; // tDatumPtr->dist_root_foot; // m_adam_t: // 1. Total translation (centimeters) of the root in camera/global coordinate representation. // m_adam_pose: // 1. First row is global rotation, in AngleAxis representation. Radians (not degrees!) // 2. Rest are joint-angles in Euler-Angle representation. Degrees. - spUdpSender->sendJointAngles(adamPose.data(), adamPose.rows(), - adamTranslation.data(), - adamFaceCoeffsExp.data(), adamFaceCoeffsExp.rows()); + spUdpSender->sendJointAngles( + adamPose.data(), adamPose.rows(), adamTranslation.data(), adamFaceCoeffsExp.data(), + adamFaceCoeffsExp.rows()); } #endif // Profiling speed diff --git a/include/openpose/filestream/wVideoSaver.hpp b/include/openpose/filestream/wVideoSaver.hpp index ef7640e1..fdc979c1 100644 --- a/include/openpose/filestream/wVideoSaver.hpp +++ b/include/openpose/filestream/wVideoSaver.hpp @@ -66,7 +66,7 @@ namespace op // Record video(s) std::vector cvOutputDatas(tDatumsNoPtr.size()); for (auto i = 0u ; i < cvOutputDatas.size() ; i++) - cvOutputDatas[i] = tDatumsNoPtr[i].cvOutputData; + cvOutputDatas[i] = tDatumsNoPtr[i]->cvOutputData; spVideoSaver->write(cvOutputDatas); // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/filestream/wVideoSaver3D.hpp b/include/openpose/filestream/wVideoSaver3D.hpp index c1109a2c..1881e8da 100644 --- a/include/openpose/filestream/wVideoSaver3D.hpp +++ b/include/openpose/filestream/wVideoSaver3D.hpp @@ -65,7 +65,7 @@ namespace op auto& tDatumsNoPtr = *tDatums; // Record video(s) if (!tDatumsNoPtr.empty()) - spVideoSaver->write(tDatumsNoPtr[0].cvOutputData3D); + spVideoSaver->write(tDatumsNoPtr[0]->cvOutputData3D); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/gui/wGui.hpp b/include/openpose/gui/wGui.hpp index 11d34b84..6a3fe677 100644 --- a/include/openpose/gui/wGui.hpp +++ b/include/openpose/gui/wGui.hpp @@ -74,8 +74,8 @@ namespace op if (!tDatums->empty()) { std::vector cvOutputDatas; - for (auto& tDatum : *tDatums) - cvOutputDatas.emplace_back(tDatum.cvOutputData); + for (auto& tDatumPtr : *tDatums) + cvOutputDatas.emplace_back(tDatumPtr->cvOutputData); spGui->setImage(cvOutputDatas); } // Refresh/update GUI diff --git a/include/openpose/gui/wGui3D.hpp b/include/openpose/gui/wGui3D.hpp index a1b9d87d..e8ca5d10 100644 --- a/include/openpose/gui/wGui3D.hpp +++ b/include/openpose/gui/wGui3D.hpp @@ -76,21 +76,22 @@ namespace op { // Update cvMat std::vector cvOutputDatas; - for (auto& tDatum : *tDatums) - cvOutputDatas.emplace_back(tDatum.cvOutputData); + for (auto& tDatumPtr : *tDatums) + cvOutputDatas.emplace_back(tDatumPtr->cvOutputData); spGui3D->setImage(cvOutputDatas); // Update keypoints - auto& tDatum = (*tDatums)[0]; - spGui3D->setKeypoints(tDatum.poseKeypoints3D, tDatum.faceKeypoints3D, tDatum.handKeypoints3D[0], - tDatum.handKeypoints3D[1]); + auto& tDatumPtr = (*tDatums)[0]; + spGui3D->setKeypoints( + tDatumPtr->poseKeypoints3D, tDatumPtr->faceKeypoints3D, tDatumPtr->handKeypoints3D[0], + tDatumPtr->handKeypoints3D[1]); } // Refresh/update GUI spGui3D->update(); // Read OpenCV mat equivalent if (!tDatums->empty()) { - auto& tDatum = (*tDatums)[0]; - tDatum.cvOutputData3D = spGui3D->readCvMat(); + auto& tDatumPtr = (*tDatums)[0]; + tDatumPtr->cvOutputData3D = spGui3D->readCvMat(); } // Profiling speed if (!tDatums->empty()) diff --git a/include/openpose/gui/wGuiAdam.hpp b/include/openpose/gui/wGuiAdam.hpp index 1a604d30..966b4c51 100644 --- a/include/openpose/gui/wGuiAdam.hpp +++ b/include/openpose/gui/wGuiAdam.hpp @@ -77,16 +77,16 @@ namespace op // Update cvMat std::vector cvOutputDatas; for (auto& tDatum : *tDatums) - cvOutputDatas.emplace_back(tDatum.cvOutputData); + cvOutputDatas.emplace_back(tDatumPtr->cvOutputData); spGuiAdam->setImage(cvOutputDatas); // Update keypoints - const auto& tDatum = (*tDatums)[0]; - if (!tDatum.poseKeypoints3D.empty()) - spGuiAdam->generateMesh(tDatum.poseKeypoints3D, tDatum.faceKeypoints3D, tDatum.handKeypoints3D, - tDatum.adamPose.data(), tDatum.adamTranslation.data(), - tDatum.vtVec.data(), tDatum.vtVec.rows(), - tDatum.j0Vec.data(), tDatum.j0Vec.rows(), - tDatum.adamFaceCoeffsExp.data()); + const auto& tDatumPtr = (*tDatums)[0]; + if (!tDatumPtr->poseKeypoints3D.empty()) + spGuiAdam->generateMesh( + tDatumPtr->poseKeypoints3D, tDatumPtr->faceKeypoints3D, tDatumPtr->handKeypoints3D, + tDatumPtr->adamPose.data(), tDatumPtr->adamTranslation.data(), tDatumPtr->vtVec.data(), + tDatumPtr->vtVec.rows(), tDatumPtr->j0Vec.data(), tDatumPtr->j0Vec.rows(), + tDatumPtr->adamFaceCoeffsExp.data()); } // Refresh/update GUI spGuiAdam->update(); diff --git a/include/openpose/gui/wGuiInfoAdder.hpp b/include/openpose/gui/wGuiInfoAdder.hpp index c272d0d1..7d58c8e3 100644 --- a/include/openpose/gui/wGuiInfoAdder.hpp +++ b/include/openpose/gui/wGuiInfoAdder.hpp @@ -62,11 +62,12 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Add GUI components to frame - for (auto& tDatum : *tDatums) - spGuiInfoAdder->addInfo(tDatum.cvOutputData, std::max(tDatum.poseKeypoints.getSize(0), - tDatum.faceKeypoints.getSize(0)), - tDatum.id, tDatum.elementRendered.second, tDatum.frameNumber, - tDatum.poseIds, tDatum.poseKeypoints); + for (auto& tDatumPtr : *tDatums) + spGuiInfoAdder->addInfo( + tDatumPtr->cvOutputData, + std::max(tDatumPtr->poseKeypoints.getSize(0), tDatumPtr->faceKeypoints.getSize(0)), + tDatumPtr->id, tDatumPtr->elementRendered.second, tDatumPtr->frameNumber, + tDatumPtr->poseIds, tDatumPtr->poseKeypoints); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/hand/wHandDetector.hpp b/include/openpose/hand/wHandDetector.hpp index 3fd455d1..5000e7d1 100644 --- a/include/openpose/hand/wHandDetector.hpp +++ b/include/openpose/hand/wHandDetector.hpp @@ -62,8 +62,8 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Detect people hand - for (auto& tDatum : *tDatums) - tDatum.handRectangles = spHandDetector->detectHands(tDatum.poseKeypoints); + for (auto& tDatumPtr : *tDatums) + tDatumPtr->handRectangles = spHandDetector->detectHands(tDatumPtr->poseKeypoints); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/hand/wHandDetectorFromTxt.hpp b/include/openpose/hand/wHandDetectorFromTxt.hpp index 2a26f68e..fa6819ea 100644 --- a/include/openpose/hand/wHandDetectorFromTxt.hpp +++ b/include/openpose/hand/wHandDetectorFromTxt.hpp @@ -62,8 +62,8 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Detect people hand - for (auto& tDatum : *tDatums) - tDatum.handRectangles = spHandDetectorFromTxt->detectHands(); + for (auto& tDatumPtr : *tDatums) + tDatumPtr->handRectangles = spHandDetectorFromTxt->detectHands(); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/hand/wHandDetectorTracking.hpp b/include/openpose/hand/wHandDetectorTracking.hpp index bc7c45b4..d2a8ec61 100644 --- a/include/openpose/hand/wHandDetectorTracking.hpp +++ b/include/openpose/hand/wHandDetectorTracking.hpp @@ -62,8 +62,8 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Detect people hand - for (auto& tDatum : *tDatums) - tDatum.handRectangles = spHandDetector->trackHands(tDatum.poseKeypoints); + for (auto& tDatumPtr : *tDatums) + tDatumPtr->handRectangles = spHandDetector->trackHands(tDatumPtr->poseKeypoints); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/hand/wHandDetectorUpdate.hpp b/include/openpose/hand/wHandDetectorUpdate.hpp index c9b8d8e2..5c1ee00d 100644 --- a/include/openpose/hand/wHandDetectorUpdate.hpp +++ b/include/openpose/hand/wHandDetectorUpdate.hpp @@ -62,8 +62,8 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Detect people hand - for (auto& tDatum : *tDatums) - spHandDetector->updateTracker(tDatum.handKeypoints, tDatum.id); + for (auto& tDatumPtr : *tDatums) + spHandDetector->updateTracker(tDatumPtr->handKeypoints, tDatumPtr->id); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/hand/wHandExtractorNet.hpp b/include/openpose/hand/wHandExtractorNet.hpp index 9f7ca69d..04350d64 100644 --- a/include/openpose/hand/wHandExtractorNet.hpp +++ b/include/openpose/hand/wHandExtractorNet.hpp @@ -63,13 +63,13 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Extract people hands - for (auto& tDatum : *tDatums) + for (auto& tDatumPtr : *tDatums) { - spHandExtractorNet->forwardPass(tDatum.handRectangles, tDatum.cvInputData); + spHandExtractorNet->forwardPass(tDatumPtr->handRectangles, tDatumPtr->cvInputData); for (auto hand = 0 ; hand < 2 ; hand++) { - tDatum.handHeatMaps[hand] = spHandExtractorNet->getHeatMaps()[hand].clone(); - tDatum.handKeypoints[hand] = spHandExtractorNet->getHandKeypoints()[hand].clone(); + tDatumPtr->handHeatMaps[hand] = spHandExtractorNet->getHeatMaps()[hand].clone(); + tDatumPtr->handKeypoints[hand] = spHandExtractorNet->getHandKeypoints()[hand].clone(); } } // Profiling speed diff --git a/include/openpose/hand/wHandRenderer.hpp b/include/openpose/hand/wHandRenderer.hpp index 92ea947d..7e44dc5b 100644 --- a/include/openpose/hand/wHandRenderer.hpp +++ b/include/openpose/hand/wHandRenderer.hpp @@ -63,9 +63,9 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Render people hands - for (auto& tDatum : *tDatums) - spHandRenderer->renderHand(tDatum.outputData, tDatum.handKeypoints, - (float)tDatum.scaleInputToOutput); + for (auto& tDatumPtr : *tDatums) + spHandRenderer->renderHand( + tDatumPtr->outputData, tDatumPtr->handKeypoints, (float)tDatumPtr->scaleInputToOutput); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/pose/wPoseExtractor.hpp b/include/openpose/pose/wPoseExtractor.hpp index e7f93708..8eebd835 100644 --- a/include/openpose/pose/wPoseExtractor.hpp +++ b/include/openpose/pose/wPoseExtractor.hpp @@ -73,25 +73,25 @@ namespace op for (auto i = 0u ; i < tDatums->size() ; i++) // for (auto& tDatum : *tDatums) { - auto& tDatum = (*tDatums)[i]; + auto& tDatumPtr = (*tDatums)[i]; // OpenPose net forward pass - spPoseExtractor->forwardPass(tDatum.inputNetData, - Point{tDatum.cvInputData.cols, tDatum.cvInputData.rows}, - tDatum.scaleInputToNetInputs, tDatum.id); + spPoseExtractor->forwardPass( + tDatumPtr->inputNetData, Point{tDatumPtr->cvInputData.cols, tDatumPtr->cvInputData.rows}, + tDatumPtr->scaleInputToNetInputs, tDatumPtr->id); // OpenPose keypoint detector - tDatum.poseCandidates = spPoseExtractor->getCandidatesCopy(); - tDatum.poseHeatMaps = spPoseExtractor->getHeatMapsCopy(); - tDatum.poseKeypoints = spPoseExtractor->getPoseKeypoints().clone(); - tDatum.poseScores = spPoseExtractor->getPoseScores().clone(); - tDatum.scaleNetToOutput = spPoseExtractor->getScaleNetToOutput(); + tDatumPtr->poseCandidates = spPoseExtractor->getCandidatesCopy(); + tDatumPtr->poseHeatMaps = spPoseExtractor->getHeatMapsCopy(); + tDatumPtr->poseKeypoints = spPoseExtractor->getPoseKeypoints().clone(); + tDatumPtr->poseScores = spPoseExtractor->getPoseScores().clone(); + tDatumPtr->scaleNetToOutput = spPoseExtractor->getScaleNetToOutput(); // Keep desired top N people - spPoseExtractor->keepTopPeople(tDatum.poseKeypoints, tDatum.poseScores); + spPoseExtractor->keepTopPeople(tDatumPtr->poseKeypoints, tDatumPtr->poseScores); // ID extractor (experimental) - tDatum.poseIds = spPoseExtractor->extractIdsLockThread( - tDatum.poseKeypoints, tDatum.cvInputData, i, tDatum.id); + tDatumPtr->poseIds = spPoseExtractor->extractIdsLockThread( + tDatumPtr->poseKeypoints, tDatumPtr->cvInputData, i, tDatumPtr->id); // Tracking (experimental) spPoseExtractor->trackLockThread( - tDatum.poseKeypoints, tDatum.poseIds, tDatum.cvInputData, i, tDatum.id); + tDatumPtr->poseKeypoints, tDatumPtr->poseIds, tDatumPtr->cvInputData, i, tDatumPtr->id); } // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/pose/wPoseExtractorNet.hpp b/include/openpose/pose/wPoseExtractorNet.hpp index b87e4826..2d10b4d1 100644 --- a/include/openpose/pose/wPoseExtractorNet.hpp +++ b/include/openpose/pose/wPoseExtractorNet.hpp @@ -70,16 +70,16 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Extract people pose - for (auto& tDatum : *tDatums) + for (auto& tDatumPtr : *tDatums) { - spPoseExtractorNet->forwardPass(tDatum.inputNetData, - Point{tDatum.cvInputData.cols, tDatum.cvInputData.rows}, - tDatum.scaleInputToNetInputs); - tDatum.poseCandidates = spPoseExtractorNet->getCandidatesCopy(); - tDatum.poseHeatMaps = spPoseExtractorNet->getHeatMapsCopy(); - tDatum.poseKeypoints = spPoseExtractorNet->getPoseKeypoints().clone(); - tDatum.poseScores = spPoseExtractorNet->getPoseScores().clone(); - tDatum.scaleNetToOutput = spPoseExtractorNet->getScaleNetToOutput(); + spPoseExtractorNet->forwardPass( + tDatumPtr->inputNetData, Point{tDatumPtr->cvInputData.cols, tDatumPtr->cvInputData.rows}, + tDatumPtr->scaleInputToNetInputs); + tDatumPtr->poseCandidates = spPoseExtractorNet->getCandidatesCopy(); + tDatumPtr->poseHeatMaps = spPoseExtractorNet->getHeatMapsCopy(); + tDatumPtr->poseKeypoints = spPoseExtractorNet->getPoseKeypoints().clone(); + tDatumPtr->poseScores = spPoseExtractorNet->getPoseScores().clone(); + tDatumPtr->scaleNetToOutput = spPoseExtractorNet->getScaleNetToOutput(); } // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/pose/wPoseRenderer.hpp b/include/openpose/pose/wPoseRenderer.hpp index 01d578c8..18aaf490 100644 --- a/include/openpose/pose/wPoseRenderer.hpp +++ b/include/openpose/pose/wPoseRenderer.hpp @@ -70,10 +70,10 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Render people pose - for (auto& tDatum : *tDatums) - tDatum.elementRendered = spPoseRenderer->renderPose( - tDatum.outputData, tDatum.poseKeypoints, (float)tDatum.scaleInputToOutput, - (float)tDatum.scaleNetToOutput); + for (auto& tDatumPtr : *tDatums) + tDatumPtr->elementRendered = spPoseRenderer->renderPose( + tDatumPtr->outputData, tDatumPtr->poseKeypoints, (float)tDatumPtr->scaleInputToOutput, + (float)tDatumPtr->scaleNetToOutput); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/producer/datumProducer.hpp b/include/openpose/producer/datumProducer.hpp index 48dbd2ec..38d04797 100644 --- a/include/openpose/producer/datumProducer.hpp +++ b/include/openpose/producer/datumProducer.hpp @@ -11,19 +11,19 @@ namespace op { - template + template class DatumProducer { public: - explicit DatumProducer(const std::shared_ptr& producerSharedPtr, - const unsigned long long frameFirst = 0, const unsigned long long frameStep = 1, - const unsigned long long frameLast = std::numeric_limits::max(), - const std::shared_ptr, - std::atomic>>& videoSeekSharedPtr = nullptr); + explicit DatumProducer( + const std::shared_ptr& producerSharedPtr, + const unsigned long long frameFirst = 0, const unsigned long long frameStep = 1, + const unsigned long long frameLast = std::numeric_limits::max(), + const std::shared_ptr, std::atomic>>& videoSeekSharedPtr = nullptr); virtual ~DatumProducer(); - std::pair> checkIfRunningAndGetDatum(); + std::pair>>> checkIfRunningAndGetDatum(); private: const unsigned long long mNumberFramesToProcess; @@ -33,8 +33,8 @@ namespace op unsigned int mNumberConsecutiveEmptyFrames; std::shared_ptr, std::atomic>> spVideoSeek; - void checkIfTooManyConsecutiveEmptyFrames(unsigned int& numberConsecutiveEmptyFrames, - const bool emptyFrame) const; + void checkIfTooManyConsecutiveEmptyFrames( + unsigned int& numberConsecutiveEmptyFrames, const bool emptyFrame) const; DELETE_COPY(DatumProducer); }; @@ -49,12 +49,12 @@ namespace op #include namespace op { - template - DatumProducer::DatumProducer(const std::shared_ptr& producerSharedPtr, - const unsigned long long frameFirst, const unsigned long long frameStep, - const unsigned long long frameLast, - const std::shared_ptr, - std::atomic>>& videoSeekSharedPtr) : + template + DatumProducer::DatumProducer( + const std::shared_ptr& producerSharedPtr, + const unsigned long long frameFirst, const unsigned long long frameStep, + const unsigned long long frameLast, + const std::shared_ptr, std::atomic>>& videoSeekSharedPtr) : mNumberFramesToProcess{(frameLast != std::numeric_limits::max() ? frameLast - frameFirst : frameLast)}, spProducer{producerSharedPtr}, @@ -92,17 +92,17 @@ namespace op } } - template - DatumProducer::~DatumProducer() + template + DatumProducer::~DatumProducer() { } - template - std::pair> DatumProducer::checkIfRunningAndGetDatum() + template + std::pair>>> DatumProducer::checkIfRunningAndGetDatum() { try { - auto datums = std::make_shared(); + auto datums = std::make_shared>>(); // Check last desired frame has not been reached if (mNumberFramesToProcess != std::numeric_limits::max() && mGlobalCounter > mNumberFramesToProcess) @@ -137,52 +137,54 @@ namespace op { datums->resize(cvMats.size()); // Datum cannot be assigned before resize() - auto& datum = (*datums)[0]; + auto& datumPtr = (*datums)[0]; + datumPtr = std::make_shared(); // Filling first element - std::swap(datum.name, nextFrameName); - datum.frameNumber = nextFrameNumber; - datum.cvInputData = cvMats[0]; + std::swap(datumPtr->name, nextFrameName); + datumPtr->frameNumber = nextFrameNumber; + datumPtr->cvInputData = cvMats[0]; if (!cameraMatrices.empty()) { - datum.cameraMatrix = cameraMatrices[0]; - datum.cameraExtrinsics = cameraExtrinsics[0]; - datum.cameraIntrinsics = cameraIntrinsics[0]; + datumPtr->cameraMatrix = cameraMatrices[0]; + datumPtr->cameraExtrinsics = cameraExtrinsics[0]; + datumPtr->cameraIntrinsics = cameraIntrinsics[0]; } // Image integrity - if (datum.cvInputData.channels() != 3) + if (datumPtr->cvInputData.channels() != 3) { const std::string commonMessage{"Input images must be 3-channel BGR."}; // Grey to RGB if required - if (datum.cvInputData.channels() == 1) + if (datumPtr->cvInputData.channels() == 1) { log(commonMessage + " Converting grey image into BGR.", Priority::High); - cv::cvtColor(datum.cvInputData, datum.cvInputData, CV_GRAY2BGR); + cv::cvtColor(datumPtr->cvInputData, datumPtr->cvInputData, CV_GRAY2BGR); } else error(commonMessage, __LINE__, __FUNCTION__, __FILE__); } - datum.cvOutputData = datum.cvInputData; + datumPtr->cvOutputData = datumPtr->cvInputData; // Resize if it's stereo-system if (datums->size() > 1) { // Stereo-system: Assign all cv::Mat for (auto i = 1u ; i < datums->size() ; i++) { - auto& datumI = (*datums)[i]; - datumI.name = datum.name; - datumI.frameNumber = datum.frameNumber; - datumI.cvInputData = cvMats[i]; - datumI.cvOutputData = datumI.cvInputData; + auto& datumIPtr = (*datums)[i]; + datumIPtr = std::make_shared(); + datumIPtr->name = datumPtr->name; + datumIPtr->frameNumber = datumPtr->frameNumber; + datumIPtr->cvInputData = cvMats[i]; + datumIPtr->cvOutputData = datumIPtr->cvInputData; if (cameraMatrices.size() > i) { - datumI.cameraMatrix = cameraMatrices[i]; - datumI.cameraExtrinsics = cameraExtrinsics[i]; - datumI.cameraIntrinsics = cameraIntrinsics[i]; + datumIPtr->cameraMatrix = cameraMatrices[i]; + datumIPtr->cameraExtrinsics = cameraExtrinsics[i]; + datumIPtr->cameraIntrinsics = cameraIntrinsics[i]; } } } // Check producer is running - if (!datumProducerRunning || (*datums)[0].cvInputData.empty()) + if (!datumProducerRunning || (*datums)[0]->cvInputData.empty()) datums = nullptr; // Increase counter if successful image if (datums != nullptr) @@ -195,13 +197,13 @@ namespace op catch (const std::exception& e) { error(e.what(), __LINE__, __FUNCTION__, __FILE__); - return std::make_pair(false, std::make_shared()); + return std::make_pair(false, std::make_shared>>()); } } - template - void DatumProducer::checkIfTooManyConsecutiveEmptyFrames(unsigned int& numberConsecutiveEmptyFrames, - const bool emptyFrame) const + template + void DatumProducer::checkIfTooManyConsecutiveEmptyFrames( + unsigned int& numberConsecutiveEmptyFrames, const bool emptyFrame) const { numberConsecutiveEmptyFrames = (emptyFrame ? numberConsecutiveEmptyFrames+1 : 0); const auto threshold = 500u; @@ -210,7 +212,7 @@ namespace op __LINE__, __FUNCTION__, __FILE__); } - extern template class DatumProducer; + extern template class DatumProducer; } diff --git a/include/openpose/producer/wDatumProducer.hpp b/include/openpose/producer/wDatumProducer.hpp index 919b971d..f16871aa 100644 --- a/include/openpose/producer/wDatumProducer.hpp +++ b/include/openpose/producer/wDatumProducer.hpp @@ -9,21 +9,21 @@ namespace op { - template - class WDatumProducer : public WorkerProducer + template + class WDatumProducer : public WorkerProducer>>> { public: - explicit WDatumProducer(const std::shared_ptr>& datumProducer); + explicit WDatumProducer(const std::shared_ptr>& datumProducer); virtual ~WDatumProducer(); void initializationOnThread(); - TDatums workProducer(); + std::shared_ptr>> workProducer(); private: - std::shared_ptr> spDatumProducer; - std::queue mQueuedElements; + std::shared_ptr> spDatumProducer; + std::queue>>> mQueuedElements; DELETE_COPY(WDatumProducer); }; @@ -37,25 +37,26 @@ namespace op #include namespace op { - template - WDatumProducer::WDatumProducer(const std::shared_ptr>& datumProducer) : + template + WDatumProducer::WDatumProducer( + const std::shared_ptr>& datumProducer) : spDatumProducer{datumProducer} { } - template - WDatumProducer::~WDatumProducer() + template + WDatumProducer::~WDatumProducer() { } - template - void WDatumProducer::initializationOnThread() + template + void WDatumProducer::initializationOnThread() { } - template - TDatums WDatumProducer::workProducer() + template + std::shared_ptr>> WDatumProducer::workProducer() { try { @@ -63,8 +64,8 @@ namespace op dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__); // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); - // Create and fill TDatums - std::shared_ptr tDatums; + // Create and fill final shared pointer + std::shared_ptr>> tDatums; // Producer if (mQueuedElements.empty()) { @@ -80,17 +81,18 @@ namespace op dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__); } // Equivalent to WQueueSplitter - // Queued elements - Multiple views --> Split views into different TDatums + // Queued elements - Multiple views --> Split views into different share pointers if (tDatums != nullptr && tDatums->size() > 1) { // Add tDatums to mQueuedElements for (auto i = 0u ; i < tDatums->size() ; i++) { - auto& tDatum = (*tDatums)[i]; - tDatum.subId = i; - tDatum.subIdMax = tDatums->size()-1; + auto& tDatumPtr = (*tDatums)[i]; + tDatumPtr->subId = i; + tDatumPtr->subIdMax = tDatums->size()-1; mQueuedElements.emplace( - std::make_shared(TDatumsNoPtr{tDatum})); + std::make_shared>>( + std::vector>{tDatumPtr})); } } // Queued elements - Multiple views --> Return oldest view @@ -99,18 +101,18 @@ namespace op tDatums = mQueuedElements.front(); mQueuedElements.pop(); } - // Return TDatums + // Return result return tDatums; } catch (const std::exception& e) { this->stop(); error(e.what(), __LINE__, __FUNCTION__, __FILE__); - return TDatums{}; + return nullptr; } } - extern template class WDatumProducer; + extern template class WDatumProducer; } #endif // OPENPOSE_PRODUCER_W_DATUM_PRODUCER_HPP diff --git a/include/openpose/thread/queueBase.hpp b/include/openpose/thread/queueBase.hpp index 054d2782..50257185 100644 --- a/include/openpose/thread/queueBase.hpp +++ b/include/openpose/thread/queueBase.hpp @@ -514,8 +514,11 @@ namespace op } } - extern template class QueueBase>; - extern template class QueueBase, std::greater>>; + extern template class QueueBase>; + extern template class QueueBase< + BASE_DATUMS_SH, + std::priority_queue, + std::greater>>; } #endif // OPENPOSE_THREAD_QUEUE_BASE_HPP diff --git a/include/openpose/thread/wIdGenerator.hpp b/include/openpose/thread/wIdGenerator.hpp index 13ae78d1..63bba2bc 100644 --- a/include/openpose/thread/wIdGenerator.hpp +++ b/include/openpose/thread/wIdGenerator.hpp @@ -63,13 +63,13 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Add ID - for (auto& tDatum : *tDatums) + for (auto& tDatumPtr : *tDatums) // To avoid overwritting ID if e.g., custom input has already filled it - if (tDatum.id == std::numeric_limits::max()) - tDatum.id = mGlobalCounter; + if (tDatumPtr->id == std::numeric_limits::max()) + tDatumPtr->id = mGlobalCounter; // Increase ID - const auto& tDatum = (*tDatums)[0]; - if (tDatum.subId == tDatum.subIdMax) + const auto& tDatumPtr = (*tDatums)[0]; + if (tDatumPtr->subId == tDatumPtr->subIdMax) mGlobalCounter++; // Profiling speed Profiler::timerEnd(profilerKey); diff --git a/include/openpose/thread/wQueueAssembler.hpp b/include/openpose/thread/wQueueAssembler.hpp index 99472878..cf28d86f 100644 --- a/include/openpose/thread/wQueueAssembler.hpp +++ b/include/openpose/thread/wQueueAssembler.hpp @@ -13,8 +13,8 @@ namespace op // with the same GPU. In this way, this work is parallelized over GPUs (1 view for each). // Pros: Latency highly recuded, same speed // Cons: Requires these extra 2 classes and proper threads for them - template - class WQueueAssembler : public Worker + template + class WQueueAssembler : public Worker> { public: explicit WQueueAssembler(); @@ -23,10 +23,10 @@ namespace op void initializationOnThread(); - void work(TDatums& tDatums); + void work(std::shared_ptr& tDatums); private: - TDatums mNextTDatums; + std::shared_ptr mNextTDatums; DELETE_COPY(WQueueAssembler); }; @@ -39,23 +39,23 @@ namespace op // Implementation namespace op { - template - WQueueAssembler::WQueueAssembler() + template + WQueueAssembler::WQueueAssembler() { } - template - WQueueAssembler::~WQueueAssembler() + template + WQueueAssembler::~WQueueAssembler() { } - template - void WQueueAssembler::initializationOnThread() + template + void WQueueAssembler::initializationOnThread() { } - template - void WQueueAssembler::work(TDatums& tDatums) + template + void WQueueAssembler::work(std::shared_ptr& tDatums) { try { @@ -70,17 +70,17 @@ namespace op " was applied in the first place, i.e., that there is only 1 element" " per TDatums (size = " + std::to_string(tDatums->size()) + ").", __LINE__, __FUNCTION__, __FILE__); - auto tDatum = (*tDatums)[0]; + auto tDatumPtr = (*tDatums)[0]; // Single view --> Return - if (tDatum.subIdMax == 0) + if (tDatumPtr->subIdMax == 0) return; // Multiple view --> Merge views into different TDatums (1st frame) if (mNextTDatums == nullptr) - mNextTDatums = std::make_shared(); + mNextTDatums = std::make_shared(); // Multiple view --> Merge views into different TDatums - mNextTDatums->emplace_back(tDatum); + mNextTDatums->emplace_back(tDatumPtr); // Last view - Return frame - if (mNextTDatums->back().subId == mNextTDatums->back().subIdMax) + if (mNextTDatums->back()->subId == mNextTDatums->back()->subIdMax) { tDatums = mNextTDatums; mNextTDatums = nullptr; @@ -106,7 +106,7 @@ namespace op } } - extern template class WQueueAssembler; + extern template class WQueueAssembler; } #endif // OPENPOSE_THREAD_W_QUEUE_ASSEMBLER_HPP diff --git a/include/openpose/thread/wQueueOrderer.hpp b/include/openpose/thread/wQueueOrderer.hpp index 9ce0074e..cb002d57 100644 --- a/include/openpose/thread/wQueueOrderer.hpp +++ b/include/openpose/thread/wQueueOrderer.hpp @@ -73,16 +73,16 @@ namespace op // T* to T auto& tDatumsNoPtr = *tDatums; // tDatums is the next expected, update counter - if (tDatumsNoPtr[0].id == mNextExpectedId && tDatumsNoPtr[0].subId == mNextExpectedSubId) + if (tDatumsNoPtr[0]->id == mNextExpectedId && tDatumsNoPtr[0]->subId == mNextExpectedSubId) { // If single-view - if (tDatumsNoPtr[0].subIdMax == 0) + if (tDatumsNoPtr[0]->subIdMax == 0) mNextExpectedId++; // If muilti-view system else { mNextExpectedSubId++; - if (mNextExpectedSubId > tDatumsNoPtr[0].subIdMax) + if (mNextExpectedSubId > tDatumsNoPtr[0]->subIdMax) { mNextExpectedSubId = 0; mNextExpectedId++; @@ -109,8 +109,8 @@ namespace op // Retrieve frame if next is desired frame or if we want to stop this worker if (!mPriorityQueueBuffer.empty() && (mStopWhenEmpty || - ((*mPriorityQueueBuffer.top())[0].id == mNextExpectedId - && (*mPriorityQueueBuffer.top())[0].subId == mNextExpectedSubId))) + ((*mPriorityQueueBuffer.top())[0]->id == mNextExpectedId + && (*mPriorityQueueBuffer.top())[0]->subId == mNextExpectedSubId))) { tDatums = { mPriorityQueueBuffer.top() }; mPriorityQueueBuffer.pop(); @@ -121,16 +121,16 @@ namespace op { const auto& tDatumsNoPtr = *tDatums; // If single-view - if (tDatumsNoPtr[0].subIdMax == 0) - mNextExpectedId = tDatumsNoPtr[0].id + 1; + if (tDatumsNoPtr[0]->subIdMax == 0) + mNextExpectedId = tDatumsNoPtr[0]->id + 1; // If muilti-view system else { - mNextExpectedSubId = tDatumsNoPtr[0].subId + 1; - if (mNextExpectedSubId > tDatumsNoPtr[0].subIdMax) + mNextExpectedSubId = tDatumsNoPtr[0]->subId + 1; + if (mNextExpectedSubId > tDatumsNoPtr[0]->subIdMax) { mNextExpectedSubId = 0; - mNextExpectedId = tDatumsNoPtr[0].id + 1; + mNextExpectedId = tDatumsNoPtr[0]->id + 1; } } } diff --git a/include/openpose/tracking/wPersonIdExtractor.hpp b/include/openpose/tracking/wPersonIdExtractor.hpp index 80ecac3b..2079e2f7 100644 --- a/include/openpose/tracking/wPersonIdExtractor.hpp +++ b/include/openpose/tracking/wPersonIdExtractor.hpp @@ -62,8 +62,9 @@ namespace op // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Render people pose - for (auto& tDatum : *tDatums) - tDatum.poseIds = spPersonIdExtractor->extractIds(tDatum.poseKeypoints, tDatum.cvInputData); + for (auto& tDatumPtr : *tDatums) + tDatumPtr->poseIds = spPersonIdExtractor->extractIds( + tDatumPtr->poseKeypoints, tDatumPtr->cvInputData); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/wrapper/wrapper.hpp b/include/openpose/wrapper/wrapper.hpp index ff50dc8c..6f2811b3 100644 --- a/include/openpose/wrapper/wrapper.hpp +++ b/include/openpose/wrapper/wrapper.hpp @@ -29,7 +29,8 @@ namespace op * - Asynchronous input + synchronous output: call the constructor * WrapperT(ThreadManagerMode::Synchronous, nullptr, workersOutput, irrelevantBoolean, true) */ - template, + template>, typename TDatumsSP = std::shared_ptr, typename TWorker = std::shared_ptr>> class WrapperT @@ -216,7 +217,7 @@ namespace op }; // Type - typedef WrapperT Wrapper; + typedef WrapperT Wrapper; } @@ -227,16 +228,16 @@ namespace op #include namespace op { - template - WrapperT::WrapperT(const ThreadManagerMode threadManagerMode) : + template + WrapperT::WrapperT(const ThreadManagerMode threadManagerMode) : mThreadManagerMode{threadManagerMode}, mThreadManager{threadManagerMode}, mMultiThreadEnabled{true} { } - template - WrapperT::~WrapperT() + template + WrapperT::~WrapperT() { try { @@ -253,8 +254,8 @@ namespace op } } - template - void WrapperT::disableMultiThreading() + template + void WrapperT::disableMultiThreading() { try { @@ -266,8 +267,8 @@ namespace op } } - template - void WrapperT::setWorker( + template + void WrapperT::setWorker( const WorkerType workerType, const TWorker& worker, const bool workerOnNewThread) { try @@ -286,8 +287,8 @@ namespace op } } - template - void WrapperT::configure(const WrapperStructPose& wrapperStructPose) + template + void WrapperT::configure(const WrapperStructPose& wrapperStructPose) { try { @@ -299,8 +300,8 @@ namespace op } } - template - void WrapperT::configure(const WrapperStructFace& wrapperStructFace) + template + void WrapperT::configure(const WrapperStructFace& wrapperStructFace) { try { @@ -312,8 +313,8 @@ namespace op } } - template - void WrapperT::configure(const WrapperStructHand& wrapperStructHand) + template + void WrapperT::configure(const WrapperStructHand& wrapperStructHand) { try { @@ -325,8 +326,8 @@ namespace op } } - template - void WrapperT::configure(const WrapperStructExtra& wrapperStructExtra) + template + void WrapperT::configure(const WrapperStructExtra& wrapperStructExtra) { try { @@ -338,8 +339,8 @@ namespace op } } - template - void WrapperT::configure(const WrapperStructInput& wrapperStructInput) + template + void WrapperT::configure(const WrapperStructInput& wrapperStructInput) { try { @@ -351,8 +352,8 @@ namespace op } } - template - void WrapperT::configure(const WrapperStructOutput& wrapperStructOutput) + template + void WrapperT::configure(const WrapperStructOutput& wrapperStructOutput) { try { @@ -364,8 +365,8 @@ namespace op } } - template - void WrapperT::configure(const WrapperStructGui& wrapperStructGui) + template + void WrapperT::configure(const WrapperStructGui& wrapperStructGui) { try { @@ -377,12 +378,12 @@ namespace op } } - template - void WrapperT::exec() + template + void WrapperT::exec() { try { - configureThreadManager( + configureThreadManager( mThreadManager, mMultiThreadEnabled, mThreadManagerMode, mWrapperStructPose, mWrapperStructFace, mWrapperStructHand, mWrapperStructExtra, mWrapperStructInput, mWrapperStructOutput, mWrapperStructGui, mUserWs, mUserWsOnNewThread); @@ -395,12 +396,12 @@ namespace op } } - template - void WrapperT::start() + template + void WrapperT::start() { try { - configureThreadManager( + configureThreadManager( mThreadManager, mMultiThreadEnabled, mThreadManagerMode, mWrapperStructPose, mWrapperStructFace, mWrapperStructHand, mWrapperStructExtra, mWrapperStructInput, mWrapperStructOutput, mWrapperStructGui, mUserWs, mUserWsOnNewThread); @@ -413,8 +414,8 @@ namespace op } } - template - void WrapperT::stop() + template + void WrapperT::stop() { try { @@ -426,8 +427,8 @@ namespace op } } - template - bool WrapperT::isRunning() const + template + bool WrapperT::isRunning() const { try { @@ -440,8 +441,8 @@ namespace op } } - template - bool WrapperT::tryEmplace(TDatumsSP& tDatums) + template + bool WrapperT::tryEmplace(TDatumsSP& tDatums) { try { @@ -457,8 +458,8 @@ namespace op } } - template - bool WrapperT::waitAndEmplace(TDatumsSP& tDatums) + template + bool WrapperT::waitAndEmplace(TDatumsSP& tDatums) { try { @@ -474,8 +475,8 @@ namespace op } } - template - bool WrapperT::tryPush(const TDatumsSP& tDatums) + template + bool WrapperT::tryPush(const TDatumsSP& tDatums) { try { @@ -491,8 +492,8 @@ namespace op } } - template - bool WrapperT::waitAndPush(const TDatumsSP& tDatums) + template + bool WrapperT::waitAndPush(const TDatumsSP& tDatums) { try { @@ -508,8 +509,8 @@ namespace op } } - template - bool WrapperT::tryPop(TDatumsSP& tDatums) + template + bool WrapperT::tryPop(TDatumsSP& tDatums) { try { @@ -525,8 +526,8 @@ namespace op } } - template - bool WrapperT::waitAndPop(TDatumsSP& tDatums) + template + bool WrapperT::waitAndPop(TDatumsSP& tDatums) { try { @@ -542,8 +543,8 @@ namespace op } } - template - bool WrapperT::emplaceAndPop(TDatumsSP& tDatums) + template + bool WrapperT::emplaceAndPop(TDatumsSP& tDatums) { try { @@ -559,17 +560,18 @@ namespace op } } - template - TDatumsSP WrapperT::emplaceAndPop(const cv::Mat& cvMat) + template + TDatumsSP WrapperT::emplaceAndPop(const cv::Mat& cvMat) { try { // Create new datum - auto datumsPtr = std::make_shared(); + auto datumsPtr = std::make_shared>>(); datumsPtr->emplace_back(); - auto& datum = datumsPtr->at(0); + auto& tDatumPtr = datumsPtr->at(0); + tDatumPtr = std::make_shared(); // Fill datum - datum.cvInputData = cvMat; + tDatumPtr->cvInputData = cvMat; // Emplace and pop emplaceAndPop(datumsPtr); // Return result @@ -582,7 +584,7 @@ namespace op } } - extern template class WrapperT; + extern template class WrapperT; } #endif // OPENPOSE_WRAPPER_WRAPPER_HPP diff --git a/include/openpose/wrapper/wrapperAuxiliary.hpp b/include/openpose/wrapper/wrapperAuxiliary.hpp index a07c9e45..209b8cfc 100644 --- a/include/openpose/wrapper/wrapperAuxiliary.hpp +++ b/include/openpose/wrapper/wrapperAuxiliary.hpp @@ -49,7 +49,8 @@ namespace op * and adds them. * Common code for start() and exec(). */ - template>, typename TDatumsSP = std::shared_ptr, typename TWorker = std::shared_ptr>> void configureThreadManager( @@ -81,7 +82,7 @@ namespace op #include namespace op { - template + template void configureThreadManager( ThreadManager& threadManager, const bool multiThreadEnabledTemp, const ThreadManagerMode threadManagerMode, const WrapperStructPose& wrapperStructPoseTemp, @@ -210,11 +211,11 @@ namespace op TWorker datumProducerW; if (oPProducer) { - const auto datumProducer = std::make_shared>( + const auto datumProducer = std::make_shared>( producerSharedPtr, wrapperStructInput.frameFirst, wrapperStructInput.frameStep, wrapperStructInput.frameLast, spVideoSeek ); - datumProducerW = std::make_shared>(datumProducer); + datumProducerW = std::make_shared>(datumProducer); } else datumProducerW = nullptr; @@ -931,7 +932,7 @@ namespace op } } // Assemble all frames from same time instant (3-D module) - const auto wQueueAssembler = std::make_shared>(); + const auto wQueueAssembler = std::make_shared>(); // 3-D reconstruction if (!poseTriangulationsWs.empty()) { diff --git a/scripts/ubuntu/Makefile.example b/scripts/ubuntu/Makefile.example index 27eb4fda..3cacc833 100644 --- a/scripts/ubuntu/Makefile.example +++ b/scripts/ubuntu/Makefile.example @@ -109,6 +109,7 @@ endif WITH_EIGEN ?= 0 ifneq ($(WITH_EIGEN), 0) COMMON_FLAGS += -DUSE_EIGEN + INCLUDE_DIRS += $(EIGEN_DIR) endif # Spinnaker SDK WITH_FLIR_CAMERA ?= 0 diff --git a/src/openpose/producer/defineTemplates.cpp b/src/openpose/producer/defineTemplates.cpp index 81880b21..a8153036 100644 --- a/src/openpose/producer/defineTemplates.cpp +++ b/src/openpose/producer/defineTemplates.cpp @@ -2,6 +2,6 @@ namespace op { - template class OP_API DatumProducer; - template class OP_API WDatumProducer; + template class OP_API DatumProducer; + template class OP_API WDatumProducer; } diff --git a/src/openpose/thread/defineTemplates.cpp b/src/openpose/thread/defineTemplates.cpp index 9ff32c1e..0fdc47fb 100644 --- a/src/openpose/thread/defineTemplates.cpp +++ b/src/openpose/thread/defineTemplates.cpp @@ -5,8 +5,11 @@ namespace op // Queues DEFINE_TEMPLATE_DATUM(PriorityQueue); DEFINE_TEMPLATE_DATUM(Queue); - template class OP_API QueueBase>; - template class OP_API QueueBase, std::greater>>; + template class OP_API QueueBase>; + template class OP_API QueueBase< + BASE_DATUMS_SH, + std::priority_queue, + std::greater>>; // Subthread DEFINE_TEMPLATE_DATUM(SubThread); DEFINE_TEMPLATE_DATUM(SubThreadNoQueue); @@ -23,6 +26,6 @@ namespace op // W-classes DEFINE_TEMPLATE_DATUM(WFpsMax); DEFINE_TEMPLATE_DATUM(WIdGenerator); - template class OP_API WQueueAssembler; + template class OP_API WQueueAssembler; DEFINE_TEMPLATE_DATUM(WQueueOrderer); } diff --git a/src/openpose/wrapper/defineTemplates.cpp b/src/openpose/wrapper/defineTemplates.cpp index 986e95c3..082fd6da 100644 --- a/src/openpose/wrapper/defineTemplates.cpp +++ b/src/openpose/wrapper/defineTemplates.cpp @@ -2,5 +2,5 @@ namespace op { - template class OP_API WrapperT; + template class OP_API WrapperT; }