diff --git a/.travis.yml b/.travis.yml index d3e278c08c335efb2ba39cab9c97a3520b5eee22..54d803ba2486cdd177c61d7ca591958f377c4dd7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,6 +52,11 @@ matrix: dist: xenial env: NAME="U16-python-cmake-cpu-debug" WITH_PYTHON=true WITH_CUDA=false WITH_DEBUG=true sudo: required + # Ubuntu 16.04 - Python - CMake - CPU - Unity + - os: linux + dist: xenial + env: NAME="U16-python-cmake-cpu-unity" WITH_PYTHON=true WITH_UNITY=true WITH_CUDA=false + sudo: required # Mac OSX # Mac OSX - Python - CMake - CPU @@ -67,7 +72,12 @@ matrix: # Mac OSX - Python - CMake - CPU - Debug - os: osx osx_image: xcode9.4 # xcode10.1 does not work with Python # Versions: https://docs.travis-ci.com/user/languages/objective-c#supported-xcode-versions - env: NAME="OSX-python-cmake-cpu" WITH_CUDA=false WITH_PYTHON=true WITH_DEBUG=true + env: NAME="OSX-python-cmake-cpu-debug" WITH_CUDA=false WITH_PYTHON=true WITH_DEBUG=true + sudo: required + # Mac OSX - Python - CMake - CPU - Unity + - os: osx + osx_image: xcode9.4 # xcode10.1 does not work with Python # Versions: https://docs.travis-ci.com/user/languages/objective-c#supported-xcode-versions + env: NAME="OSX-python-cmake-cpu-unity" WITH_CUDA=false WITH_PYTHON=true WITH_UNITY=true sudo: required # # TO-DO: To be implemented diff --git a/CMakeLists.txt b/CMakeLists.txt index b0db10bdc0aec3f66167054011e9bc90c74c078e..60520d164bcd536a6ff6d13d8271504a9e244477 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -273,9 +273,7 @@ if (WIN32) endif (WIN32) # Unity -if (WIN32) - option(BUILD_UNITY_SUPPORT "Build OpenPose as a Unity plugin." OFF) -endif (WIN32) +option(BUILD_UNITY_SUPPORT "Build OpenPose as a Unity plugin." OFF) # Build as shared library option(BUILD_SHARED_LIBS "Build as shared lib." ON) diff --git a/README.md b/README.md index 546bc01693c861ff5f7ec94aeefd3fc72c905351..5457bc0d19cb93bbd992b2507462e0053b31a331 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ ----------------- -| | `Python (CUDA GPU)` | `Python (CPU)` | `CUDA GPU` | `CPU` | `Debug mode` | -| :---: | :---: | :---: | :---: |:---: | :---: | -| **`Linux`** | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/1)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/2)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/3)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/4)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/5)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | -| **`MacOS`** | | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/6)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/7)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/8)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | - +| |`Python (CUDA)`| `Python (CPU)`| `CUDA` | `CPU` | `Debug` | `Unity` | +| :---: | :---: | :---: | :---: | :---: | :---: | :---: | +| **`Linux`** | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/1)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/2)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/3)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/4)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/5)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/6)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | +| **`MacOS`** | | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/7)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/8)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/9)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/10)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | + diff --git a/include/openpose/core/arrayCpuGpu.hpp b/include/openpose/core/arrayCpuGpu.hpp index ed6451be578238b4bd876560324d7c76b848a490..e48048fd8d5427362a3614f2ad3ae38081278378 100644 --- a/include/openpose/core/arrayCpuGpu.hpp +++ b/include/openpose/core/arrayCpuGpu.hpp @@ -68,7 +68,7 @@ namespace op const T* cpu_data() const; void set_cpu_data(T* data); - const int* gpu_shape() const; + // const int* gpu_shape() const; // Disabled because it produces compiler errors for some users const T* gpu_data() const; void set_gpu_data(T* data); const T* cpu_diff() const; diff --git a/scripts/travis/configure_cmake.sh b/scripts/travis/configure_cmake.sh index 34fd4344dc277fe72d85f8ff4971f95c6d48d71a..1a3f4b7b7cec67377d71708583277799b85ff315 100755 --- a/scripts/travis/configure_cmake.sh +++ b/scripts/travis/configure_cmake.sh @@ -50,6 +50,11 @@ else ARGS="$ARGS -DUSE_CUDNN=Off" fi +echo "WITH_UNITY = ${WITH_UNITY}." +if [[ $WITH_UNITY == true ]] ; then + ARGS="$ARGS -DBUILD_UNITY_SUPPORT=On" +fi + echo "WITH_DEBUG = ${WITH_DEBUG}." if [[ $WITH_DEBUG == true ]] ; then ARGS="$ARGS -DCMAKE_BUILD_TYPE=Debug" diff --git a/scripts/travis/defaults.sh b/scripts/travis/defaults.sh index 5edb4c2be2252a2a8a72a8d49634522fef9642e5..74a6a8eebbffaacc64b825457536d9e63b25cfb9 100755 --- a/scripts/travis/defaults.sh +++ b/scripts/travis/defaults.sh @@ -8,11 +8,12 @@ WITH_CUDA=${WITH_CUDA:-true} WITH_CUDNN=${WITH_CUDNN:-true} WITH_OPEN_CL=${WITH_OPEN_CL:-false} WITH_MKL=${WITH_MKL:-false} +WITH_UNITY=${WITH_UNITY:-false} WITH_DEBUG=${WITH_DEBUG:-false} # Examples should be run (Travis not compatible with GPU code) # if [[ $WITH_CMAKE == true ]] && [[ $WITH_PYTHON == true ]] && [[ $WITH_CUDA == false ]] && [[ $WITH_OPEN_CL == false ]] && [[ $WITH_MKL == false ]]; then -if [[ $WITH_CUDA == false ]] && [[ $WITH_OPEN_CL == false ]]; then +if [[ $WITH_CUDA == false ]] && [[ $WITH_OPEN_CL == false ]] && [[ $WITH_UNITY == false ]]; then RUN_EXAMPLES=true else RUN_EXAMPLES=false @@ -21,7 +22,7 @@ echo "RUN_EXAMPLES = ${RUN_EXAMPLES}." # Makefile configuration compatible # if [[ $WITH_PYTHON == false ]] ; then -if [[ $WITH_PYTHON == false ]] && [[ $WITH_DEBUG == false ]]; then +if [[ $WITH_PYTHON == false ]] && [[ $WITH_DEBUG == false ]] && [[ $WITH_UNITY == false ]]; then MAKE_CONFIG_COMPATIBLE=true else MAKE_CONFIG_COMPATIBLE=false diff --git a/src/openpose/core/arrayCpuGpu.cpp b/src/openpose/core/arrayCpuGpu.cpp index 3440dc1472e87dc8f5c72c9a5f0c231c16f6a787..373bba66d1ad5fe853fce7bc43bf7a3287d20b8d 100644 --- a/src/openpose/core/arrayCpuGpu.cpp +++ b/src/openpose/core/arrayCpuGpu.cpp @@ -578,23 +578,23 @@ namespace op } } - template - const int* ArrayCpuGpu::gpu_shape() const - { - try - { - #ifdef USE_CAFFE - return spImpl->pCaffeBlobT->gpu_shape(); - #else - return nullptr; - #endif - } - catch (const std::exception& e) - { - error(e.what(), __LINE__, __FUNCTION__, __FILE__); - return nullptr; - } - } + // template + // const int* ArrayCpuGpu::gpu_shape() const + // { + // try + // { + // #ifdef USE_CAFFE + // return spImpl->pCaffeBlobT->gpu_shape(); + // #else + // return nullptr; + // #endif + // } + // catch (const std::exception& e) + // { + // error(e.what(), __LINE__, __FUNCTION__, __FILE__); + // return nullptr; + // } + // } template const T* ArrayCpuGpu::gpu_data() const diff --git a/src/openpose/pose/poseExtractorCaffe.cpp b/src/openpose/pose/poseExtractorCaffe.cpp index fb449fea2c566e4af7345be6afb409933e36a0b7..d434be2a33757922e6f87234a9344821b7930b79 100644 --- a/src/openpose/pose/poseExtractorCaffe.cpp +++ b/src/openpose/pose/poseExtractorCaffe.cpp @@ -292,8 +292,9 @@ namespace op { // Sanity check if (inputNetData.size() != 1u) - error("Size(inputNetData) must be provided heatmaps (" + std::to_string(inputNetData.size()) - + " vs. " + std::to_string(1) + ").", __LINE__, __FUNCTION__, __FILE__); + error("Size(inputNetData) must match the provided heatmaps batch size (" + + std::to_string(inputNetData.size()) + " vs. " + std::to_string(1) + ").", + __LINE__, __FUNCTION__, __FILE__); // Copy heatmap information upImpl->spCaffeNetOutputBlobs.clear(); const bool copyFromGpu = false; diff --git a/src/openpose/unity/unityBinding.cpp b/src/openpose/unity/unityBinding.cpp index 7fa2b3eed419d40d328f16d469e1e2a7ce49f48b..0c3394ad7ad59916349548e934595cb87fb6263b 100644 --- a/src/openpose/unity/unityBinding.cpp +++ b/src/openpose/unity/unityBinding.cpp @@ -6,11 +6,15 @@ namespace op { - // Output callback register in Unity - typedef void(__stdcall * OutputCallback) (void * ptrs, int ptrSize, int * sizes, int sizeSize, uchar outputType); - - // Global output callback - OutputCallback sUnityOutputCallback; + #ifdef _WIN32 + // Output callback register in Unity + typedef void(__stdcall * OutputCallback) (void * ptrs, int ptrSize, int * sizes, int sizeSize, + uchar outputType); + // Global output callback + OutputCallback sUnityOutputCallback; + #endif + + // Other global parameters bool sMultiThreadEnabled = true; bool sUnityOutputEnabled = true; bool sImageOutput = false; @@ -84,200 +88,314 @@ namespace op template void outputValue(T ** ptrs, int ptrSize, int * sizes, int sizeSize, OutputType outputType) { - if (sUnityOutputCallback) - sUnityOutputCallback(static_cast(ptrs), ptrSize, sizes, sizeSize, (uchar)outputType); + try + { + #ifdef _WIN32 + if (sUnityOutputCallback) + sUnityOutputCallback(static_cast(ptrs), ptrSize, sizes, sizeSize, (uchar)outputType); + #else + UNUSED(ptrs); + UNUSED(ptrSize); + UNUSED(sizes); + UNUSED(sizeSize); + UNUSED(outputType); + error("Function only available on Windows.", __LINE__, __FUNCTION__, __FILE__); + #endif + } + catch (const std::exception& e) + { + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); + } } void sendDatumsInfoAndName(const std::shared_ptr>>& datumsPtr) { - auto& datum = datumsPtr->at(0); - int sizes[] = { 1 }; - int sizeSize = 1; - unsigned long long *val[] = {&(datum->id), &(datum->subId), &(datum->subIdMax), &(datum->frameNumber)}; - int ptrSize = 4; - outputValue(&val[0], ptrSize, &sizes[0], sizeSize, OutputType::DatumsInfo); - - char const *a[] = { datum->name.c_str() }; - outputValue(&a[0], 1, &sizes[0], sizeSize, OutputType::Name); + try + { + auto& datum = datumsPtr->at(0); + int sizes[] = { 1 }; + int sizeSize = 1; + unsigned long long *val[] = {&(datum->id), &(datum->subId), &(datum->subIdMax), &(datum->frameNumber)}; + int ptrSize = 4; + outputValue(&val[0], ptrSize, &sizes[0], sizeSize, OutputType::DatumsInfo); + + char const *a[] = { datum->name.c_str() }; + outputValue(&a[0], 1, &sizes[0], sizeSize, OutputType::Name); + } + catch (const std::exception& e) + { + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); + } } void sendPoseKeypoints(const std::shared_ptr>>& datumsPtr) { - auto& data = datumsPtr->at(0)->poseKeypoints; // Array - if (!data.empty()) + try + { + auto& data = datumsPtr->at(0)->poseKeypoints; // Array + if (!data.empty()) + { + auto sizeVector = data.getSize(); + int sizeSize = sizeVector.size(); + int * sizes = &sizeVector[0]; + float * val = data.getPtr(); + outputValue(&val, 1, sizes, sizeSize, OutputType::PoseKeypoints); + } + } + catch (const std::exception& e) { - auto sizeVector = data.getSize(); - int sizeSize = sizeVector.size(); - int * sizes = &sizeVector[0]; - float * val = data.getPtr(); - outputValue(&val, 1, sizes, sizeSize, OutputType::PoseKeypoints); + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); } } void sendPoseIds(const std::shared_ptr>>& datumsPtr) { - auto& data = datumsPtr->at(0)->poseIds; // Array - if (!data.empty()) + try { - auto sizeVector = data.getSize(); - int sizeSize = sizeVector.size(); - int * sizes = &sizeVector[0]; - long long * val = data.getPtr(); - outputValue(&val, 1, sizes, sizeSize, OutputType::PoseIds); + auto& data = datumsPtr->at(0)->poseIds; // Array + if (!data.empty()) + { + auto sizeVector = data.getSize(); + int sizeSize = sizeVector.size(); + int * sizes = &sizeVector[0]; + long long * val = data.getPtr(); + outputValue(&val, 1, sizes, sizeSize, OutputType::PoseIds); + } + } + catch (const std::exception& e) + { + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); } } void sendPoseScores(const std::shared_ptr>>& datumsPtr) { - auto& data = datumsPtr->at(0)->poseScores; // Array - if (!data.empty()) + try + { + auto& data = datumsPtr->at(0)->poseScores; // Array + if (!data.empty()) + { + auto sizeVector = data.getSize(); + int sizeSize = sizeVector.size(); + int * sizes = &sizeVector[0]; + float * val = data.getPtr(); + outputValue(&val, 1, sizes, sizeSize, OutputType::PoseScores); + } + } + catch (const std::exception& e) { - auto sizeVector = data.getSize(); - int sizeSize = sizeVector.size(); - int * sizes = &sizeVector[0]; - float * val = data.getPtr(); - outputValue(&val, 1, sizes, sizeSize, OutputType::PoseScores); + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); } } void sendPoseHeatMaps(const std::shared_ptr>>& datumsPtr) { - auto& data = datumsPtr->at(0)->poseHeatMaps; // Array - if (!data.empty()) + try { - auto sizeVector = data.getSize(); - int sizeSize = sizeVector.size(); - int * sizes = &sizeVector[0]; - float * val = data.getPtr(); - outputValue(&val, 1, sizes, sizeSize, OutputType::PoseHeatMaps); + auto& data = datumsPtr->at(0)->poseHeatMaps; // Array + if (!data.empty()) + { + auto sizeVector = data.getSize(); + int sizeSize = sizeVector.size(); + int * sizes = &sizeVector[0]; + float * val = data.getPtr(); + outputValue(&val, 1, sizes, sizeSize, OutputType::PoseHeatMaps); + } + } + catch (const std::exception& e) + { + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); } } void sendPoseCandidates(const std::shared_ptr>>& datumsPtr) { - auto& data = datumsPtr->at(0)->poseCandidates; // std::vector>> - if (!data.empty()) + try { - // TODO - /*auto a = data[0][0].data(); - auto sizeVector = data.getSize(); - int sizeSize = sizeVector.size(); - int * sizes = &sizeVector[0]; - long long * val = data.getPtr(); - outputValue(&val, 1, sizes, sizeSize, OutputType::PoseIds);*/ + auto& data = datumsPtr->at(0)->poseCandidates; // std::vector>> + if (!data.empty()) + { + // TODO + /*auto a = data[0][0].data(); + auto sizeVector = data.getSize(); + int sizeSize = sizeVector.size(); + int * sizes = &sizeVector[0]; + long long * val = data.getPtr(); + outputValue(&val, 1, sizes, sizeSize, OutputType::PoseIds);*/ + } + } + catch (const std::exception& e) + { + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); } } void sendFaceRectangles(const std::shared_ptr>>& datumsPtr) { - auto& data = datumsPtr->at(0)->faceRectangles; // std::vector> - if (data.size() > 0) + try { - int sizes[] = { data.size(), 4 }; - std::vector vals(data.size() * 4); - for (int i = 0; i < data.size(); i++) + auto& data = datumsPtr->at(0)->faceRectangles; // std::vector> + if (data.size() > 0) { - vals[4 * i + 0] = data[i].x; - vals[4 * i + 1] = data[i].y; - vals[4 * i + 2] = data[i].width; - vals[4 * i + 3] = data[i].height; + int sizes[] = { (int)data.size(), 4 }; + std::vector vals(data.size() * 4); + for (auto i = 0u; i < data.size(); i++) + { + vals[4 * i + 0] = data[i].x; + vals[4 * i + 1] = data[i].y; + vals[4 * i + 2] = data[i].width; + vals[4 * i + 3] = data[i].height; + } + float * val = &vals[0]; + outputValue(&val, 1, sizes, 2, OutputType::FaceRectangles); } - float * val = &vals[0]; - outputValue(&val, 1, sizes, 2, OutputType::FaceRectangles); + } + catch (const std::exception& e) + { + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); } } void sendFaceKeypoints(const std::shared_ptr>>& datumsPtr) { - auto& data = datumsPtr->at(0)->faceKeypoints; // Array - if (!data.empty()) + try { - auto sizeVector = data.getSize(); - int sizeSize = sizeVector.size(); - int * sizes = &sizeVector[0]; - float * val = data.getPtr(); - outputValue(&val, 1, sizes, sizeSize, OutputType::FaceKeypoints); + auto& data = datumsPtr->at(0)->faceKeypoints; // Array + if (!data.empty()) + { + auto sizeVector = data.getSize(); + int sizeSize = sizeVector.size(); + int * sizes = &sizeVector[0]; + float * val = data.getPtr(); + outputValue(&val, 1, sizes, sizeSize, OutputType::FaceKeypoints); + } + } + catch (const std::exception& e) + { + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); } } void sendFaceHeatMaps(const std::shared_ptr>>& datumsPtr) { - auto& data = datumsPtr->at(0)->faceHeatMaps; // Array - if (!data.empty()) + try { - auto sizeVector = data.getSize(); - int sizeSize = sizeVector.size(); - int * sizes = &sizeVector[0]; - float * val = data.getPtr(); - outputValue(&val, 1, sizes, sizeSize, OutputType::FaceHeatMaps); + auto& data = datumsPtr->at(0)->faceHeatMaps; // Array + if (!data.empty()) + { + auto sizeVector = data.getSize(); + int sizeSize = sizeVector.size(); + int * sizes = &sizeVector[0]; + float * val = data.getPtr(); + outputValue(&val, 1, sizes, sizeSize, OutputType::FaceHeatMaps); + } + } + catch (const std::exception& e) + { + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); } } void sendHandRectangles(const std::shared_ptr>>& datumsPtr) { - auto& data = datumsPtr->at(0)->handRectangles; // std::vector, 2>> - if (!data.empty()) + try { - std::vector valPtrs; - for (int i = 0; i < data.size(); i++) + auto& data = datumsPtr->at(0)->handRectangles; // std::vector, 2>> + if (!data.empty()) { - float vals[8]; - for (int j = 0; j < 2; j++) + std::vector valPtrs; + for (auto i = 0u; i < data.size(); i++) { - vals[4 * j + 0] = data[i][j].x; - vals[4 * j + 1] = data[i][j].y; - vals[4 * j + 2] = data[i][j].width; - vals[4 * j + 3] = data[i][j].height; + float vals[8]; + for (auto j = 0; j < 2; j++) + { + vals[4 * j + 0] = data[i][j].x; + vals[4 * j + 1] = data[i][j].y; + vals[4 * j + 2] = data[i][j].width; + vals[4 * j + 3] = data[i][j].height; + } + valPtrs.push_back(vals); } - valPtrs.push_back(vals); + int sizes[] = {2, 4}; + int sizeSize = 2; + outputValue(valPtrs.data(), valPtrs.size(), sizes, sizeSize, OutputType::HandRectangles); } - int sizes[] = {2, 4}; - int sizeSize = 2; - outputValue(valPtrs.data(), valPtrs.size(), sizes, sizeSize, OutputType::HandRectangles); + } + catch (const std::exception& e) + { + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); } } void sendHandKeypoints(const std::shared_ptr>>& datumsPtr) { - auto& data = datumsPtr->at(0)->handKeypoints; // std::array, 2> - if (data.size() == 2 && !data[0].empty()) + try { - auto sizeVector = data[0].getSize(); - int sizeSize = sizeVector.size(); - int * sizes = &sizeVector[0]; - float * ptrs[] = { data[0].getPtr(), data[1].getPtr() }; - outputValue(ptrs, 2, sizes, sizeSize, OutputType::HandKeypoints); + auto& data = datumsPtr->at(0)->handKeypoints; // std::array, 2> + if (data.size() == 2 && !data[0].empty()) + { + auto sizeVector = data[0].getSize(); + int sizeSize = sizeVector.size(); + int * sizes = &sizeVector[0]; + float * ptrs[] = { data[0].getPtr(), data[1].getPtr() }; + outputValue(ptrs, 2, sizes, sizeSize, OutputType::HandKeypoints); + } + } + catch (const std::exception& e) + { + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); } } void sendHandHeatMaps(const std::shared_ptr>>& datumsPtr) { - auto& data = datumsPtr->at(0)->handHeatMaps; // std::array, 2> - if (data.size() == 2 && !data[0].empty()) + try { - auto sizeVector = data[0].getSize(); - int sizeSize = sizeVector.size(); - int * sizes = &sizeVector[0]; - float * ptrs[] = { data[0].getPtr(), data[1].getPtr() }; - outputValue(ptrs, 2, sizes, sizeSize, OutputType::HandHeightMaps); + auto& data = datumsPtr->at(0)->handHeatMaps; // std::array, 2> + if (data.size() == 2 && !data[0].empty()) + { + auto sizeVector = data[0].getSize(); + int sizeSize = sizeVector.size(); + int * sizes = &sizeVector[0]; + float * ptrs[] = { data[0].getPtr(), data[1].getPtr() }; + outputValue(ptrs, 2, sizes, sizeSize, OutputType::HandHeightMaps); + } + } + catch (const std::exception& e) + { + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); } } void sendImage(const std::shared_ptr>>& datumsPtr) { - auto& data = datumsPtr->at(0)->cvInputData; // cv::Mat - if (!data.empty()) + try { - int sizeVector[] = { data.rows, data.cols, 3 }; - int sizeSize = 3; - auto valPtr = data.data; - outputValue(&valPtr, 1, sizeVector, sizeSize, OutputType::Image); + auto& data = datumsPtr->at(0)->cvInputData; // cv::Mat + if (!data.empty()) + { + int sizeVector[] = { data.rows, data.cols, 3 }; + int sizeSize = 3; + auto valPtr = data.data; + outputValue(&valPtr, 1, sizeVector, sizeSize, OutputType::Image); + } + } + catch (const std::exception& e) + { + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); } } void sendEndOfFrame() { - outputValue((void**)nullptr, 0, nullptr, 0, OutputType::None); + try + { + outputValue((void**)nullptr, 0, nullptr, 0, OutputType::None); + } + catch (const std::exception& e) + { + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); + } } }; @@ -334,7 +452,7 @@ namespace op { log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); } - }; + } // Functions called from Unity extern "C" { @@ -369,17 +487,19 @@ namespace op } // Register Unity output callback function - OP_API void _OPRegisterOutputCallback(OutputCallback callback) - { - try - { - sUnityOutputCallback = callback; - } - catch (const std::exception& e) + #ifdef _WIN32 + OP_API void _OPRegisterOutputCallback(OutputCallback callback) { - log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); + try + { + sUnityOutputCallback = callback; + } + catch (const std::exception& e) + { + log(e.what(), Priority::Max, __LINE__, __FUNCTION__, __FILE__); + } } - } + #endif // Enable/disable multi-threading OP_API void _OPSetMultiThreadEnable(bool enable) @@ -422,7 +542,7 @@ namespace op // Configs OP_API void _OPConfigurePose( - bool enable, + uchar poseMode, int netInputSizeX, int netInputSizeY, // Point int outputSizeX, int outputSizeY, // Point uchar keypointScaleMode, // ScaleMode @@ -434,19 +554,19 @@ namespace op bool heatMapAddPAFs, // HeatMapType // uchar heatmap_type, uchar heatMapScaleMode, // ScaleMode bool addPartCandidates, float renderThreshold, int numberPeopleMax, - bool maximizePositives, double fpsMax, char* protoTxtPath, char* caffeModelPath) + bool maximizePositives, double fpsMax, char* protoTxtPath, float upsamplingRatio, char* caffeModelPath) { try { spWrapperStructPose = std::make_shared( - enable, Point{netInputSizeX, netInputSizeY}, Point{outputSizeX, outputSizeY}, + (PoseMode)poseMode, Point{netInputSizeX, netInputSizeY}, Point{outputSizeX, outputSizeY}, (ScaleMode) keypointScaleMode, gpuNumber, gpuNumberStart, scalesNumber, scaleGap, (RenderMode) renderMode, (PoseModel) poseModel, blendOriginalFrame, alphaKeypoint, alphaHeatMap, defaultPartToRender, modelFolder, // HeatMapType // (HeatMapType) heatmap_type, flagsToHeatMaps(heatMapAddParts, heatMapAddBkg, heatMapAddPAFs), (ScaleMode) heatMapScaleMode, addPartCandidates, renderThreshold, numberPeopleMax, - maximizePositives, fpsMax, protoTxtPath, caffeModelPath, true + maximizePositives, fpsMax, protoTxtPath, caffeModelPath, upsamplingRatio, true ); } catch (const std::exception& e) @@ -481,8 +601,8 @@ namespace op try { spWrapperStructFace = std::make_shared( - enable, (Detector) detector, Point{ netInputSizeX, netInputSizeY }, (RenderMode) renderMode, alphaKeypoint, - alphaHeatMap, renderThreshold + enable, (Detector) detector, Point{ netInputSizeX, netInputSizeY }, (RenderMode) renderMode, + alphaKeypoint, alphaHeatMap, renderThreshold ); } catch (const std::exception& e) @@ -530,9 +650,9 @@ namespace op OP_API void _OPConfigureOutput( double verbose, char* writeKeypoint, uchar writeKeypointFormat, // DataFormat char* writeJson, char* writeCocoJson, char* writeCocoFootJson, int writeCocoJsonVariant, char* writeImages, - char* writeImagesFormat, char* writeVideo, double writeVideoFps, bool writeVideoWithAudio, char* writeHeatMaps, - char* writeHeatMapsFormat, char* writeVideo3D, char* writeVideoAdam, char* writeBvh, char* udpHost, - char* udpPort) + char* writeImagesFormat, char* writeVideo, double writeVideoFps, bool writeVideoWithAudio, + char* writeHeatMaps, char* writeHeatMapsFormat, char* writeVideo3D, char* writeVideoAdam, char* writeBvh, + char* udpHost, char* udpPort) { try { diff --git a/src/openpose/utilities/errorAndLog.cpp b/src/openpose/utilities/errorAndLog.cpp index 174f8ce55a9dbdd6f600d3ffa60a24e843ea9e96..37515f3c8e0ceeda55b28d205fecfc846bbe2351 100644 --- a/src/openpose/utilities/errorAndLog.cpp +++ b/src/openpose/utilities/errorAndLog.cpp @@ -9,21 +9,36 @@ namespace op #ifdef USE_UNITY_SUPPORT namespace UnityDebugger { - typedef void(__stdcall * DebugCallback) (const char* const str, int type); - DebugCallback unityDebugCallback; - bool unityDebugEnabled = true; + #ifdef _WIN32 + typedef void(__stdcall * DebugCallback) (const char* const str, int type); + DebugCallback unityDebugCallback; + #endif + bool unityDebugEnabled = true; - extern "C" void OP_API _OPRegisterDebugCallback(DebugCallback debugCallback) { - if (debugCallback) + #ifdef _WIN32 + extern "C" void OP_API _OPRegisterDebugCallback(DebugCallback debugCallback) + { + if (debugCallback) unityDebugCallback = debugCallback; - } + } - extern "C" void OP_API _OPSetDebugEnable(bool enable) { - unityDebugEnabled = enable; - } + extern "C" void OP_API _OPSetDebugEnable(bool enable) + { + unityDebugEnabled = enable; + } + #endif - void DebugInUnity(const std::string& message, const int type) { - if (unityDebugEnabled) if (unityDebugCallback) unityDebugCallback(message.c_str(), type); + void DebugInUnity(const std::string& message, const int type) + { + #ifdef _WIN32 + if (unityDebugEnabled) + if (unityDebugCallback) + unityDebugCallback(message.c_str(), type); + #else + UNUSED(message); + UNUSED(type); + error("Unity plugin only available on Windows.", __LINE__, __FUNCTION__, __FILE__); + #endif } void log(const std::string& message) { DebugInUnity(message, 0); }