From e8ec52e94ef7e8ae32d5f9eb1567be829407ecba Mon Sep 17 00:00:00 2001 From: gineshidalgo99 Date: Mon, 29 Jan 2018 15:25:33 -0500 Subject: [PATCH] Fixed CPU pose renderer/GUI core dumped --- doc/installation_deprecated.md | 4 +-- doc/openpose_3d_reconstruction_demo.md | 2 +- doc/release_notes.md | 1 + include/openpose/face/faceParameters.hpp | 1 + include/openpose/hand/handParameters.hpp | 1 + include/openpose/pose/poseCpuRenderer.hpp | 5 ++-- include/openpose/pose/poseParameters.hpp | 1 - .../openpose/pose/poseParametersRender.hpp | 1 + include/openpose/pose/renderPose.hpp | 2 +- include/openpose/utilities/errorAndLog.hpp | 21 +++++++++----- include/openpose/wrapper/wrapper.hpp | 7 +++-- .../openpose/wrapper/wrapperStructPose.hpp | 1 + src/openpose/core/renderer.cpp | 5 ++++ src/openpose/hand/handCpuRenderer.cpp | 3 +- src/openpose/pose/poseCpuRenderer.cpp | 5 ++-- src/openpose/pose/poseGpuRenderer.cpp | 3 +- src/openpose/pose/poseParameters.cpp | 1 + src/openpose/pose/poseParametersRender.cpp | 15 ++++++++++ src/openpose/utilities/errorAndLog.cpp | 29 ++++++++++++------- 19 files changed, 76 insertions(+), 32 deletions(-) diff --git a/doc/installation_deprecated.md b/doc/installation_deprecated.md index 00b11a57..2d0a1b35 100644 --- a/doc/installation_deprecated.md +++ b/doc/installation_deprecated.md @@ -56,7 +56,7 @@ Build Caffe & the OpenPose library + download the required Caffe models for Ubun ```bash bash ./ubuntu/install_caffe_and_openpose_if_cuda8.sh ``` -**Highly important**: This script only works with CUDA 8 and Ubuntu 14 or 16. Otherwise, see [doc/installation_cmake.md](installation_cmake.md) or [Installation - Manual Compilation](#installation---manual-compilation). +**Highly important**: This script only works with CUDA 8 and Ubuntu 14 or 16. Otherwise, see [doc/installation.md](installation.md) or [Installation - Manual Compilation](#installation---manual-compilation). @@ -126,7 +126,7 @@ You just need to remove the OpenPose folder, by default called `openpose/`. E.g. 3. [**cuDNN 5.1**](https://developer.nvidia.com/cudnn): Once you have downloaded it, just unzip it and copy (merge) the contents on the CUDA folder, `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0`. #### CMake Installer -Recommended installation method, it is simpler and offers more customization settings. See [doc/installation_cmake.md](installation_cmake.md). Note that it is a beta version, post in GitHub any issue you find. +Recommended installation method, it is simpler and offers more customization settings. See [doc/installation.md](installation.md). Note that it is a beta version, post in GitHub any issue you find. #### Deprecated Windows Installer diff --git a/doc/openpose_3d_reconstruction_demo.md b/doc/openpose_3d_reconstruction_demo.md index 1826fb99..cef76561 100644 --- a/doc/openpose_3d_reconstruction_demo.md +++ b/doc/openpose_3d_reconstruction_demo.md @@ -56,7 +56,7 @@ In order to verify that the camera parameters introduced by the user are sorted ## Installing the OpenPose 3-D Reconstruction Module -Check the [doc/installation_cmake.md#openpose-3d-reconstruction-module-and-demo](./installation_cmake.md#openpose-3d-reconstruction-module-and-demo) instructions. +Check the [doc/installation.md#openpose-3d-reconstruction-module-and-demo](./installation.md#openpose-3d-reconstruction-module-and-demo) instructions. diff --git a/doc/release_notes.md b/doc/release_notes.md index e97eabe1..0ab3c79d 100644 --- a/doc/release_notes.md +++ b/doc/release_notes.md @@ -182,6 +182,7 @@ OpenPose Library - Release Notes 10. 3-D Reconstruction demo cleaned, implemented in Ubuntu too, and now defined as experimental module of OpenPose rather than just a demo. 2. Main bugs fixed: 1. Slight speed up (~1%) for performing the non-maximum suppression stage only in the body part heatmaps channels, and not also in the PAF channels. + 2. Fixed core-dumped in PoseRenderer with GUI when changed element to be rendered to something else than skeleton. diff --git a/include/openpose/face/faceParameters.hpp b/include/openpose/face/faceParameters.hpp index 42eb1b62..a5f1141d 100644 --- a/include/openpose/face/faceParameters.hpp +++ b/include/openpose/face/faceParameters.hpp @@ -2,6 +2,7 @@ #define OPENPOSE_FACE_FACE_PARAMETERS_HPP #include +#include namespace op { diff --git a/include/openpose/hand/handParameters.hpp b/include/openpose/hand/handParameters.hpp index 9cf6f206..a131be94 100644 --- a/include/openpose/hand/handParameters.hpp +++ b/include/openpose/hand/handParameters.hpp @@ -2,6 +2,7 @@ #define OPENPOSE_HAND_HAND_PARAMETERS_HPP #include +#include namespace op { diff --git a/include/openpose/pose/poseCpuRenderer.hpp b/include/openpose/pose/poseCpuRenderer.hpp index 0e6695fc..7d65fc0b 100644 --- a/include/openpose/pose/poseCpuRenderer.hpp +++ b/include/openpose/pose/poseCpuRenderer.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include namespace op @@ -15,7 +15,8 @@ namespace op public: PoseCpuRenderer(const PoseModel poseModel, const float renderThreshold, const bool blendOriginalFrame = true, const float alphaKeypoint = POSE_DEFAULT_ALPHA_KEYPOINT, - const float alphaHeatMap = POSE_DEFAULT_ALPHA_HEAT_MAP); + const float alphaHeatMap = POSE_DEFAULT_ALPHA_HEAT_MAP, + const unsigned int elementToRender = 0u); std::pair renderPose(Array& outputData, const Array& poseKeypoints, const float scaleInputToOutput, diff --git a/include/openpose/pose/poseParameters.hpp b/include/openpose/pose/poseParameters.hpp index 20245264..7eb89b53 100644 --- a/include/openpose/pose/poseParameters.hpp +++ b/include/openpose/pose/poseParameters.hpp @@ -4,7 +4,6 @@ #include #include #include -#include namespace op { diff --git a/include/openpose/pose/poseParametersRender.hpp b/include/openpose/pose/poseParametersRender.hpp index a1f53479..7bd85acf 100644 --- a/include/openpose/pose/poseParametersRender.hpp +++ b/include/openpose/pose/poseParametersRender.hpp @@ -200,6 +200,7 @@ namespace op OP_API const std::vector& getPoseScales(const PoseModel poseModel); OP_API const std::vector& getPoseColors(const PoseModel poseModel); OP_API const std::vector& getPoseBodyPartPairsRender(const PoseModel poseModel); + OP_API unsigned int getNumberElementsToRender(const PoseModel poseModel); } #endif // OPENPOSE_POSE_POSE_PARAMETERS_RENDER_HPP diff --git a/include/openpose/pose/renderPose.hpp b/include/openpose/pose/renderPose.hpp index 5891b53f..860dad64 100644 --- a/include/openpose/pose/renderPose.hpp +++ b/include/openpose/pose/renderPose.hpp @@ -4,7 +4,7 @@ #include // cv::Mat #include #include -#include +#include namespace op { diff --git a/include/openpose/utilities/errorAndLog.hpp b/include/openpose/utilities/errorAndLog.hpp index 74df3860..1fe63f00 100644 --- a/include/openpose/utilities/errorAndLog.hpp +++ b/include/openpose/utilities/errorAndLog.hpp @@ -23,28 +23,35 @@ namespace op // Error managment - How to use: // error(message, __LINE__, __FUNCTION__, __FILE__); - OP_API void error(const std::string& message, const int line = -1, const std::string& function = "", const std::string& file = ""); + OP_API void error(const std::string& message, const int line = -1, const std::string& function = "", + const std::string& file = ""); template - inline void error(const T& message, const int line = -1, const std::string& function = "", const std::string& file = "") + inline void error(const T& message, const int line = -1, const std::string& function = "", + const std::string& file = "") { error(tToString(message), line, function, file); } // Printing info - How to use: - // log(message, desiredPriority, __LINE__, __FUNCTION__, __FILE__); // It will print info if desiredPriority >= sPriorityThreshold - OP_API void log(const std::string& message, const Priority priority = Priority::Max, const int line = -1, const std::string& function = "", const std::string& file = ""); + // It will print info if desiredPriority >= sPriorityThreshold + // log(message, desiredPriority, __LINE__, __FUNCTION__, __FILE__); + OP_API void log(const std::string& message, const Priority priority = Priority::Max, const int line = -1, + const std::string& function = "", const std::string& file = ""); template - inline void log(const T& message, const Priority priority = Priority::Max, const int line = -1, const std::string& function = "", const std::string& file = "") + inline void log(const T& message, const Priority priority = Priority::Max, const int line = -1, + const std::string& function = "", const std::string& file = "") { log(tToString(message), priority, line, function, file); } // If only desired on debug mode (no computational cost at all on release mode): - // dLog(message, desiredPriority, __LINE__, __FUNCTION__, __FILE__); // It will print info if desiredPriority >= sPriorityThreshold + // It will print info if desiredPriority >= sPriorityThreshold + // dLog(message, desiredPriority, __LINE__, __FUNCTION__, __FILE__); template - inline void dLog(const T& message, const Priority priority = Priority::Max, const int line = -1, const std::string& function = "", const std::string& file = "") + inline void dLog(const T& message, const Priority priority = Priority::Max, const int line = -1, + const std::string& function = "", const std::string& file = "") { #ifndef NDEBUG log(message, priority, line, function, file); diff --git a/include/openpose/wrapper/wrapper.hpp b/include/openpose/wrapper/wrapper.hpp index 6171d996..a15f0da2 100644 --- a/include/openpose/wrapper/wrapper.hpp +++ b/include/openpose/wrapper/wrapper.hpp @@ -665,9 +665,10 @@ namespace op // CPU rendering if (wrapperStructPose.renderMode == RenderMode::Cpu) { - poseCpuRenderer = std::make_shared(wrapperStructPose.poseModel, - wrapperStructPose.renderThreshold, - wrapperStructPose.blendOriginalFrame); + poseCpuRenderer = std::make_shared( + wrapperStructPose.poseModel, wrapperStructPose.renderThreshold, + wrapperStructPose.blendOriginalFrame, alphaKeypoint, alphaHeatMap, + wrapperStructPose.defaultPartToRender); cpuRenderers.emplace_back(std::make_shared>(poseCpuRenderer)); } } diff --git a/include/openpose/wrapper/wrapperStructPose.hpp b/include/openpose/wrapper/wrapperStructPose.hpp index dbe7c4b0..cc3274c5 100644 --- a/include/openpose/wrapper/wrapperStructPose.hpp +++ b/include/openpose/wrapper/wrapperStructPose.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace op { diff --git a/src/openpose/core/renderer.cpp b/src/openpose/core/renderer.cpp index d2720f99..85e9bf00 100644 --- a/src/openpose/core/renderer.cpp +++ b/src/openpose/core/renderer.cpp @@ -19,6 +19,11 @@ namespace op { try { + // Security checks + if (*spNumberElementsToRender == 0) + error("Number elements to render cannot be 0 for this function.", + __LINE__, __FUNCTION__, __FILE__); + // Get current element to be rendered auto elementToRender = (((int)(*spElementToRender) + increment) % (int)(*spNumberElementsToRender)); // Handling negative increments while (elementToRender < 0) diff --git a/src/openpose/hand/handCpuRenderer.cpp b/src/openpose/hand/handCpuRenderer.cpp index d3ad5069..0f780c4d 100644 --- a/src/openpose/hand/handCpuRenderer.cpp +++ b/src/openpose/hand/handCpuRenderer.cpp @@ -17,7 +17,8 @@ namespace op if (outputData.empty()) error("Empty Array outputData.", __LINE__, __FUNCTION__, __FILE__); if (handKeypoints[0].getSize(0) != handKeypoints[1].getSize(0)) - error("Wrong hand format: handKeypoints.getSize(0) != handKeypoints.getSize(1).", __LINE__, __FUNCTION__, __FILE__); + error("Wrong hand format: handKeypoints.getSize(0) != handKeypoints.getSize(1).", + __LINE__, __FUNCTION__, __FILE__); // CPU rendering renderHandKeypointsCpu(outputData, handKeypoints, mRenderThreshold); } diff --git a/src/openpose/pose/poseCpuRenderer.cpp b/src/openpose/pose/poseCpuRenderer.cpp index 18ad9e16..cde813e8 100644 --- a/src/openpose/pose/poseCpuRenderer.cpp +++ b/src/openpose/pose/poseCpuRenderer.cpp @@ -6,8 +6,9 @@ namespace op { PoseCpuRenderer::PoseCpuRenderer(const PoseModel poseModel, const float renderThreshold, const bool blendOriginalFrame, const float alphaKeypoint, - const float alphaHeatMap) : - Renderer{renderThreshold, alphaKeypoint, alphaHeatMap, blendOriginalFrame}, + const float alphaHeatMap, const unsigned int elementToRender) : + Renderer{renderThreshold, alphaKeypoint, alphaHeatMap, blendOriginalFrame, elementToRender, + getNumberElementsToRender(poseModel)}, // mNumberElementsToRender PoseRenderer{poseModel} { } diff --git a/src/openpose/pose/poseGpuRenderer.cpp b/src/openpose/pose/poseGpuRenderer.cpp index ca6d2f1b..dfce1daf 100644 --- a/src/openpose/pose/poseGpuRenderer.cpp +++ b/src/openpose/pose/poseGpuRenderer.cpp @@ -18,8 +18,7 @@ namespace op // + 3 (+whole pose +whole heatmaps +PAFs) // POSE_BODY_PART_MAPPING crashes on Windows, replaced by getPoseBodyPartMapping GpuRenderer{renderThreshold, alphaKeypoint, alphaHeatMap, blendOriginalFrame, elementToRender, - (unsigned int)(getPoseBodyPartMapping(poseModel).size() - + getPosePartPairs(poseModel).size()/2 + 3)}, // mNumberElementsToRender + getNumberElementsToRender(poseModel)}, // mNumberElementsToRender PoseRenderer{poseModel}, spPoseExtractor{poseExtractor}, pGpuPose{nullptr} diff --git a/src/openpose/pose/poseParameters.cpp b/src/openpose/pose/poseParameters.cpp index ac85228a..b19a53c0 100644 --- a/src/openpose/pose/poseParameters.cpp +++ b/src/openpose/pose/poseParameters.cpp @@ -1,3 +1,4 @@ +#include #include namespace op diff --git a/src/openpose/pose/poseParametersRender.cpp b/src/openpose/pose/poseParametersRender.cpp index edf1536c..b8d660dd 100644 --- a/src/openpose/pose/poseParametersRender.cpp +++ b/src/openpose/pose/poseParametersRender.cpp @@ -1,3 +1,4 @@ +#include #include namespace op @@ -69,4 +70,18 @@ namespace op return POSE_BODY_PART_PAIRS_RENDER[(int)poseModel]; } } + + unsigned int getNumberElementsToRender(const PoseModel poseModel) + { + try + { + return (unsigned int)(getPoseBodyPartMapping(poseModel).size() + + getPosePartPairs(poseModel).size()/2 + 3); + } + catch (const std::exception& e) + { + error(e.what(), __LINE__, __FUNCTION__, __FILE__); + return 0u; + } + } } diff --git a/src/openpose/utilities/errorAndLog.cpp b/src/openpose/utilities/errorAndLog.cpp index 8cff2247..3ee677ca 100644 --- a/src/openpose/utilities/errorAndLog.cpp +++ b/src/openpose/utilities/errorAndLog.cpp @@ -23,8 +23,8 @@ namespace op return false; } - std::string createFullMessage(const std::string& message, const int line = -1, const std::string& function = "", const std::string& file = "") - // std::string createFullMessage(const std::string& message, const int line, const std::string& function, const std::string& file) + std::string createFullMessage(const std::string& message, const int line = -1, const std::string& function = "", + const std::string& file = "") { const auto hasMessage = (!message.empty()); const auto hasLocation = (line != -1 || !function.empty() || !file.empty()); @@ -34,10 +34,14 @@ namespace op if (hasMessage) { fullMessage += message; - // // Add dot at the end if the sentence does not finish in a programming file path (this happens when the error is propagated over several error) + // // Add dot at the end if the sentence does not finish in a programming file path (this happens when the + // error is propagated over several error) // if (*message.crbegin() != '.' // && (message.size() < 4 - // || (message.substr(message.size() - 4, 4) != ".cpp" && message.substr(message.size() - 4, 4) != ".hpp" && message.substr(message.size() - 4, 4) != ".h" && message.substr(message.size() - 4, 4) != ".c"))) + // || (message.substr(message.size() - 4, 4) != ".cpp" + // && message.substr(message.size() - 4, 4) != ".hpp" + // && message.substr(message.size() - 4, 4) != ".h" + // && message.substr(message.size() - 4, 4) != ".c"))) // fullMessage += "."; if (hasLocation) @@ -74,8 +78,9 @@ namespace op // Common timeStruct.tm_mon++; timeStruct.tm_year += 1900; - return std::to_string(timeStruct.tm_year) + '_' + std::to_string(timeStruct.tm_mon) + '_' + std::to_string(timeStruct.tm_mday) + "___" - + std::to_string(timeStruct.tm_hour) + '_' + std::to_string(timeStruct.tm_min) + '_' + std::to_string(timeStruct.tm_sec); + return std::to_string(timeStruct.tm_year) + '_' + std::to_string(timeStruct.tm_mon) + + '_' + std::to_string(timeStruct.tm_mday) + "___" + std::to_string(timeStruct.tm_hour) + + '_' + std::to_string(timeStruct.tm_min) + '_' + std::to_string(timeStruct.tm_sec); } void fileLogging(const std::string& message) @@ -89,7 +94,8 @@ namespace op // Continue at the end of the file or delete it and re-write it (according to current file size) const auto maxLogSize = 15 * 1024 * 1024; // 15 MB - std::ofstream loggingFile{fileToOpen, (currentSizeBytes < maxLogSize ? std::ios_base::app : std::ios_base::trunc)}; + std::ofstream loggingFile{fileToOpen, + (currentSizeBytes < maxLogSize ? std::ios_base::app : std::ios_base::trunc)}; // Message to write loggingFile << getTime(); @@ -116,14 +122,16 @@ namespace op // If first error if (message.size() < errorInit.size() || message.substr(0, errorInit.size()) != errorInit) { - errorMessageToPrint = errorInit + createFullMessage(message) + "\n\nComing from:\n" + errorEnum + createFullMessage("", line, function, file); + errorMessageToPrint = errorInit + createFullMessage(message) + "\n\nComing from:\n" + errorEnum + + createFullMessage("", line, function, file); errorMessageToPropagate = errorMessageToPrint + "\n"; } // If error propagated among different errors else { errorMessageToPrint = errorEnum + createFullMessage("", line, function, file); - errorMessageToPropagate = createFullMessage(message.substr(0, message.size()-1)) + "\n" + errorMessageToPrint + "\n"; + errorMessageToPropagate = createFullMessage(message.substr(0, message.size()-1)) + "\n" + + errorMessageToPrint + "\n"; } // std::cerr @@ -139,7 +147,8 @@ namespace op throw std::runtime_error{errorMessageToPropagate}; } - void log(const std::string& message, const Priority priority, const int line, const std::string& function, const std::string& file) + void log(const std::string& message, const Priority priority, const int line, const std::string& function, + const std::string& file) { if (priority >= ConfigureLog::getPriorityThreshold()) { -- GitLab