Ubuntu code compatible with Windows one

This commit is contained in:
Gines Hidalgo
2017-05-25 14:41:55 -04:00
parent 763cd1ff03
commit e8a4223d27
12 changed files with 79 additions and 46 deletions
-32
View File
@@ -5,38 +5,6 @@ Forget about the OpenPose library code, just compile the library and use the dem
In order to learn how to use it, run `./build/examples/openpose/openpose.bin --help` in your bash and read all the available flags (check only the flags for `examples/openpose/openpose.cpp` itself, i.e. the section `Flags from examples/openpose/openpose.cpp:`). We detail some of them in the following sections.
## Quick Start
Check that the library is working properly by using any of the following commands. Note that `examples/media/video.avi` and `examples/media` exist, so you do not need to change the paths.
1. Running on Video
```
./build/examples/openpose/openpose.bin --video examples/media/video.avi
```
2. Running on Webcam
```
./build/examples/openpose/openpose.bin
```
3. Running on Images
```
./build/examples/openpose/openpose.bin --image_dir examples/media/
```
The visual GUI should show the original image with the poses blended on it, similarly to the pose of this gif:
<p align="center">
<img src="media/shake.gif", width="720">
</p>
If you choose to visualize a body part or a PAF (Part Affinity Field) heat map with the command option `--part_to_show`, the result should be similar to one of the following images:
<p align="center">
<img src="media/body_heat_maps.png", width="720">
</p>
<p align="center">
<img src="media/paf_heat_maps.png", width="720">
</p>
## Other Important Options
+41 -1
View File
@@ -5,7 +5,7 @@ OpenPose Library - Compilation and Installation
## Requirements
- Ubuntu (tested on 14 and 16)
- GPU with at least 2 GB and 1.5 GB available (the `nvidia-smi` command checks the available GPU memory in Ubuntu).
- GPU with at least 1.5 GB available (the `nvidia-smi` command checks the available GPU memory in Ubuntu).
- CUDA and cuDNN installed.
- At least 2 GB of free RAM memory.
- Highly recommended: A CPU with at least 8 cores.
@@ -80,3 +80,43 @@ make clean && cd 3rdparty/caffe && make clean
## Uninstallation
You just need to remove the OpenPose folder, by default called `openpose/`. E.g. `rm -rf openpose/`.
## Quick Start
Check that the library is working properly by using any of the following commands. Note that `examples/media/video.avi` and `examples/media` exist, so you do not need to change the paths.
1. Running on Video
```
./build/examples/openpose/openpose.bin --video examples/media/video.avi
```
2. Running on Webcam
```
./build/examples/openpose/openpose.bin
```
3. Running on Images
```
./build/examples/openpose/openpose.bin --image_dir examples/media/
```
The visual GUI should show the original image with the poses blended on it, similarly to the pose of this gif:
<p align="center">
<img src="media/shake.gif", width="720">
</p>
If you choose to visualize a body part or a PAF (Part Affinity Field) heat map with the command option `--part_to_show`, the result should be similar to one of the following images:
<p align="center">
<img src="media/body_heat_maps.png", width="720">
</p>
<p align="center">
<img src="media/paf_heat_maps.png", width="720">
</p>
## FAQ
Q: Out of memory error - After installing OpenPose, I get an out of memory error, similar to: `Check failed: error == cudaSuccess (2 vs. 0) out of memory`.
A: Most probably cuDNN is not installed/enabled, the default Caffe model uses >12 GB of GPU memory, cuDNN reduces it to ~1.5 GB.
+4 -1
View File
@@ -66,7 +66,6 @@ namespace op
const std::array<float, (int)PoseModel::Size> POSE_CCN_DECREASE_FACTOR{ 8.f, 8.f, 8.f};
const std::array<unsigned int, (int)PoseModel::Size> POSE_MAX_PEAKS{ POSE_MAX_PEOPLE, POSE_MAX_PEOPLE, POSE_MAX_PEOPLE};
const std::array<unsigned char, (int)PoseModel::Size> POSE_NUMBER_BODY_PARTS{ POSE_COCO_NUMBER_PARTS, POSE_MPI_NUMBER_PARTS, POSE_MPI_NUMBER_PARTS};
const std::array<std::map<unsigned char, std::string>, 3> POSE_BODY_PART_MAPPING{ POSE_COCO_BODY_PARTS, POSE_MPI_BODY_PARTS, POSE_MPI_BODY_PARTS};
const std::array<std::vector<unsigned char>, 3> POSE_BODY_PART_PAIRS{ POSE_COCO_PAIRS, POSE_MPI_PAIRS, POSE_MPI_PAIRS};
const std::array<std::vector<unsigned char>, 3> POSE_MAP_IDX{ POSE_COCO_MAP_IDX, POSE_MPI_MAP_IDX, POSE_MPI_MAP_IDX};
const std::array<std::string, (int)PoseModel::Size> POSE_PROTOTXT{ "pose/coco/pose_deploy_linevec.prototxt",
@@ -75,6 +74,10 @@ namespace op
const std::array<std::string, (int)PoseModel::Size> POSE_TRAINED_MODEL{ "pose/coco/pose_iter_440000.caffemodel",
"pose/mpi/pose_iter_160000.caffemodel",
"pose/mpi/pose_iter_160000.caffemodel"};
// POSE_BODY_PART_MAPPING crashes on Windows at dynamic initialization, to avoid this crash:
// POSE_BODY_PART_MAPPING has been moved to poseParameters.cpp and getPoseBodyPartMapping() wraps it
//const std::array<std::map<unsigned char, std::string>, 3> POSE_BODY_PART_MAPPING{ POSE_COCO_BODY_PARTS, POSE_MPI_BODY_PARTS, POSE_MPI_BODY_PARTS};
const std::map<unsigned char, std::string>& getPoseBodyPartMapping(const PoseModel poseModel);
// Default Model Parameters
// They might be modified on running time
+1
View File
@@ -1,6 +1,7 @@
#ifndef OPENPOSE__PRODUCER__PRODUCER_HPP
#define OPENPOSE__PRODUCER__PRODUCER_HPP
#include <array>
#include <chrono>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp> // capProperties of OpenCV
+1 -1
View File
@@ -1,5 +1,5 @@
#ifndef OPENPOSE__THREAD__QUEUE_BASE_HPP
#define OPENPOSE__THREAD__QUEUE_BASE_HPP
#define OPENPOSE__THREAD__QUEUE_BASE_HPP
#include <queue> // std::queue & std::priority_queue
#include <condition_variable>
+4 -4
View File
@@ -442,7 +442,7 @@ namespace op
// #threads = maxThreadId+1
mThreads.resize(maxThreadId);
for (auto& thread : mThreads)
thread = {std::make_shared<Thread<TDatums, TWorker>>()};
thread = std::make_shared<Thread<TDatums, TWorker>>();
mThreads.emplace_back(std::make_shared<Thread<TDatums, TWorker>>(spIsRunning));
}
catch (const std::exception& e)
@@ -467,8 +467,8 @@ namespace op
std::vector<std::pair<bool, bool>> usedQueueIds(maxQueueId + 1, {false, false});
for (const auto& threadWorkerQueue : mThreadWorkerQueues)
{
usedQueueIds[std::get<2>(threadWorkerQueue)].first = true;
usedQueueIds[std::get<3>(threadWorkerQueue)].second = true;
usedQueueIds.at(std::get<2>(threadWorkerQueue)).first = true;
usedQueueIds.at(std::get<3>(threadWorkerQueue)).second = true;
}
// Id 0 must only needs a worker using it as input.
usedQueueIds.begin()->second = true;
@@ -493,7 +493,7 @@ namespace op
else
error("Unknown ThreadManagerMode", __LINE__, __FUNCTION__, __FILE__);
for (auto& tQueue : mTQueues)
tQueue = {std::make_shared<TQueue>(mDefaultMaxSizeQueues)};
tQueue = std::make_shared<TQueue>(mDefaultMaxSizeQueues);
}
}
catch (const std::exception& e)
+2 -2
View File
@@ -7,8 +7,8 @@
namespace op
{
const auto THREADS_PER_BLOCK_1D = 16;
const auto THREADS_PER_BLOCK = 512;
const auto THREADS_PER_BLOCK_1D = 16u;
const auto THREADS_PER_BLOCK = 512u;
template <typename T>
__global__ void nmsRegisterKernel(int* kernelPtr, const T* const sourcePtr, const int w, const int h, const T threshold)
+2 -1
View File
@@ -1,5 +1,6 @@
#include <chrono>
#include <cstdio> // std::snprintf
#include <limits> // std::numeric_limits
#include "openpose/utilities/errorAndLog.hpp"
#include "openpose/utilities/fastMath.hpp"
#include "openpose/utilities/openCv.hpp"
@@ -52,7 +53,7 @@ namespace op
mGuiEnabled{guiEnabled},
mFpsCounter{0u},
mLastElementRenderedCounter{std::numeric_limits<int>::max()},
mLastId{-1u}
mLastId{std::numeric_limits<unsigned long long>::max()}
{
}
+15
View File
@@ -3,6 +3,8 @@
namespace op
{
const std::array<std::map<unsigned char, std::string>, 3> POSE_BODY_PART_MAPPING{ POSE_COCO_BODY_PARTS, POSE_MPI_BODY_PARTS, POSE_MPI_BODY_PARTS };
unsigned char poseBodyPartMapStringToKey(const PoseModel poseModel, const std::vector<std::string>& strings)
{
try
@@ -34,4 +36,17 @@ namespace op
return 0;
}
}
const std::map<unsigned char, std::string>& getPoseBodyPartMapping(const PoseModel poseModel)
{
try
{
return POSE_BODY_PART_MAPPING.at((int)poseModel);
}
catch (const std::exception& e)
{
error(e.what(), __LINE__, __FUNCTION__, __FILE__);
return POSE_BODY_PART_MAPPING[(int)poseModel];
}
}
}
+3 -1
View File
@@ -8,6 +8,8 @@
namespace op
{
// PI digits: http://www.piday.org/million/
__constant__ const float PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745f;
__constant__ const unsigned char COCO_PAIRS_GPU[] = POSE_COCO_PAIRS_TO_RENDER;
__constant__ const unsigned char MPI_PAIRS_GPU[] = POSE_MPI_PAIRS_TO_RENDER;
__constant__ const float COCO_RGB_COLORS[] = {
@@ -131,7 +133,7 @@ namespace op
inline __device__ void getColorXYAffinity(float3& colorPtr, const float x, const float y)
{
const auto rad = fastMin(1.f, sqrt( x*x + y*y ) );
const float a = atan2(-y,-x)/M_PI;
const float a = atan2(-y,-x)/PI;
auto fk = (a+1.f)/2.f; // 0 to 1
if (::isnan(fk))
fk = 0.f;
+5 -2
View File
@@ -12,7 +12,9 @@ namespace op
{
try
{
auto partToName = POSE_BODY_PART_MAPPING[(int)poseModel];
// POSE_BODY_PART_MAPPING crashes on Windows, replaced by getPoseBodyPartMapping
// auto partToName = POSE_BODY_PART_MAPPING[(int)poseModel];
auto partToName = getPoseBodyPartMapping(poseModel);
const auto& bodyPartPairs = POSE_BODY_PART_PAIRS[(int)poseModel];
const auto& mapIdx = POSE_MAP_IDX[(int)poseModel];
@@ -43,7 +45,8 @@ namespace op
mPoseModel{poseModel},
mPartIndexToName{createPartToName(poseModel)},
// #body elements to render = #body parts (size()) + #body part pair connections + 3 (+whole pose +whole heatmaps +PAFs)
mNumberElementsToRender{(int)(POSE_BODY_PART_MAPPING[(int)mPoseModel].size() + POSE_BODY_PART_PAIRS[(int)mPoseModel].size()/2 + 3)},
// POSE_BODY_PART_MAPPING crashes on Windows, replaced by getPoseBodyPartMapping
mNumberElementsToRender{(int)(getPoseBodyPartMapping(mPoseModel).size() + POSE_BODY_PART_PAIRS[(int)mPoseModel].size()/2 + 3)},
spPoseExtractor{poseExtractor},
mAlphaPose{alphaPose},
mAlphaHeatMap{alphaHeatMap},
+1 -1
View File
@@ -42,7 +42,7 @@ namespace op
if (sProfilerTuple.count(key) > 0)
std::get<2>(sProfilerTuple[key]) = std::chrono::high_resolution_clock::now();
else
sProfilerTuple[key] = {std::make_tuple(0., 0, std::chrono::high_resolution_clock::now())};
sProfilerTuple[key] = {std::make_tuple(0., 0ull, std::chrono::high_resolution_clock::now())};
lock.unlock();
return key;
#else