From b0e5de3bf12b7dc2d6bfe1e7b0f953b0421e429e Mon Sep 17 00:00:00 2001 From: gineshidalgo99 Date: Fri, 6 Oct 2017 19:35:56 -0400 Subject: [PATCH] Google flags working on Ubuntu 14 --- examples/openpose/openpose.cpp | 7 ++++- examples/openpose/openposeBasicDemo.cpp | 7 ++++- examples/tests/handFromJsonTest.cpp | 7 ++++- .../tutorial_pose/1_extract_from_image.cpp | 7 ++++- .../2_extract_pose_or_heatmat_from_image.cpp | 7 ++++- .../1_openpose_read_and_display.cpp | 7 ++++- .../2_user_processing_function.cpp | 7 ++++- .../3_user_input_processing_and_output.cpp | 7 ++++- ...user_input_processing_output_and_datum.cpp | 7 ++++- .../1_user_asynchronous_output.cpp | 7 ++++- .../tutorial_wrapper/2_user_synchronous.cpp | 7 ++++- .../tutorial_wrapper/3_user_asynchronous.cpp | 7 ++++- examples_beta/openpose3d/openpose3d.cpp | 7 ++++- include/openpose/utilities/fileSystem.hpp | 4 ++- src/openpose/core/netCaffe.cpp | 9 +++++++ src/openpose/utilities/fileSystem.cpp | 27 ++++++++++++++++--- 16 files changed, 114 insertions(+), 17 deletions(-) diff --git a/examples/openpose/openpose.cpp b/examples/openpose/openpose.cpp index ec6304c3..8cf7539d 100755 --- a/examples/openpose/openpose.cpp +++ b/examples/openpose/openpose.cpp @@ -19,7 +19,12 @@ #include // `std::chrono::` functions and classes, e.g. std::chrono::milliseconds #include // std::this_thread // Other 3rdparty dependencies -#include // DEFINE_bool, DEFINE_int32, DEFINE_int64, DEFINE_uint64, DEFINE_double, DEFINE_string +// GFlags: DEFINE_bool, _int32, _int64, _uint64, _double, _string +#include +// Allow Google Flags in Ubuntu 14 +#ifndef GFLAGS_GFLAGS_H_ + namespace gflags = google; +#endif #include // google::InitGoogleLogging // OpenPose dependencies #include diff --git a/examples/openpose/openposeBasicDemo.cpp b/examples/openpose/openposeBasicDemo.cpp index bbe6a010..9868b18b 100644 --- a/examples/openpose/openposeBasicDemo.cpp +++ b/examples/openpose/openposeBasicDemo.cpp @@ -3,7 +3,12 @@ #include // `std::chrono::` functions and classes, e.g. std::chrono::milliseconds #include // std::this_thread // Other 3rdparty dependencies -#include // DEFINE_bool, DEFINE_int32, DEFINE_int64, DEFINE_uint64, DEFINE_double, DEFINE_string +// GFlags: DEFINE_bool, _int32, _int64, _uint64, _double, _string +#include +// Allow Google Flags in Ubuntu 14 +#ifndef GFLAGS_GFLAGS_H_ + namespace gflags = google; +#endif #include // google::InitGoogleLogging // OpenPose dependencies diff --git a/examples/tests/handFromJsonTest.cpp b/examples/tests/handFromJsonTest.cpp index b24590c7..1595e577 100644 --- a/examples/tests/handFromJsonTest.cpp +++ b/examples/tests/handFromJsonTest.cpp @@ -2,7 +2,12 @@ // Example to test hands accuracy given ground-truth bounding boxes. #include // `std::chrono::` functions and classes, e.g. std::chrono::milliseconds -#include // DEFINE_bool, DEFINE_int32, DEFINE_int64, DEFINE_uint64, DEFINE_double, DEFINE_string +// GFlags: DEFINE_bool, _int32, _int64, _uint64, _double, _string +#include +// Allow Google Flags in Ubuntu 14 +#ifndef GFLAGS_GFLAGS_H_ + namespace gflags = google; +#endif #include // google::InitGoogleLogging #include #include "wrapperHandFromJsonTest.hpp" diff --git a/examples/tutorial_pose/1_extract_from_image.cpp b/examples/tutorial_pose/1_extract_from_image.cpp index 15313190..2d0959d5 100644 --- a/examples/tutorial_pose/1_extract_from_image.cpp +++ b/examples/tutorial_pose/1_extract_from_image.cpp @@ -9,7 +9,12 @@ // 2. `utilities` module: for the error & logging functions, i.e. op::error & op::log respectively // 3rdparty dependencies -#include // DEFINE_bool, DEFINE_int32, DEFINE_int64, DEFINE_uint64, DEFINE_double, DEFINE_string +// GFlags: DEFINE_bool, _int32, _int64, _uint64, _double, _string +#include +// Allow Google Flags in Ubuntu 14 +#ifndef GFLAGS_GFLAGS_H_ + namespace gflags = google; +#endif #include // google::InitGoogleLogging // OpenPose dependencies #include diff --git a/examples/tutorial_pose/2_extract_pose_or_heatmat_from_image.cpp b/examples/tutorial_pose/2_extract_pose_or_heatmat_from_image.cpp index d9d9e6e2..4b0a5a06 100644 --- a/examples/tutorial_pose/2_extract_pose_or_heatmat_from_image.cpp +++ b/examples/tutorial_pose/2_extract_pose_or_heatmat_from_image.cpp @@ -9,7 +9,12 @@ // 2. `utilities` module: for the error & logging functions, i.e. op::error & op::log respectively // 3rdparty dependencies -#include // DEFINE_bool, DEFINE_int32, DEFINE_int64, DEFINE_uint64, DEFINE_double, DEFINE_string +// GFlags: DEFINE_bool, _int32, _int64, _uint64, _double, _string +#include +// Allow Google Flags in Ubuntu 14 +#ifndef GFLAGS_GFLAGS_H_ + namespace gflags = google; +#endif #include // google::InitGoogleLogging // OpenPose dependencies #include diff --git a/examples/tutorial_thread/1_openpose_read_and_display.cpp b/examples/tutorial_thread/1_openpose_read_and_display.cpp index 676c0fcb..0ad74c65 100644 --- a/examples/tutorial_thread/1_openpose_read_and_display.cpp +++ b/examples/tutorial_thread/1_openpose_read_and_display.cpp @@ -8,7 +8,12 @@ // 2. `utilities` module: for the error & logging functions, i.e. op::error & op::log respectively // 3rdparty dependencies -#include // DEFINE_bool, DEFINE_int32, DEFINE_int64, DEFINE_uint64, DEFINE_double, DEFINE_string +// GFlags: DEFINE_bool, _int32, _int64, _uint64, _double, _string +#include +// Allow Google Flags in Ubuntu 14 +#ifndef GFLAGS_GFLAGS_H_ + namespace gflags = google; +#endif #include // google::InitGoogleLogging // OpenPose dependencies #include diff --git a/examples/tutorial_thread/2_user_processing_function.cpp b/examples/tutorial_thread/2_user_processing_function.cpp index 24bf8588..d6a3f0f3 100644 --- a/examples/tutorial_thread/2_user_processing_function.cpp +++ b/examples/tutorial_thread/2_user_processing_function.cpp @@ -9,7 +9,12 @@ // 2. `utilities` module: for the error & logging functions, i.e. op::error & op::log respectively // 3rdparty dependencies -#include // DEFINE_bool, DEFINE_int32, DEFINE_int64, DEFINE_uint64, DEFINE_double, DEFINE_string +// GFlags: DEFINE_bool, _int32, _int64, _uint64, _double, _string +#include +// Allow Google Flags in Ubuntu 14 +#ifndef GFLAGS_GFLAGS_H_ + namespace gflags = google; +#endif #include // google::InitGoogleLogging // OpenPose dependencies #include diff --git a/examples/tutorial_thread/3_user_input_processing_and_output.cpp b/examples/tutorial_thread/3_user_input_processing_and_output.cpp index e8b69153..4df67d8f 100644 --- a/examples/tutorial_thread/3_user_input_processing_and_output.cpp +++ b/examples/tutorial_thread/3_user_input_processing_and_output.cpp @@ -9,7 +9,12 @@ // 2. `utilities` module: for the error & logging functions, i.e. op::error & op::log respectively // 3rdparty dependencies -#include // DEFINE_bool, DEFINE_int32, DEFINE_int64, DEFINE_uint64, DEFINE_double, DEFINE_string +// GFlags: DEFINE_bool, _int32, _int64, _uint64, _double, _string +#include +// Allow Google Flags in Ubuntu 14 +#ifndef GFLAGS_GFLAGS_H_ + namespace gflags = google; +#endif #include // google::InitGoogleLogging // OpenPose dependencies // Option a) Importing all modules diff --git a/examples/tutorial_thread/4_user_input_processing_output_and_datum.cpp b/examples/tutorial_thread/4_user_input_processing_output_and_datum.cpp index 6659c8dd..a55f4c10 100644 --- a/examples/tutorial_thread/4_user_input_processing_output_and_datum.cpp +++ b/examples/tutorial_thread/4_user_input_processing_output_and_datum.cpp @@ -9,7 +9,12 @@ // 2. `utilities` module: for the error & logging functions, i.e. op::error & op::log respectively // 3rdparty dependencies -#include // DEFINE_bool, DEFINE_int32, DEFINE_int64, DEFINE_uint64, DEFINE_double, DEFINE_string +// GFlags: DEFINE_bool, _int32, _int64, _uint64, _double, _string +#include +// Allow Google Flags in Ubuntu 14 +#ifndef GFLAGS_GFLAGS_H_ + namespace gflags = google; +#endif #include // google::InitGoogleLogging // OpenPose dependencies // Option a) Importing all modules diff --git a/examples/tutorial_wrapper/1_user_asynchronous_output.cpp b/examples/tutorial_wrapper/1_user_asynchronous_output.cpp index 9b1dda9e..c86058a9 100644 --- a/examples/tutorial_wrapper/1_user_asynchronous_output.cpp +++ b/examples/tutorial_wrapper/1_user_asynchronous_output.cpp @@ -19,7 +19,12 @@ #include // `std::chrono::` functions and classes, e.g. std::chrono::milliseconds #include // std::this_thread // Other 3rdparty dependencies -#include // DEFINE_bool, DEFINE_int32, DEFINE_int64, DEFINE_uint64, DEFINE_double, DEFINE_string +// GFlags: DEFINE_bool, _int32, _int64, _uint64, _double, _string +#include +// Allow Google Flags in Ubuntu 14 +#ifndef GFLAGS_GFLAGS_H_ + namespace gflags = google; +#endif #include // google::InitGoogleLogging // OpenPose dependencies #include diff --git a/examples/tutorial_wrapper/2_user_synchronous.cpp b/examples/tutorial_wrapper/2_user_synchronous.cpp index 78af7c9f..da941359 100644 --- a/examples/tutorial_wrapper/2_user_synchronous.cpp +++ b/examples/tutorial_wrapper/2_user_synchronous.cpp @@ -19,7 +19,12 @@ #include // `std::chrono::` functions and classes, e.g. std::chrono::milliseconds #include // std::this_thread // Other 3rdparty dependencies -#include // DEFINE_bool, DEFINE_int32, DEFINE_int64, DEFINE_uint64, DEFINE_double, DEFINE_string +// GFlags: DEFINE_bool, _int32, _int64, _uint64, _double, _string +#include +// Allow Google Flags in Ubuntu 14 +#ifndef GFLAGS_GFLAGS_H_ + namespace gflags = google; +#endif #include // google::InitGoogleLogging // OpenPose dependencies #include diff --git a/examples/tutorial_wrapper/3_user_asynchronous.cpp b/examples/tutorial_wrapper/3_user_asynchronous.cpp index 4d862964..d51cb9d2 100644 --- a/examples/tutorial_wrapper/3_user_asynchronous.cpp +++ b/examples/tutorial_wrapper/3_user_asynchronous.cpp @@ -19,7 +19,12 @@ #include // `std::chrono::` functions and classes, e.g. std::chrono::milliseconds #include // std::this_thread // Other 3rdparty dependencies -#include // DEFINE_bool, DEFINE_int32, DEFINE_int64, DEFINE_uint64, DEFINE_double, DEFINE_string +// GFlags: DEFINE_bool, _int32, _int64, _uint64, _double, _string +#include +// Allow Google Flags in Ubuntu 14 +#ifndef GFLAGS_GFLAGS_H_ + namespace gflags = google; +#endif #include // google::InitGoogleLogging // OpenPose dependencies #include diff --git a/examples_beta/openpose3d/openpose3d.cpp b/examples_beta/openpose3d/openpose3d.cpp index 535fc226..7f5567fe 100644 --- a/examples_beta/openpose3d/openpose3d.cpp +++ b/examples_beta/openpose3d/openpose3d.cpp @@ -19,7 +19,12 @@ #include // std::this_thread #include // Other 3rdparty dependencies -#include // DEFINE_bool, DEFINE_int32, DEFINE_int64, DEFINE_uint64, DEFINE_double, DEFINE_string +// GFlags: DEFINE_bool, _int32, _int64, _uint64, _double, _string +#include +// Allow Google Flags in Ubuntu 14 +#ifndef GFLAGS_GFLAGS_H_ + namespace gflags = google; +#endif #include // google::InitGoogleLogging // OpenPose dependencies diff --git a/include/openpose/utilities/fileSystem.hpp b/include/openpose/utilities/fileSystem.hpp index 2a585f32..3e8cf4cd 100644 --- a/include/openpose/utilities/fileSystem.hpp +++ b/include/openpose/utilities/fileSystem.hpp @@ -7,7 +7,9 @@ namespace op { OP_API void mkdir(const std::string& directoryPath); - OP_API bool exist(const std::string& directoryPath); + OP_API bool existDir(const std::string& directoryPath); + + OP_API bool existFile(const std::string& filePath); OP_API bool isDirectory(const std::string& directoryPath); diff --git a/src/openpose/core/netCaffe.cpp b/src/openpose/core/netCaffe.cpp index ac8c9981..f6cdb117 100644 --- a/src/openpose/core/netCaffe.cpp +++ b/src/openpose/core/netCaffe.cpp @@ -3,6 +3,7 @@ #include #endif #include +#include #include namespace op @@ -32,6 +33,14 @@ namespace op mCaffeTrainedModel{caffeTrainedModel}, mLastBlobName{lastBlobName} { + 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__); } #endif }; diff --git a/src/openpose/utilities/fileSystem.cpp b/src/openpose/utilities/fileSystem.cpp index 67a02ba3..d1f62a49 100644 --- a/src/openpose/utilities/fileSystem.cpp +++ b/src/openpose/utilities/fileSystem.cpp @@ -1,7 +1,8 @@ +#include // fopen #include #include -#include #include +#include namespace op { @@ -23,10 +24,11 @@ namespace op } } - bool exist(const std::string& directoryPath) + bool existDir(const std::string& directoryPath) { try { + // Maybe existFile also works for directories in Ubuntu/Windows/Mac? return boost::filesystem::exists(directoryPath); } catch (const std::exception& e) @@ -36,6 +38,25 @@ namespace op } } + bool existFile(const std::string& filePath) + { + try + { + if (auto* file = fopen(filePath.c_str(), "r")) + { + fclose(file); + return true; + } + else + return false; + } + catch (const std::exception& e) + { + error(e.what(), __LINE__, __FUNCTION__, __FILE__); + return false; + } + } + bool isDirectory(const std::string& directoryPath) { try @@ -153,7 +174,7 @@ namespace op try { // Check folder exits - if (!exist(directoryPath)) + if (!existDir(directoryPath)) error("Folder " + directoryPath + " does not exist.", __LINE__, __FUNCTION__, __FILE__); // Read images std::vector filePaths; -- GitLab