Skip to content

Commit

Permalink
Fixed link and grammar typos
Browse files Browse the repository at this point in the history
  • Loading branch information
gineshidalgo99 committed Nov 7, 2018
1 parent 0fd438d commit 3377d18
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 43 deletions.
2 changes: 1 addition & 1 deletion doc/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Any problem installing OpenPose? Check [doc/faq.md](./faq.md) and/or post a GitH
### Prerequisites
1. Ubuntu - **Anaconda should not be installed** on your system. Anaconda includes a Protobuf version that is incompatible with Caffe. Either you uninstall anaconda and install protobuf via apt-get, or you compile your own Caffe and link it to OpenPose.
2. Download and install CMake GUI:
- Ubuntu: run the command `sudo apt-get install cmake-qt-gui`. Note: If you prefer to use CMake through the command line, see [Cmake Command Line Build](#cmake-command-line-build-ubuntu-only).
- Ubuntu: run the command `sudo apt-get install cmake-qt-gui`. Note: If you prefer to use CMake through the command line, see [CMake Command Line Configuration (Ubuntu Only)](#cmake-command-line-configuration-ubuntu-only).
- Windows: download and install the latest CMake win64-x64 msi installer from the [CMake website](https://cmake.org/download/), called `cmake-X.X.X-win64-x64.msi`.
- Mac: `brew cask install cmake`.
3. Windows - **Microsoft Visual Studio (VS) 2015 Enterprise Update 3**:
Expand Down
12 changes: 11 additions & 1 deletion include/openpose/core/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>
#include <thread> // std::this_thread
#include <vector>
#include <opencv2/core/core.hpp> // cv::Mat, check OpenCV version

// OpenPose name and version
const std::string OPEN_POSE_NAME_STRING = "OpenPose";
Expand Down Expand Up @@ -85,7 +86,16 @@ namespace boost
}

// Compabitility for OpenCV 4.0 while preserving 2.4.X and 3.X compatibility
#if (defined(CV_MAJOR_VERSION) && CV_MAJOR_VERSION == 4)
// Note:
// - CV_VERSION: 2.4.9.1 | 4.0.0-beta
// - CV_MAJOR_VERSION: 2 | 4
// - CV_MINOR_VERSION: 4 | 0
// - CV_SUBMINOR_VERSION: 9 | 0
// - CV_VERSION_EPOCH: 2 | Not defined
#if (defined(CV_MAJOR_VERSION) && CV_MAJOR_VERSION > 3)
#define OPEN_CV_IS_4_OR_HIGHER
#endif
#ifdef OPEN_CV_IS_4_OR_HIGHER
#define CV_BGR2GRAY cv::COLOR_BGR2GRAY
#define CV_CALIB_CB_ADAPTIVE_THRESH cv::CALIB_CB_ADAPTIVE_THRESH
#define CV_CALIB_CB_NORMALIZE_IMAGE cv::CALIB_CB_NORMALIZE_IMAGE
Expand Down
1 change: 1 addition & 0 deletions include/openpose/net/headers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <openpose/net/maximumCaffe.hpp>
#include <openpose/net/net.hpp>
#include <openpose/net/netCaffe.hpp>
#include <openpose/net/netOpenCv.hpp>
#include <openpose/net/nmsBase.hpp>
#include <openpose/net/nmsCaffe.hpp>
#include <openpose/net/resizeAndMergeBase.hpp>
Expand Down
34 changes: 34 additions & 0 deletions include/openpose/net/netOpenCv.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef OPENPOSE_NET_NET_OPEN_CV_HPP
#define OPENPOSE_NET_NET_OPEN_CV_HPP

#include <openpose/core/common.hpp>
#include <openpose/net/net.hpp>

namespace op
{
class OP_API NetOpenCv : public Net
{
public:
NetOpenCv(const std::string& caffeProto, const std::string& caffeTrainedModel, const int gpuId = 0);

virtual ~NetOpenCv();

void initializationOnThread();

void forwardPass(const Array<float>& inputNetData) const;

boost::shared_ptr<caffe::Blob<float>> getOutputBlob() const;

private:
// PIMPL idiom
// http://www.cppsamples.com/common-tasks/pimpl.html
struct ImplNetOpenCv;
std::unique_ptr<ImplNetOpenCv> upImpl;

// PIMP requires DELETE_COPY & destructor, or extra code
// http://oliora.github.io/2015/12/29/pimpl-and-rule-of-zero.html
DELETE_COPY(NetOpenCv);
};
}

#endif // OPENPOSE_NET_NET_OPEN_CV_HPP
4 changes: 2 additions & 2 deletions include/openpose/utilities/keypoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ namespace op
const T threshold);

template <typename T>
float getKeypointsROI(const Array<T>& keypoints, const int personA, const int personB, const T threshold);
float getKeypointsRoi(const Array<T>& keypoints, const int personA, const int personB, const T threshold);

template <typename T>
float getKeypointsROI(const Array<T>& keypointsA, const int personA, const Array<T>& keypointsB, const int personB,
float getKeypointsRoi(const Array<T>& keypointsA, const int personA, const Array<T>& keypointsB, const int personB,
const T threshold);
}

Expand Down
6 changes: 3 additions & 3 deletions python/openpose/_openpose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ OP_API class OpenPose {
#ifdef USE_CUDA
caffe::Caffe::set_mode(caffe::Caffe::GPU);
caffe::Caffe::SetDevice(mGpuID);
#elif USE_OPENCL
#elif defined USE_OPENCL
caffe::Caffe::set_mode(caffe::Caffe::GPU);
std::vector<int> devices;
const int maxNumberGpu = op::OpenCL::getTotalGPU();
Expand Down Expand Up @@ -217,7 +217,7 @@ OP_API class OpenPose {
std::vector<caffe::Blob<float>*> peaksBlobs{ peaksBlob.get() };
#ifdef USE_CUDA
resizeAndMergeCaffe->Forward_gpu(caffeNetOutputBlobs, heatMapsBlobs); // ~5ms
#elif USE_OPENCL
#elif defined USE_OPENCL
resizeAndMergeCaffe->Forward_ocl(caffeNetOutputBlobs, heatMapsBlobs); // ~5ms
#else
resizeAndMergeCaffe->Forward_cpu(caffeNetOutputBlobs, heatMapsBlobs); // ~5ms
Expand All @@ -226,7 +226,7 @@ OP_API class OpenPose {
nmsCaffe->setThreshold((float)poseExtractorCaffe->get(op::PoseProperty::NMSThreshold));
#ifdef USE_CUDA
nmsCaffe->Forward_gpu(heatMapsBlobs, peaksBlobs);// ~2ms
#elif USE_OPENCL
#elif defined USE_OPENCL
nmsCaffe->Forward_ocl(heatMapsBlobs, peaksBlobs);// ~2ms
#else
nmsCaffe->Forward_cpu(heatMapsBlobs, peaksBlobs);// ~2ms
Expand Down
13 changes: 11 additions & 2 deletions src/openpose/core/cvMatToOpInput.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// #include <opencv2/opencv.hpp>
#include <openpose/utilities/fastMath.hpp>
#include <openpose/utilities/openCv.hpp>
#include <openpose/core/cvMatToOpInput.hpp>
Expand Down Expand Up @@ -31,13 +32,21 @@ namespace op
std::vector<Array<float>> inputNetData(numberScales);
for (auto i = 0u ; i < inputNetData.size() ; i++)
{
inputNetData[i].reset({1, 3, netInputSizes.at(i).y, netInputSizes.at(i).x});
std::vector<double> scaleRatios(numberScales, 1.f);
cv::Mat frameWithNetSize;
resizeFixedAspectRatio(frameWithNetSize, cvInputData, scaleInputToNetInputs[i], netInputSizes[i]);
// Fill inputNetData[i]
inputNetData[i].reset({1, 3, netInputSizes.at(i).y, netInputSizes.at(i).x});
uCharCvMatToFloatPtr(inputNetData[i].getPtr(), frameWithNetSize,
(mPoseModel == PoseModel::BODY_19N ? 2 : 1));
// // OpenCV equivalent
// const auto scale = 1/255.;
// const cv::Scalar mean{128,128,128};
// const cv::Size outputSize{netInputSizes[i].x, netInputSizes[i].y};
// // cv::Mat cvMat;
// cv::dnn::blobFromImage(
// // frameWithNetSize, cvMat, scale, outputSize, mean);
// frameWithNetSize, inputNetData[i].getCvMat(), scale, outputSize, mean);
// // log(cv::norm(cvMat - inputNetData[i].getCvMat())); // ~0.25
}
return inputNetData;
}
Expand Down
1 change: 1 addition & 0 deletions src/openpose/net/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(SOURCES_OP_NET
maximumBase.cu
maximumCaffe.cpp
netCaffe.cpp
netOpenCv.cpp
nmsBase.cpp
nmsBase.cu
nmsBaseCL.cpp
Expand Down
5 changes: 2 additions & 3 deletions src/openpose/net/netCaffe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,8 @@ namespace op
#elif defined USE_OPENCL
auto* gpuImagePtr = upImpl->upCaffeNet->blobs().at(0)->mutable_gpu_data();
cl::Buffer imageBuffer = cl::Buffer((cl_mem)gpuImagePtr, true);
OpenCL::getInstance(upImpl->mGpuId)->getQueue().enqueueWriteBuffer(imageBuffer, true, 0,
inputData.getVolume() * sizeof(float),
inputData.getConstPtr());
OpenCL::getInstance(upImpl->mGpuId)->getQueue().enqueueWriteBuffer(
imageBuffer, true, 0, inputData.getVolume() * sizeof(float), inputData.getConstPtr());
#else
auto* cpuImagePtr = upImpl->upCaffeNet->blobs().at(0)->mutable_cpu_data();
std::copy(inputData.getConstPtr(), inputData.getConstPtr() + inputData.getVolume(), cpuImagePtr);
Expand Down
151 changes: 151 additions & 0 deletions src/openpose/net/netOpenCv.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// Note: OpenCV only uses CPU or OpenCL (for Intel GPUs). Used CUDA for following blobs (Resize + NMS)
#include <openpose/core/macros.hpp> // OPEN_CV_IS_4_OR_HIGHER
#ifdef USE_CAFFE
#include <caffe/net.hpp>
#endif
#if defined(USE_CAFFE) && defined(USE_CUDA) && defined(OPEN_CV_IS_4_OR_HIGHER)
#define OPEN_CV_DNN_AVAILABLE
#include <opencv2/opencv.hpp>
#include <openpose/gpu/cuda.hpp>
#endif
#include <numeric> // std::accumulate
#include <openpose/utilities/fileSystem.hpp>
#include <openpose/net/netOpenCv.hpp>

namespace op
{
struct NetOpenCv::ImplNetOpenCv
{
#ifdef OPEN_CV_DNN_AVAILABLE
// Init with constructor
const int mGpuId;
const std::string mCaffeProto;
const std::string mCaffeTrainedModel;
// OpenCV DNN
cv::dnn::Net mNet;
cv::Mat mNetOutputBlob;
// std::shared_ptr<caffe::Blob<float>> spOutputBlob;
boost::shared_ptr<caffe::Blob<float>> spOutputBlob;

ImplNetOpenCv(const std::string& caffeProto, const std::string& caffeTrainedModel, const int gpuId) :
mGpuId{gpuId},
mCaffeProto{caffeProto},
mCaffeTrainedModel{caffeTrainedModel},
mNet{cv::dnn::readNetFromCaffe(caffeProto, caffeTrainedModel)},
// spOutputBlob{std::make_shared<caffe::Blob<float>>(1,1,1,1)}
spOutputBlob{new caffe::Blob<float>(1,1,1,1)}
{
const std::string message{".\nPossible causes:\n\t1. Not downloading the OpenPose trained models."
"\n\t2. Not running OpenPose from the same directory where the `model`"
" folder is located.\n\t3. Using paths with spaces."};
if (!existFile(mCaffeProto))
error("Prototxt file not found: " + mCaffeProto + message, __LINE__, __FUNCTION__, __FILE__);
if (!existFile(mCaffeTrainedModel))
error("Caffe trained model file not found: " + mCaffeTrainedModel + message,
__LINE__, __FUNCTION__, __FILE__);

// Set GPU
mNet.setPreferableTarget(cv::dnn::DNN_TARGET_CPU); // 1.7 sec at -1x160
// mNet.setPreferableTarget(cv::dnn::DNN_TARGET_OPENCL); // 1.2 sec at -1x160
// mNet.setPreferableTarget(cv::dnn::DNN_TARGET_OPENCL_FP16);
// mNet.setPreferableTarget(cv::dnn::DNN_TARGET_MYRIAD);
// mNet.setPreferableTarget(cv::dnn::DNN_TARGET_VULKAN);
// // Set backen
// mNet.setPreferableBackend(cv::dnn::DNN_BACKEND_DEFAULT);
// mNet.setPreferableBackend(cv::dnn::DNN_BACKEND_HALIDE);
// mNet.setPreferableBackend(cv::dnn::DNN_BACKEND_INFERENCE_ENGINE);
// mNet.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
// mNet.setPreferableBackend(cv::dnn::DNN_BACKEND_VKCOM);
}
#endif
};

#ifdef OPEN_CV_DNN_AVAILABLE
inline void reshapeNetOpenCv(caffe::Net<float>* caffeNet, const std::vector<int>& dimensions)
{
try
{
caffeNet->blobs()[0]->Reshape(dimensions);
caffeNet->Reshape();
#ifdef USE_CUDA
cudaCheck(__LINE__, __FUNCTION__, __FILE__);
#endif
}
catch (const std::exception& e)
{
error(e.what(), __LINE__, __FUNCTION__, __FILE__);
}
}
#endif

NetOpenCv::NetOpenCv(const std::string& caffeProto, const std::string& caffeTrainedModel, const int gpuId)
#ifdef OPEN_CV_DNN_AVAILABLE
: upImpl{new ImplNetOpenCv{caffeProto, caffeTrainedModel, gpuId}}
#endif
{
try
{
#ifndef OPEN_CV_DNN_AVAILABLE
UNUSED(caffeProto);
UNUSED(caffeTrainedModel);
UNUSED(gpuId);
error("OpenPose must be compiled with the `USE_CAFFE` macro definition in order to use this"
" functionality.", __LINE__, __FUNCTION__, __FILE__);
#endif
}
catch (const std::exception& e)
{
error(e.what(), __LINE__, __FUNCTION__, __FILE__);
}
}

NetOpenCv::~NetOpenCv()
{
}

void NetOpenCv::initializationOnThread()
{
}

void NetOpenCv::forwardPass(const Array<float>& inputData) const
{
try
{
#ifdef OPEN_CV_DNN_AVAILABLE
upImpl->mNet.setInput(inputData.getConstCvMat());
upImpl->mNetOutputBlob = upImpl->mNet.forward(); // 99% of the runtime here
std::vector<int> outputSize(upImpl->mNetOutputBlob.dims,0);
for (auto i = 0u ; i < outputSize.size() ; i++)
outputSize[i] = upImpl->mNetOutputBlob.size[i];
upImpl->spOutputBlob->Reshape(outputSize);
auto* gpuImagePtr = upImpl->spOutputBlob->mutable_gpu_data();
cudaMemcpy(gpuImagePtr, (float*)upImpl->mNetOutputBlob.data,
upImpl->spOutputBlob->count() * sizeof(float),
cudaMemcpyHostToDevice);
#else
UNUSED(inputData);
#endif
}
catch (const std::exception& e)
{
error(e.what(), __LINE__, __FUNCTION__, __FILE__);
}
}

boost::shared_ptr<caffe::Blob<float>> NetOpenCv::getOutputBlob() const
{
try
{
#ifdef OPEN_CV_DNN_AVAILABLE
return upImpl->spOutputBlob;
#else
return nullptr;
#endif
}
catch (const std::exception& e)
{
error(e.what(), __LINE__, __FUNCTION__, __FILE__);
return nullptr;
}
}
}
2 changes: 1 addition & 1 deletion src/openpose/net/nmsCaffe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ namespace op
#ifdef USE_CUDA
Forward_gpu(bottom, top);
// OpenCL
#elif USE_OPENCL
#elif defined USE_OPENCL
Forward_ocl(bottom, top);
// CPU
#else
Expand Down
8 changes: 4 additions & 4 deletions src/openpose/net/resizeAndMergeCaffe.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifdef USE_CAFFE
#include <caffe/blob.hpp>
#endif
#include <openpose/net/resizeAndMergeBase.hpp>
#include <openpose/utilities/fastMath.hpp>
#include <openpose/net/resizeAndMergeCaffe.hpp>
#ifdef USE_OPENCL
#include <openpose/gpu/opencl.hcl>
#include <openpose/gpu/cl2.hpp>
#endif
#include <openpose/net/resizeAndMergeBase.hpp>
#include <openpose/utilities/fastMath.hpp>
#include <openpose/net/resizeAndMergeCaffe.hpp>

namespace op
{
Expand Down Expand Up @@ -135,7 +135,7 @@ namespace op
#ifdef USE_CUDA
Forward_gpu(bottom, top);
// OpenCL
#elif USE_OPENCL
#elif defined USE_OPENCL
Forward_ocl(bottom, top);
// CPU
#else
Expand Down
Loading

0 comments on commit 3377d18

Please sign in to comment.