From 4e455b280e31c675a4364f6a3e81385da1e1b046 Mon Sep 17 00:00:00 2001 From: gineshidalgo99 Date: Wed, 31 Jan 2018 15:32:10 -0500 Subject: [PATCH] GPU moved to gpu module --- doc/installation.md | 2 +- examples/tests/wrapperHandFromJsonTest.hpp | 2 +- include/openpose/{utilities => gpu}/cuda.hpp | 8 +- include/openpose/{utilities => gpu}/cuda.hu | 6 +- include/openpose/gpu/enumClasses.hpp | 15 ++ include/openpose/gpu/gpu.hpp | 14 + include/openpose/gpu/headers.hpp | 9 + include/openpose/utilities/headers.hpp | 1 - include/openpose/wrapper/headers.hpp | 1 + include/openpose/wrapper/wrapper.hpp | 96 +------ include/openpose/wrapper/wrapperAuxiliary.hpp | 33 +++ src/openpose/core/maximumBase.cu | 4 +- src/openpose/core/netCaffe.cpp | 2 +- src/openpose/core/nmsBase.cu | 4 +- src/openpose/core/resizeAndMergeBase.cu | 4 +- .../experimental/3d/cameraParameters.cpp | 240 +++++++++--------- src/openpose/experimental/3d/renderer.cpp | 1 + src/openpose/face/faceExtractorCaffe.cpp | 2 +- src/openpose/face/faceGpuRenderer.cpp | 2 +- src/openpose/face/renderFace.cu | 4 +- src/openpose/gpu/CMakeLists.txt | 24 ++ src/openpose/{utilities => gpu}/cuda.cpp | 4 +- src/openpose/gpu/gpu.cpp | 50 ++++ src/openpose/hand/handExtractorCaffe.cpp | 2 +- src/openpose/hand/handGpuRenderer.cpp | 2 +- src/openpose/hand/renderHand.cu | 4 +- src/openpose/pose/bodyPartConnectorBase.cu | 4 +- src/openpose/pose/poseExtractorCaffe.cpp | 2 +- src/openpose/pose/poseGpuRenderer.cpp | 4 +- src/openpose/pose/renderPose.cu | 4 +- src/openpose/utilities/CMakeLists.txt | 3 +- src/openpose/wrapper/CMakeLists.txt | 1 + src/openpose/wrapper/wrapperAuxiliary.cpp | 116 +++++++++ 33 files changed, 424 insertions(+), 246 deletions(-) rename include/openpose/{utilities => gpu}/cuda.hpp (82%) rename include/openpose/{utilities => gpu}/cuda.hu (97%) create mode 100644 include/openpose/gpu/enumClasses.hpp create mode 100644 include/openpose/gpu/gpu.hpp create mode 100644 include/openpose/gpu/headers.hpp create mode 100644 include/openpose/wrapper/wrapperAuxiliary.hpp create mode 100644 src/openpose/gpu/CMakeLists.txt rename src/openpose/{utilities => gpu}/cuda.cpp (98%) create mode 100644 src/openpose/gpu/gpu.cpp create mode 100644 src/openpose/wrapper/wrapperAuxiliary.cpp diff --git a/doc/installation.md b/doc/installation.md index 87ef82ae..750bd3e6 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -205,7 +205,7 @@ You can include the 3D reconstruction module by: - Copy `Spinnaker_v140.lib` and `Spinnakerd_v140.lib` from `{PointGreyParentDirectory}\Point Grey Research\Spinnaker\lib64\vs2015\` into `{OpenPoseDirectory}\3rdparty\windows\spinnaker\lib\`. - (Optional) Spinnaker SDK overview: [https://www.ptgrey.com/spinnaker-sdk](https://www.ptgrey.com/spinnaker-sdk). 2. Install the 3D visualizer, FreeGLUT: - 1. Ubuntu: run `sudo apt-get install freeglut3 freeglut3-dev`. + 1. Ubuntu: run `sudo apt-get install freeglut3 freeglut3-dev libxmu-dev libxi-dev`. 2. Windows: 1. It is automatically downloaded by the CMake installer. 2. Alternatively, if you prefer to download it yourself, you could either: diff --git a/examples/tests/wrapperHandFromJsonTest.hpp b/examples/tests/wrapperHandFromJsonTest.hpp index 9e227b53..bb259599 100644 --- a/examples/tests/wrapperHandFromJsonTest.hpp +++ b/examples/tests/wrapperHandFromJsonTest.hpp @@ -87,10 +87,10 @@ namespace op #include #include #include +#include #include #include #include -#include #include #include namespace op diff --git a/include/openpose/utilities/cuda.hpp b/include/openpose/gpu/cuda.hpp similarity index 82% rename from include/openpose/utilities/cuda.hpp rename to include/openpose/gpu/cuda.hpp index 15563fbd..7fc7420f 100644 --- a/include/openpose/utilities/cuda.hpp +++ b/include/openpose/gpu/cuda.hpp @@ -1,5 +1,5 @@ -#ifndef OPENPOSE_UTILITIES_CUDA_HPP -#define OPENPOSE_UTILITIES_CUDA_HPP +#ifndef OPENPOSE_GPU_CUDA_HPP +#define OPENPOSE_GPU_CUDA_HPP #include // std::pair #include @@ -10,7 +10,7 @@ namespace op OP_API void cudaCheck(const int line = -1, const std::string& function = "", const std::string& file = ""); - OP_API int getGpuNumber(); + OP_API int getCudaGpuNumber(); inline unsigned int getNumberCudaBlocks(const unsigned int totalRequired, const unsigned int numberCudaThreads = CUDA_NUM_THREADS) @@ -22,4 +22,4 @@ namespace op const Point& frameSize); } -#endif // OPENPOSE_UTILITIES_CUDA_HPP +#endif // OPENPOSE_GPU_CUDA_HPP diff --git a/include/openpose/utilities/cuda.hu b/include/openpose/gpu/cuda.hu similarity index 97% rename from include/openpose/utilities/cuda.hu rename to include/openpose/gpu/cuda.hu index 5e060006..4d41da4b 100644 --- a/include/openpose/utilities/cuda.hu +++ b/include/openpose/gpu/cuda.hu @@ -1,5 +1,5 @@ -#ifndef OPENPOSE_UTILITIES_CUDA_HU -#define OPENPOSE_UTILITIES_CUDA_HU +#ifndef OPENPOSE_GPU_CUDA_HU +#define OPENPOSE_GPU_CUDA_HU namespace op { @@ -147,4 +147,4 @@ namespace op } } -#endif // OPENPOSE_UTILITIES_CUDA_HU +#endif // OPENPOSE_GPU_CUDA_HU diff --git a/include/openpose/gpu/enumClasses.hpp b/include/openpose/gpu/enumClasses.hpp new file mode 100644 index 00000000..59e7282f --- /dev/null +++ b/include/openpose/gpu/enumClasses.hpp @@ -0,0 +1,15 @@ +#ifndef OPENPOSE_GPU_ENUM_CLASSES_HPP +#define OPENPOSE_GPU_ENUM_CLASSES_HPP + +namespace op +{ + enum class GpuMode : unsigned char + { + CUDA = 0, + OPEN_CL = 1, + CPU_ONLY = 2, + Size, + }; +} + +#endif // OPENPOSE_GPU_ENUM_CLASSES_HPP diff --git a/include/openpose/gpu/gpu.hpp b/include/openpose/gpu/gpu.hpp new file mode 100644 index 00000000..76c65568 --- /dev/null +++ b/include/openpose/gpu/gpu.hpp @@ -0,0 +1,14 @@ +#ifndef OPENPOSE_GPU_GPU_HPP +#define OPENPOSE_GPU_GPU_HPP + +#include +#include + +namespace op +{ + OP_API int getGpuNumber(); + + OP_API GpuMode getGpuMode(); +} + +#endif // OPENPOSE_GPU_GPU_HPP diff --git a/include/openpose/gpu/headers.hpp b/include/openpose/gpu/headers.hpp new file mode 100644 index 00000000..231ca8b6 --- /dev/null +++ b/include/openpose/gpu/headers.hpp @@ -0,0 +1,9 @@ +#ifndef OPENPOSE_GPU_HEADERS_HPP +#define OPENPOSE_GPU_HEADERS_HPP + +// gpu module +#include +#include +#include + +#endif // OPENPOSE_GPU_HEADERS_HPP diff --git a/include/openpose/utilities/headers.hpp b/include/openpose/utilities/headers.hpp index ae91070a..34bdc415 100644 --- a/include/openpose/utilities/headers.hpp +++ b/include/openpose/utilities/headers.hpp @@ -3,7 +3,6 @@ // utilities module #include -#include #include #include #include diff --git a/include/openpose/wrapper/headers.hpp b/include/openpose/wrapper/headers.hpp index bece720b..3c4b6e45 100644 --- a/include/openpose/wrapper/headers.hpp +++ b/include/openpose/wrapper/headers.hpp @@ -3,6 +3,7 @@ // wrapper module #include +#include #include #include #include diff --git a/include/openpose/wrapper/wrapper.hpp b/include/openpose/wrapper/wrapper.hpp index a15f0da2..6c5a29d3 100644 --- a/include/openpose/wrapper/wrapper.hpp +++ b/include/openpose/wrapper/wrapper.hpp @@ -260,16 +260,17 @@ namespace op // Implementation #include +#include #include #include #include +#include #include #include #include -#include -#include #include #include +#include namespace op { template @@ -447,94 +448,9 @@ namespace op const auto renderHandGpu = wrapperStructHand.enable && wrapperStructHand.renderMode == RenderMode::Gpu; // Check no wrong/contradictory flags enabled - if (wrapperStructPose.alphaKeypoint < 0. || wrapperStructPose.alphaKeypoint > 1. - || wrapperStructFace.alphaHeatMap < 0. || wrapperStructFace.alphaHeatMap > 1. - || wrapperStructHand.alphaHeatMap < 0. || wrapperStructHand.alphaHeatMap > 1.) - error("Alpha value for blending must be in the range [0,1].", __LINE__, __FUNCTION__, __FILE__); - if (wrapperStructPose.scaleGap <= 0.f && wrapperStructPose.scalesNumber > 1) - error("The scale gap must be greater than 0 (it has no effect if the number of scales is 1).", - __LINE__, __FUNCTION__, __FILE__); - if (!renderOutput && (!wrapperStructOutput.writeImages.empty() || !wrapperStructOutput.writeVideo.empty())) - { - const auto message = "In order to save the rendered frames (`--write_images` or `--write_video`), you" - " cannot disable `--render_pose`."; - log(message, Priority::High); - } - if (!wrapperStructOutput.writeHeatMaps.empty() && wrapperStructPose.heatMapTypes.empty()) - { - const auto message = "In order to save the heatmaps (`--write_heatmaps`), you need to pick which heat" - " maps you want to save: `--heatmaps_add_X` flags or fill the" - " wrapperStructPose.heatMapTypes."; - error(message, __LINE__, __FUNCTION__, __FILE__); - } - if (!wrapperStructOutput.writeHeatMaps.empty() - && (wrapperStructPose.heatMapScale != ScaleMode::UnsignedChar && - wrapperStructOutput.writeHeatMapsFormat != "float")) - { - const auto message = "In order to save the heatmaps, you must either set" - " wrapperStructPose.heatMapScale to ScaleMode::UnsignedChar (i.e. range [0, 255])" - " or `--write_heatmaps_format` to `float` to storage floating numbers in binary" - " mode."; - error(message, __LINE__, __FUNCTION__, __FILE__); - } - if (mUserOutputWs.empty() && mThreadManagerMode != ThreadManagerMode::Asynchronous - && mThreadManagerMode != ThreadManagerMode::AsynchronousOut) - { - const std::string additionalMessage{ - " You could also set mThreadManagerMode = mThreadManagerMode::Asynchronous(Out) and/or add your" - " own output worker class before calling this function." - }; - const auto savingSomething = ( - !wrapperStructOutput.writeImages.empty() || !wrapperStructOutput.writeVideo.empty() - || !wrapperStructOutput.writeKeypoint.empty() || !wrapperStructOutput.writeJson.empty() - || !wrapperStructOutput.writeCocoJson.empty() || !wrapperStructOutput.writeHeatMaps.empty() - ); - if (!wrapperStructOutput.displayGui && !savingSomething) - { - const auto message = "No output is selected (`--no_display`) and no results are generated (no" - " `--write_X` flags enabled). Thus, no output would be generated." - + additionalMessage; - error(message, __LINE__, __FUNCTION__, __FILE__); - } - if (wrapperStructInput.framesRepeat && savingSomething) - { - const auto message = "Frames repetition (`--frames_repeat`) is enabled as well as some writing" - " function (`--write_X`). This program would never stop recording the same" - " frames over and over. Please, disable repetition or remove writing."; - error(message, __LINE__, __FUNCTION__, __FILE__); - } - // Warnings - if ((wrapperStructOutput.displayGui && wrapperStructOutput.guiVerbose) && !renderOutput) - { - const auto message = "No render is enabled (e.g. `--render_pose 0`), so you might also want to" - " remove the display (set `--no_display` or `--no_gui_verbose`). If you" - " simply want to use OpenPose to record video/images without keypoints, you" - " only need to set `--num_gpu 0`." + additionalMessage; - log(message, Priority::High); - } - if (wrapperStructInput.realTimeProcessing && savingSomething) - { - const auto message = "Real time processing is enabled as well as some writing function. Thus, some" - " frames might be skipped. Consider disabling real time processing if you" - " intend to save any results."; - log(message, Priority::High); - } - } - if (!wrapperStructOutput.writeVideo.empty() && wrapperStructInput.producerSharedPtr == nullptr) - error("Writting video is only available if the OpenPose producer is used (i.e." - " wrapperStructInput.producerSharedPtr cannot be a nullptr).", __LINE__, __FUNCTION__, __FILE__); - if (!wrapperStructPose.enable) - { - if (!wrapperStructFace.enable) - error("Body keypoint detection must be enabled.", __LINE__, __FUNCTION__, __FILE__); - if (wrapperStructHand.enable) - error("Body keypoint detection must be enabled in order to run hand keypoint detection.", - __LINE__, __FUNCTION__, __FILE__); - } - #ifdef CPU_ONLY - if (wrapperStructPose.gpuNumber > 0) - error("GPU number must be negative or 0 if CPU_ONLY is enabled.", __LINE__, __FUNCTION__, __FILE__); - #endif + const auto userOutputWsEmpty = mUserOutputWs.empty(); + wrapperConfigureSecurityChecks(wrapperStructPose, wrapperStructFace, wrapperStructHand, wrapperStructInput, + wrapperStructOutput, renderOutput, userOutputWsEmpty, mThreadManagerMode); // Get number threads // CPU --> 1 thread or no pose extraction diff --git a/include/openpose/wrapper/wrapperAuxiliary.hpp b/include/openpose/wrapper/wrapperAuxiliary.hpp new file mode 100644 index 00000000..004b0562 --- /dev/null +++ b/include/openpose/wrapper/wrapperAuxiliary.hpp @@ -0,0 +1,33 @@ +#ifndef OPENPOSE_WRAPPER_AUXILIARY_HPP +#define OPENPOSE_WRAPPER_AUXILIARY_HPP + +#include +#include +#include +#include +#include + +namespace op +{ + /** + * It checks that no wrong/contradictory flags are enabled for Wrapper + * @param wrapperStructPose + * @param wrapperStructFace + * @param wrapperStructHand + * @param wrapperStructInput + * @param wrapperStructOutput + * @param renderOutput + * @param userOutputWsEmpty + * @param threadManagerMode + */ + void wrapperConfigureSecurityChecks(const WrapperStructPose& wrapperStructPose, + const WrapperStructFace& wrapperStructFace, + const WrapperStructHand& wrapperStructHand, + const WrapperStructInput& wrapperStructInput, + const WrapperStructOutput& wrapperStructOutput, + const bool renderOutput, + const bool userOutputWsEmpty, + const ThreadManagerMode threadManagerMode); +} + +#endif // OPENPOSE_WRAPPER_AUXILIARY_HPP diff --git a/src/openpose/core/maximumBase.cu b/src/openpose/core/maximumBase.cu index 78796312..90e04cfb 100644 --- a/src/openpose/core/maximumBase.cu +++ b/src/openpose/core/maximumBase.cu @@ -1,7 +1,7 @@ #include #include -#include -#include +#include +#include #include namespace op diff --git a/src/openpose/core/netCaffe.cpp b/src/openpose/core/netCaffe.cpp index 1452c41f..efe13b22 100644 --- a/src/openpose/core/netCaffe.cpp +++ b/src/openpose/core/netCaffe.cpp @@ -5,7 +5,7 @@ #include #include // google::InitGoogleLogging #endif -#include +#include #include #include #include diff --git a/src/openpose/core/nmsBase.cu b/src/openpose/core/nmsBase.cu index c864d1eb..5000d222 100644 --- a/src/openpose/core/nmsBase.cu +++ b/src/openpose/core/nmsBase.cu @@ -1,7 +1,7 @@ #include #include -#include -#include +#include +#include #include namespace op diff --git a/src/openpose/core/resizeAndMergeBase.cu b/src/openpose/core/resizeAndMergeBase.cu index b819de88..026e2f89 100644 --- a/src/openpose/core/resizeAndMergeBase.cu +++ b/src/openpose/core/resizeAndMergeBase.cu @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include namespace op diff --git a/src/openpose/experimental/3d/cameraParameters.cpp b/src/openpose/experimental/3d/cameraParameters.cpp index 0a98ca8b..15faf462 100644 --- a/src/openpose/experimental/3d/cameraParameters.cpp +++ b/src/openpose/experimental/3d/cameraParameters.cpp @@ -4,133 +4,133 @@ namespace op { - // User configurable code - // Intrinsic and distortion parameters - // Camera 1 parameters - const cv::Mat INTRINSIC_1 = (cv::Mat_(3, 3) << 817.93481631740565, 0, 600.70689997785121, - 0, 816.51774059837908, 517.84529566329593, - 0, 0, 1); - const cv::Mat DISTORTION_1 = (cv::Mat_(8, 1) << - -1.8102158829399091, 9.1966147162623262, -0.00044293900343777355, 0.0013638377686816653, 1.3303863414979364, -1.418905163635487, 8.4725535468475819, 4.7911023525901033); - // Camera 2 parameters - const cv::Mat INTRINSIC_2 = (cv::Mat_(3, 3) << 816.20921132436638, 0, 612.67087968681585, - 0, 816.18292222910486, 530.47901782670431, - 0, 0, 1); - const cv::Mat DISTORTION_2 = (cv::Mat_(8, 1) << - -5.1088507540294881, 133.63995617304997, -0.0010048069080912836, 0.00018825291386406282, 20.688286893903879, -4.7604289550474768, 132.42412342224557, 70.01195364029752); - const cv::Mat INTRINSIC_3 = (cv::Mat_(3, 3) << 798.42980806905666, 0, 646.48130011561727, - 0, 798.46535448393979, 523.91590563194586, - 0, 0, 1); - // Camera 3 - const cv::Mat DISTORTION_3 = (cv::Mat_(8, 1) << - -0.57530495294002304, -0.54721992620722582, -0.00037614702677289967, -0.00081995658363481598, -0.020321660897680775, -0.18040544059116842, -0.87724444571603022, -0.13136636671099691); + // User configurable code + // Intrinsic and distortion parameters + // Camera 1 parameters + const cv::Mat INTRINSIC_1 = (cv::Mat_(3, 3) << 817.93481631740565, 0, 600.70689997785121, + 0, 816.51774059837908, 517.84529566329593, + 0, 0, 1); + const cv::Mat DISTORTION_1 = (cv::Mat_(8, 1) << + -1.8102158829399091, 9.1966147162623262, -0.00044293900343777355, 0.0013638377686816653, 1.3303863414979364, -1.418905163635487, 8.4725535468475819, 4.7911023525901033); + // Camera 2 parameters + const cv::Mat INTRINSIC_2 = (cv::Mat_(3, 3) << 816.20921132436638, 0, 612.67087968681585, + 0, 816.18292222910486, 530.47901782670431, + 0, 0, 1); + const cv::Mat DISTORTION_2 = (cv::Mat_(8, 1) << + -5.1088507540294881, 133.63995617304997, -0.0010048069080912836, 0.00018825291386406282, 20.688286893903879, -4.7604289550474768, 132.42412342224557, 70.01195364029752); + const cv::Mat INTRINSIC_3 = (cv::Mat_(3, 3) << 798.42980806905666, 0, 646.48130011561727, + 0, 798.46535448393979, 523.91590563194586, + 0, 0, 1); + // Camera 3 + const cv::Mat DISTORTION_3 = (cv::Mat_(8, 1) << + -0.57530495294002304, -0.54721992620722582, -0.00037614702677289967, -0.00081995658363481598, -0.020321660897680775, -0.18040544059116842, -0.87724444571603022, -0.13136636671099691); - // Extrinsic parameters - rotation and pose orientation between cameras - // Camera 1 - const cv::Mat M_1_1 = (cv::Mat_(3, 4) << 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0); - // Not working on Windows - // const cv::Mat M_1_1 = cv::Mat::eye(3, 4, CV_64F); - // From camera 1 to 2 - const cv::Mat M_1_2 = (cv::Mat_(3, 4) << 0.999962504862692, -0.00165862051503619, 0.00849928507093793, -238.301309354482, - 0.00176155163779584, 0.999925029704659, -0.0121174215889211, 4.75863886121558, - -0.00847854967298925, 0.0121319391740716, 0.999890459124058, 15.9219925821916); - // From camera 1 to 3 - const cv::Mat M_1_3 = (cv::Mat_(3, 4) << 0.995809442124071, -0.000473104796892308, 0.0914512501193800, -461.301274485705, - 0.00165046455210419, 0.999916727562850, -0.0127989806923977, 6.22648121362088, - -0.0914375794917412, 0.0128962828696210, 0.995727299487585, 63.4911132860733); - // From camera 2 to 3 - const cv::Mat M_2_3 = (cv::Mat_(3, 4) << 0.999644115423621, -0.00194501088674130, -0.0266056278177532, -235.236375502202, - 0.00201646110733780, 0.999994431880356, 0.00265896462686206, 9.52238656728889, - 0.0266003079592876, -0.00271166755609303, 0.999642471324391, -4.23534963077479); + // Extrinsic parameters - rotation and pose orientation between cameras + // Camera 1 + const cv::Mat M_1_1 = (cv::Mat_(3, 4) << 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0); + // Not working on Windows + // const cv::Mat M_1_1 = cv::Mat::eye(3, 4, CV_64F); + // From camera 1 to 2 + const cv::Mat M_1_2 = (cv::Mat_(3, 4) << 0.999962504862692, -0.00165862051503619, 0.00849928507093793, -238.301309354482, + 0.00176155163779584, 0.999925029704659, -0.0121174215889211, 4.75863886121558, + -0.00847854967298925, 0.0121319391740716, 0.999890459124058, 15.9219925821916); + // From camera 1 to 3 + const cv::Mat M_1_3 = (cv::Mat_(3, 4) << 0.995809442124071, -0.000473104796892308, 0.0914512501193800, -461.301274485705, + 0.00165046455210419, 0.999916727562850, -0.0127989806923977, 6.22648121362088, + -0.0914375794917412, 0.0128962828696210, 0.995727299487585, 63.4911132860733); + // From camera 2 to 3 + const cv::Mat M_2_3 = (cv::Mat_(3, 4) << 0.999644115423621, -0.00194501088674130, -0.0266056278177532, -235.236375502202, + 0.00201646110733780, 0.999994431880356, 0.00265896462686206, 9.52238656728889, + 0.0266003079592876, -0.00271166755609303, 0.999642471324391, -4.23534963077479); - // Do not modify this code - const std::vector INTRINSICS{ INTRINSIC_1, INTRINSIC_2, INTRINSIC_3 }; - const std::vector DISTORTIONS{ DISTORTION_1, DISTORTION_2, DISTORTION_3 }; + // Do not modify this code + const std::vector INTRINSICS{ INTRINSIC_1, INTRINSIC_2, INTRINSIC_3 }; + const std::vector DISTORTIONS{ DISTORTION_1, DISTORTION_2, DISTORTION_3 }; const std::vector M{ M_1_1, M_1_2, M_1_3 }; - // Not working on Windows - // const std::vector M_EACH_CAMERA{ - // INTRINSIC_1 * M_1_1, - // INTRINSIC_2 * M_1_2, - // INTRINSIC_3 * M_1_3 - // }; + // Not working on Windows + // const std::vector M_EACH_CAMERA{ + // INTRINSIC_1 * M_1_1, + // INTRINSIC_2 * M_1_2, + // INTRINSIC_3 * M_1_3 + // }; - const cv::Mat getIntrinsics(const int cameraIndex) - { - try - { - return INTRINSICS[cameraIndex]; - } - catch (const std::exception& e) - { - error(e.what(), __LINE__, __FUNCTION__, __FILE__); - return cv::Mat{}; - } - } + const cv::Mat getIntrinsics(const int cameraIndex) + { + try + { + return INTRINSICS[cameraIndex]; + } + catch (const std::exception& e) + { + error(e.what(), __LINE__, __FUNCTION__, __FILE__); + return cv::Mat{}; + } + } - const cv::Mat getDistorsion(const int cameraIndex) - { - try - { - return DISTORTIONS[cameraIndex]; - } - catch (const std::exception& e) - { - error(e.what(), __LINE__, __FUNCTION__, __FILE__); - return cv::Mat{}; - } - } + const cv::Mat getDistorsion(const int cameraIndex) + { + try + { + return DISTORTIONS[cameraIndex]; + } + catch (const std::exception& e) + { + error(e.what(), __LINE__, __FUNCTION__, __FILE__); + return cv::Mat{}; + } + } - const cv::Mat getM(const int cameraIndex) - { - try - { - return INTRINSICS[cameraIndex] * M[cameraIndex]; - // return M_EACH_CAMERA[cameraIndex]; - } - catch (const std::exception& e) - { - error(e.what(), __LINE__, __FUNCTION__, __FILE__); - return cv::Mat{}; - } - } - std::vector getMs() - { - try - { - // Security checks - if (INTRINSICS.size() != DISTORTIONS.size()) - error("The INTRINSICS and DISTORTIONS vector should have the same size.", - __LINE__, __FUNCTION__, __FILE__); - if (INTRINSICS.size() != M.size()) - error("The INTRINSICS and M_EACH_CAMERA vector should have the same size.", - __LINE__, __FUNCTION__, __FILE__); + const cv::Mat getM(const int cameraIndex) + { + try + { + return INTRINSICS[cameraIndex] * M[cameraIndex]; + // return M_EACH_CAMERA[cameraIndex]; + } + catch (const std::exception& e) + { + error(e.what(), __LINE__, __FUNCTION__, __FILE__); + return cv::Mat{}; + } + } + std::vector getMs() + { + try + { + // Security checks + if (INTRINSICS.size() != DISTORTIONS.size()) + error("The INTRINSICS and DISTORTIONS vector should have the same size.", + __LINE__, __FUNCTION__, __FILE__); + if (INTRINSICS.size() != M.size()) + error("The INTRINSICS and M_EACH_CAMERA vector should have the same size.", + __LINE__, __FUNCTION__, __FILE__); - std::vector result(INTRINSICS.size()); - for (auto i = 0u ; i < result.size(); i++) - result[i] = getM(i); - return result; - // return M_EACH_CAMERA; - } - catch (const std::exception& e) - { - error(e.what(), __LINE__, __FUNCTION__, __FILE__); - return{}; - } - } - unsigned long long getNumberCameras() - { - try - { - return INTRINSICS.size(); - } - catch (const std::exception& e) - { - error(e.what(), __LINE__, __FUNCTION__, __FILE__); - return 0; - } - } + std::vector result(INTRINSICS.size()); + for (auto i = 0u ; i < result.size(); i++) + result[i] = getM(i); + return result; + // return M_EACH_CAMERA; + } + catch (const std::exception& e) + { + error(e.what(), __LINE__, __FUNCTION__, __FILE__); + return{}; + } + } + unsigned long long getNumberCameras() + { + try + { + return INTRINSICS.size(); + } + catch (const std::exception& e) + { + error(e.what(), __LINE__, __FUNCTION__, __FILE__); + return 0; + } + } } diff --git a/src/openpose/experimental/3d/renderer.cpp b/src/openpose/experimental/3d/renderer.cpp index 8aab8e81..738947aa 100644 --- a/src/openpose/experimental/3d/renderer.cpp +++ b/src/openpose/experimental/3d/renderer.cpp @@ -388,6 +388,7 @@ namespace op // glutSetOption(GLUT_MULTISAMPLE,8); // Ideally adding also GLUT_BORDERLESS | GLUT_CAPTIONLESS should fix the problem of disabling the `x` // button, but it does not work (tested in Ubuntu) + // https://stackoverflow.com/questions/3799803/is-it-possible-to-make-a-window-withouth-a-top-in-glut glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); // create and set up a window diff --git a/src/openpose/face/faceExtractorCaffe.cpp b/src/openpose/face/faceExtractorCaffe.cpp index 236a8e50..90dffe59 100644 --- a/src/openpose/face/faceExtractorCaffe.cpp +++ b/src/openpose/face/faceExtractorCaffe.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/openpose/face/faceGpuRenderer.cpp b/src/openpose/face/faceGpuRenderer.cpp index 2248f3d2..c9f70891 100644 --- a/src/openpose/face/faceGpuRenderer.cpp +++ b/src/openpose/face/faceGpuRenderer.cpp @@ -3,7 +3,7 @@ #include #endif #include -#include +#include #include namespace op diff --git a/src/openpose/face/renderFace.cu b/src/openpose/face/renderFace.cu index 0d555e12..7a4d0602 100644 --- a/src/openpose/face/renderFace.cu +++ b/src/openpose/face/renderFace.cu @@ -1,6 +1,6 @@ #include -#include -#include +#include +#include #include #include diff --git a/src/openpose/gpu/CMakeLists.txt b/src/openpose/gpu/CMakeLists.txt new file mode 100644 index 00000000..70240d28 --- /dev/null +++ b/src/openpose/gpu/CMakeLists.txt @@ -0,0 +1,24 @@ +set(SOURCES_OP_GPU + cuda.cpp + gpu.cpp) + +include(${CMAKE_SOURCE_DIR}/cmake/Utils.cmake) +prepend(SOURCES_OP_GPU_WITH_CP ${CMAKE_CURRENT_SOURCE_DIR} ${SOURCES_OP_GPU}) +set(SOURCES_OP_GPU_WITH_CP ${SOURCES_OP_GPU_WITH_CP} PARENT_SCOPE) +set(SOURCES_OPENPOSE ${SOURCES_OPENPOSE} ${SOURCES_OP_GPU_WITH_CP} PARENT_SCOPE) + +if (UNIX AND NOT APPLE) + if (${GPU_MODE} MATCHES "CUDA") + cuda_add_library(openpose_gpu ${SOURCES_OP_GPU}) + else() + add_library(openpose_gpu ${SOURCES_OP_GPU}) + endif () + + # target_link_libraries(openpose_gpu openpose_core) + + install(TARGETS openpose_gpu + EXPORT OpenPose + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/openpose) +endif (UNIX AND NOT APPLE) diff --git a/src/openpose/utilities/cuda.cpp b/src/openpose/gpu/cuda.cpp similarity index 98% rename from src/openpose/utilities/cuda.cpp rename to src/openpose/gpu/cuda.cpp index 58d25cb6..6cb277d5 100644 --- a/src/openpose/utilities/cuda.cpp +++ b/src/openpose/gpu/cuda.cpp @@ -3,7 +3,7 @@ #include #include #endif -#include +#include namespace op { @@ -38,7 +38,7 @@ namespace op } } - int getGpuNumber() + int getCudaGpuNumber() { try { diff --git a/src/openpose/gpu/gpu.cpp b/src/openpose/gpu/gpu.cpp new file mode 100644 index 00000000..cc7fc141 --- /dev/null +++ b/src/openpose/gpu/gpu.cpp @@ -0,0 +1,50 @@ +#ifdef USE_CUDA + #include +#endif +#ifdef USE_OPENCL + #include +#endif +#include + +namespace op +{ + int getGpuNumber() + { + try + { + #ifdef USE_CUDA + return getCudaGpuNumber(); + #elif defined USE_OPENCL + return CLManager::getTotalGPU(); + #else + error("OpenPose must be compiled with the `USE_CUDA` or `USE_OPENCL` macro definition in order to use" + " this functionality.", __LINE__, __FUNCTION__, __FILE__); + return -1; + #endif + } + catch (const std::exception& e) + { + error(e.what(), __LINE__, __FUNCTION__, __FILE__); + return -1; + } + } + + GpuMode getGpuMode() + { + try + { + #ifdef USE_CUDA + return GpuMode::CUDA; + #elif defined USE_OPENCL + return GpuMode::OPEN_CL; + #else + return GpuMode::CPU_ONLY; + #endif + } + catch (const std::exception& e) + { + error(e.what(), __LINE__, __FUNCTION__, __FILE__); + return GpuMode::CPU_ONLY; + } + } +} diff --git a/src/openpose/hand/handExtractorCaffe.cpp b/src/openpose/hand/handExtractorCaffe.cpp index c0d2a466..27507964 100644 --- a/src/openpose/hand/handExtractorCaffe.cpp +++ b/src/openpose/hand/handExtractorCaffe.cpp @@ -5,8 +5,8 @@ #include #include #include +#include #include -#include #include #include #include diff --git a/src/openpose/hand/handGpuRenderer.cpp b/src/openpose/hand/handGpuRenderer.cpp index 5ece2859..eb707ba6 100644 --- a/src/openpose/hand/handGpuRenderer.cpp +++ b/src/openpose/hand/handGpuRenderer.cpp @@ -2,8 +2,8 @@ #include #include #endif +#include #include -#include #include namespace op diff --git a/src/openpose/hand/renderHand.cu b/src/openpose/hand/renderHand.cu index 60f89f28..4f9e74d9 100644 --- a/src/openpose/hand/renderHand.cu +++ b/src/openpose/hand/renderHand.cu @@ -1,6 +1,6 @@ +#include +#include #include -#include -#include #include #include diff --git a/src/openpose/pose/bodyPartConnectorBase.cu b/src/openpose/pose/bodyPartConnectorBase.cu index 893c719e..8d0c3e9f 100644 --- a/src/openpose/pose/bodyPartConnectorBase.cu +++ b/src/openpose/pose/bodyPartConnectorBase.cu @@ -1,7 +1,7 @@ +#include +#include #include -#include #include -#include #include namespace op diff --git a/src/openpose/pose/poseExtractorCaffe.cpp b/src/openpose/pose/poseExtractorCaffe.cpp index f03c4c2d..7c0db144 100644 --- a/src/openpose/pose/poseExtractorCaffe.cpp +++ b/src/openpose/pose/poseExtractorCaffe.cpp @@ -4,10 +4,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include diff --git a/src/openpose/pose/poseGpuRenderer.cpp b/src/openpose/pose/poseGpuRenderer.cpp index dfce1daf..16ce2434 100644 --- a/src/openpose/pose/poseGpuRenderer.cpp +++ b/src/openpose/pose/poseGpuRenderer.cpp @@ -4,7 +4,7 @@ #endif #include #include -#include +#include #include #include @@ -152,9 +152,9 @@ namespace op gpuToCpuMemoryIfLastRenderer(outputData.getPtr(), outputData.getVolume()); cudaCheck(__LINE__, __FUNCTION__, __FILE__); #else - UNUSED(elementRendered); UNUSED(outputData); UNUSED(poseKeypoints); + UNUSED(scaleInputToOutput); UNUSED(scaleNetToOutput); error("OpenPose must be compiled with the `USE_CUDA` macro definitions in order to run this" " functionality. You can alternatively use CPU rendering (flag `--render_pose 1`).", diff --git a/src/openpose/pose/renderPose.cu b/src/openpose/pose/renderPose.cu index b6ddfb15..6341beed 100644 --- a/src/openpose/pose/renderPose.cu +++ b/src/openpose/pose/renderPose.cu @@ -1,6 +1,6 @@ +#include +#include #include -#include -#include #include #include diff --git a/src/openpose/utilities/CMakeLists.txt b/src/openpose/utilities/CMakeLists.txt index 08e8e7cc..d18cc8d5 100644 --- a/src/openpose/utilities/CMakeLists.txt +++ b/src/openpose/utilities/CMakeLists.txt @@ -1,5 +1,4 @@ -set(SOURCES_OP_UTILITIES - cuda.cpp +set(SOURCES_OP_UTILITIES errorAndLog.cpp fileSystem.cpp flagsToOpenPose.cpp diff --git a/src/openpose/wrapper/CMakeLists.txt b/src/openpose/wrapper/CMakeLists.txt index 23d3b25f..89b709e1 100644 --- a/src/openpose/wrapper/CMakeLists.txt +++ b/src/openpose/wrapper/CMakeLists.txt @@ -1,5 +1,6 @@ set(SOURCES_OP_WRAPPER defineTemplates.cpp + wrapperAuxiliary.cpp wrapperStructFace.cpp wrapperStructHand.cpp wrapperStructInput.cpp diff --git a/src/openpose/wrapper/wrapperAuxiliary.cpp b/src/openpose/wrapper/wrapperAuxiliary.cpp new file mode 100644 index 00000000..2c8a4208 --- /dev/null +++ b/src/openpose/wrapper/wrapperAuxiliary.cpp @@ -0,0 +1,116 @@ +#include +#include + +namespace op +{ + void wrapperConfigureSecurityChecks(const WrapperStructPose& wrapperStructPose, + const WrapperStructFace& wrapperStructFace, + const WrapperStructHand& wrapperStructHand, + const WrapperStructInput& wrapperStructInput, + const WrapperStructOutput& wrapperStructOutput, + const bool renderOutput, + const bool userOutputWsEmpty, + const ThreadManagerMode threadManagerMode) + { + try + { + log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__); + + // Check no wrong/contradictory flags enabled + if (wrapperStructPose.alphaKeypoint < 0. || wrapperStructPose.alphaKeypoint > 1. + || wrapperStructFace.alphaHeatMap < 0. || wrapperStructFace.alphaHeatMap > 1. + || wrapperStructHand.alphaHeatMap < 0. || wrapperStructHand.alphaHeatMap > 1.) + error("Alpha value for blending must be in the range [0,1].", __LINE__, __FUNCTION__, __FILE__); + if (wrapperStructPose.scaleGap <= 0.f && wrapperStructPose.scalesNumber > 1) + error("The scale gap must be greater than 0 (it has no effect if the number of scales is 1).", + __LINE__, __FUNCTION__, __FILE__); + if (!renderOutput && (!wrapperStructOutput.writeImages.empty() || !wrapperStructOutput.writeVideo.empty())) + { + const auto message = "In order to save the rendered frames (`--write_images` or `--write_video`), you" + " cannot disable `--render_pose`."; + log(message, Priority::High); + } + if (!wrapperStructOutput.writeHeatMaps.empty() && wrapperStructPose.heatMapTypes.empty()) + { + const auto message = "In order to save the heatmaps (`--write_heatmaps`), you need to pick which heat" + " maps you want to save: `--heatmaps_add_X` flags or fill the" + " wrapperStructPose.heatMapTypes."; + error(message, __LINE__, __FUNCTION__, __FILE__); + } + if (!wrapperStructOutput.writeHeatMaps.empty() + && (wrapperStructPose.heatMapScale != ScaleMode::UnsignedChar && + wrapperStructOutput.writeHeatMapsFormat != "float")) + { + const auto message = "In order to save the heatmaps, you must either set" + " wrapperStructPose.heatMapScale to ScaleMode::UnsignedChar (i.e. range [0, 255])" + " or `--write_heatmaps_format` to `float` to storage floating numbers in binary" + " mode."; + error(message, __LINE__, __FUNCTION__, __FILE__); + } + if (userOutputWsEmpty && threadManagerMode != ThreadManagerMode::Asynchronous + && threadManagerMode != ThreadManagerMode::AsynchronousOut) + { + const std::string additionalMessage{ + " You could also set mThreadManagerMode = mThreadManagerMode::Asynchronous(Out) and/or add your" + " own output worker class before calling this function." + }; + const auto savingSomething = ( + !wrapperStructOutput.writeImages.empty() || !wrapperStructOutput.writeVideo.empty() + || !wrapperStructOutput.writeKeypoint.empty() || !wrapperStructOutput.writeJson.empty() + || !wrapperStructOutput.writeCocoJson.empty() || !wrapperStructOutput.writeHeatMaps.empty() + ); + if (!wrapperStructOutput.displayGui && !savingSomething) + { + const auto message = "No output is selected (`--no_display`) and no results are generated (no" + " `--write_X` flags enabled). Thus, no output would be generated." + + additionalMessage; + error(message, __LINE__, __FUNCTION__, __FILE__); + } + if (wrapperStructInput.framesRepeat && savingSomething) + { + const auto message = "Frames repetition (`--frames_repeat`) is enabled as well as some writing" + " function (`--write_X`). This program would never stop recording the same" + " frames over and over. Please, disable repetition or remove writing."; + error(message, __LINE__, __FUNCTION__, __FILE__); + } + // Warnings + if ((wrapperStructOutput.displayGui && wrapperStructOutput.guiVerbose) && !renderOutput) + { + const auto message = "No render is enabled (e.g. `--render_pose 0`), so you might also want to" + " remove the display (set `--no_display` or `--no_gui_verbose`). If you" + " simply want to use OpenPose to record video/images without keypoints, you" + " only need to set `--num_gpu 0`." + additionalMessage; + log(message, Priority::High); + } + if (wrapperStructInput.realTimeProcessing && savingSomething) + { + const auto message = "Real time processing is enabled as well as some writing function. Thus, some" + " frames might be skipped. Consider disabling real time processing if you" + " intend to save any results."; + log(message, Priority::High); + } + } + if (!wrapperStructOutput.writeVideo.empty() && wrapperStructInput.producerSharedPtr == nullptr) + error("Writting video is only available if the OpenPose producer is used (i.e." + " wrapperStructInput.producerSharedPtr cannot be a nullptr).", __LINE__, __FUNCTION__, __FILE__); + if (!wrapperStructPose.enable) + { + if (!wrapperStructFace.enable) + error("Body keypoint detection must be enabled.", __LINE__, __FUNCTION__, __FILE__); + if (wrapperStructHand.enable) + error("Body keypoint detection must be enabled in order to run hand keypoint detection.", + __LINE__, __FUNCTION__, __FILE__); + } + #ifdef CPU_ONLY + if (wrapperStructPose.gpuNumber > 0) + error("GPU number must be negative or 0 if CPU_ONLY is enabled.", __LINE__, __FUNCTION__, __FILE__); + #endif + + log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__); + } + catch (const std::exception& e) + { + error(e.what(), __LINE__, __FUNCTION__, __FILE__); + } + } +} -- GitLab