diff --git a/doc/release_notes.md b/doc/release_notes.md index c346c2ba5dc1fbff17df493bb21ad289b74049e3..41accb8eaf3bbf646fdd5cf82049d9ce1eb36324 100644 --- a/doc/release_notes.md +++ b/doc/release_notes.md @@ -122,7 +122,7 @@ OpenPose Library - Release Notes 3. CvMatToOutput and Renderers allow to keep input resolution as output for images (core module). 3. New standalone face keypoint detector based on OpenCV face detector: much faster if body keypoint detection is not required but much less accurate. 4. Face and hand keypoint detectors now can return each keypoint heatmap. - 5. The flag `USE_CUDNN` is no longer required; `USE_CAFFE` and `USE_CUDA` (replacing the old `CPU_ONLY`) are no longer required to use the library, only to build it. In addition, Caffe and its dependencies have been removed from the OpenPose header files. Only OpenCV include and lib folders are required when building a project using OpenPose. + 5. The flag `USE_CUDNN` is no longer required; `USE_CAFFE` and `USE_CUDA` (replacing the old `CPU_ONLY`) are no longer required to use the library, only to build it. In addition, Boost, Caffe, and its dependencies have been removed from the OpenPose header files. Only OpenCV include and lib folders are required when building a project using OpenPose. 6. OpenPose successfully compiles if the flags `USE_CAFFE` and/or `USE_CUDA` are not enabled, although it will give an error saying they are required. 7. COCO JSON file outputs 0 as score for non-detected keypoints. 8. Added example for OpenPose for user asynchronous output and cleaned all `tutorial_wrapper/` examples. diff --git a/include/openpose/core/array.hpp b/include/openpose/core/array.hpp index c0cbcd5f7aad0fe77217c881bc3d2fbc93306713..e71cca837d7d85f9c79bd40dcbb5a8cfd9f0f439 100644 --- a/include/openpose/core/array.hpp +++ b/include/openpose/core/array.hpp @@ -1,9 +1,9 @@ #ifndef OPENPOSE_CORE_ARRAY_HPP #define OPENPOSE_CORE_ARRAY_HPP +#include // std::shared_ptr #include #include // cv::Mat -#include // Note: std::shared_ptr not (fully) supported for array pointers: http://stackoverflow.com/questions/8947579/ namespace op { @@ -241,7 +241,7 @@ namespace op inline T& operator[](const int index) { #ifdef NDEBUG - return spData[index]; + return spData.get()[index]; #else return at(index); #endif @@ -256,7 +256,7 @@ namespace op inline const T& operator[](const int index) const { #ifdef NDEBUG - return spData[index]; + return spData.get()[index]; #else return at(index); #endif @@ -346,7 +346,7 @@ namespace op private: std::vector mSize; size_t mVolume; - boost::shared_ptr spData; + std::shared_ptr spData; std::pair mCvMatData; /** diff --git a/src/openpose/core/array.cpp b/src/openpose/core/array.cpp index b24bf51ccba88275737ceaf00d249e991870619c..059f6c9d332bc15fe5218b7ccb80e40331073d06 100644 --- a/src/openpose/core/array.cpp +++ b/src/openpose/core/array.cpp @@ -4,6 +4,17 @@ #include #include +// Note: std::shared_ptr not (fully) supported for array pointers: +// http://stackoverflow.com/questions/8947579/ +// Solutions: +// 1) Using boost::shared_ptr from : Very easy but requires Boost. +// 2) Using std::unique_ptr from : Same behaviour than 1, but only `unique`. +// 3) Using std::shared_ptr from : Harder to use, but benefits of 1 & 2. Solutions to its problems: +// a) Accessing elements: +// https://stackoverflow.com/questions/30780262/accessing-array-of-shared-ptr +// b) Default delete: +// https://stackoverflow.com/questions/13061979/shared-ptr-to-an-array-should-it-be-used + namespace op { template @@ -167,7 +178,7 @@ namespace op mSize = sizes; mVolume = {std::accumulate(sizes.begin(), sizes.end(), 1ul, std::multiplies())}; // Prepare shared_ptr - spData.reset(new T[mVolume]); + spData.reset(new T[mVolume], std::default_delete()); setCvMatFromSharedPtr(); } else @@ -324,7 +335,8 @@ namespace op try { if (!mCvMatData.first) - error("Array: cv::Mat functions only valid for T types defined by OpenCV: unsigned char, signed char, int, float & double", __LINE__, __FUNCTION__, __FILE__); + error("Array: cv::Mat functions only valid for T types defined by OpenCV: unsigned char," + " signed char, int, float & double", __LINE__, __FUNCTION__, __FILE__); return mCvMatData.second; } catch (const std::exception& e) @@ -340,7 +352,8 @@ namespace op try { if (!mCvMatData.first) - error("Array: cv::Mat functions only valid for T types defined by OpenCV: unsigned char, signed char, int, float & double", __LINE__, __FUNCTION__, __FILE__); + error("Array: cv::Mat functions only valid for T types defined by OpenCV: unsigned char," + " signed char, int, float & double", __LINE__, __FUNCTION__, __FILE__); return mCvMatData.second; } catch (const std::exception& e) @@ -358,14 +371,16 @@ namespace op // Initial value std::string string{"Array::toString():\n"}; // Add each element + auto* dataPtr = spData.get(); for (auto i = 0u ; i < mVolume ; i++) { // Adding element sepearted by an space - string += std::to_string(spData[i]) + " "; + string += std::to_string(dataPtr[i]) + " "; // Introduce an enter for each dimension change // If comented, all values will be printed in the same line auto multiplier = 1; - for (auto dimension = (int)(mSize.size() - 1u) ; dimension > 0 && (int(i/multiplier) % getSize(dimension) == getSize(dimension)-1) ; dimension--) + for (auto dimension = (int)(mSize.size() - 1u) ; dimension > 0 + && (int(i/multiplier) % getSize(dimension) == getSize(dimension)-1) ; dimension--) { string += "\n"; multiplier *= getSize(dimension); @@ -424,17 +439,17 @@ namespace op try { if (0 <= index && (size_t)index < mVolume) - return spData[index]; + return spData.get()[index]; else { error("Index out of bounds: 0 <= index && index < mVolume", __LINE__, __FUNCTION__, __FILE__); - return spData[0]; + return spData.get()[0]; } } catch (const std::exception& e) { error(e.what(), __LINE__, __FUNCTION__, __FILE__); - return spData[0]; + return spData.get()[0]; } } @@ -460,7 +475,7 @@ namespace op mCvMatData.first = false; if (mCvMatData.first) - mCvMatData.second = cv::Mat((int)mSize.size(), mSize.data(), cvFormat, spData.get()); + mCvMatData.second = cv::Mat((int)mSize.size(), mSize.data(), cvFormat, spData.get()[0]); else mCvMatData.second = cv::Mat(); }