提交 babd8900 编写于 作者: G gineshidalgo99

Fixed #1069 and #1071

上级 de117486
......@@ -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
......
......@@ -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)
......
......@@ -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) |
<!-- | **`Windows`** | | | | | | -->
| |`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) |
<!-- | **`Windows`** | | | | | | -->
<!--
Note: Currently using [travis-matrix-badges](https://github.com/bjfish/travis-matrix-badges) vs. traditional [![Build Status](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose.svg?branch=master)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose)
-->
......
......@@ -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;
......
......@@ -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"
......
......@@ -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
......
......@@ -578,23 +578,23 @@ namespace op
}
}
template<typename T>
const int* ArrayCpuGpu<T>::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<typename T>
// const int* ArrayCpuGpu<T>::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<typename T>
const T* ArrayCpuGpu<T>::gpu_data() const
......
......@@ -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;
......
......@@ -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<class T>
void outputValue(T ** ptrs, int ptrSize, int * sizes, int sizeSize, OutputType outputType)
{
if (sUnityOutputCallback)
sUnityOutputCallback(static_cast<void*>(ptrs), ptrSize, sizes, sizeSize, (uchar)outputType);
try
{
#ifdef _WIN32
if (sUnityOutputCallback)
sUnityOutputCallback(static_cast<void*>(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<std::vector<std::shared_ptr<Datum>>>& 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<std::vector<std::shared_ptr<Datum>>>& datumsPtr)
{
auto& data = datumsPtr->at(0)->poseKeypoints; // Array<float>
if (!data.empty())
try
{
auto& data = datumsPtr->at(0)->poseKeypoints; // Array<float>
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<std::vector<std::shared_ptr<Datum>>>& datumsPtr)
{
auto& data = datumsPtr->at(0)->poseIds; // Array<long long>
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<long long>
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<std::vector<std::shared_ptr<Datum>>>& datumsPtr)
{
auto& data = datumsPtr->at(0)->poseScores; // Array<float>
if (!data.empty())
try
{
auto& data = datumsPtr->at(0)->poseScores; // Array<float>
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<std::vector<std::shared_ptr<Datum>>>& datumsPtr)
{
auto& data = datumsPtr->at(0)->poseHeatMaps; // Array<float>
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<float>
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<std::vector<std::shared_ptr<Datum>>>& datumsPtr)
{
auto& data = datumsPtr->at(0)->poseCandidates; // std::vector<std::vector<std::array<float, 3>>>
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<std::vector<std::array<float, 3>>>
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<std::vector<std::shared_ptr<Datum>>>& datumsPtr)
{
auto& data = datumsPtr->at(0)->faceRectangles; // std::vector<Rectangle<float>>
if (data.size() > 0)
try
{
int sizes[] = { data.size(), 4 };
std::vector<float> vals(data.size() * 4);
for (int i = 0; i < data.size(); i++)
auto& data = datumsPtr->at(0)->faceRectangles; // std::vector<Rectangle<float>>
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<float> 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<std::vector<std::shared_ptr<Datum>>>& datumsPtr)
{
auto& data = datumsPtr->at(0)->faceKeypoints; // Array<float>
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<float>
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<std::vector<std::shared_ptr<Datum>>>& datumsPtr)
{
auto& data = datumsPtr->at(0)->faceHeatMaps; // Array<float>
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<float>
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<std::vector<std::shared_ptr<Datum>>>& datumsPtr)
{
auto& data = datumsPtr->at(0)->handRectangles; // std::vector<std::array<Rectangle<float>, 2>>
if (!data.empty())
try
{
std::vector<float*> valPtrs;
for (int i = 0; i < data.size(); i++)
auto& data = datumsPtr->at(0)->handRectangles; // std::vector<std::array<Rectangle<float>, 2>>
if (!data.empty())
{
float vals[8];
for (int j = 0; j < 2; j++)
std::vector<float*> 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<std::vector<std::shared_ptr<Datum>>>& datumsPtr)
{
auto& data = datumsPtr->at(0)->handKeypoints; // std::array<Array<float>, 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<Array<float>, 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<std::vector<std::shared_ptr<Datum>>>& datumsPtr)
{
auto& data = datumsPtr->at(0)->handHeatMaps; // std::array<Array<float>, 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<Array<float>, 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<std::vector<std::shared_ptr<Datum>>>& 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<WrapperStructPose>(
enable, Point<int>{netInputSizeX, netInputSizeY}, Point<int>{outputSizeX, outputSizeY},
(PoseMode)poseMode, Point<int>{netInputSizeX, netInputSizeY}, Point<int>{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<WrapperStructFace>(
enable, (Detector) detector, Point<int>{ netInputSizeX, netInputSizeY }, (RenderMode) renderMode, alphaKeypoint,
alphaHeatMap, renderThreshold
enable, (Detector) detector, Point<int>{ 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
{
......
......@@ -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); }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册