提交 5de57b80 编写于 作者: G gineshidalgo99

GLog not required in demos

上级 35a02f16
......@@ -25,7 +25,6 @@
#ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
#endif
#include <glog/logging.h> // google::InitGoogleLogging
// OpenPose dependencies
#include <openpose/headers.hpp>
......@@ -197,6 +196,9 @@ int openPoseDemo()
const auto keypointScale = op::flagsToScaleMode(FLAGS_keypoint_scale);
// heatmaps to add
const auto heatMapTypes = op::flagsToHeatMaps(FLAGS_heatmaps_add_parts, FLAGS_heatmaps_add_bkg, FLAGS_heatmaps_add_PAFs);
// Enabling Google Logging
const bool enableGoogleLogging = true;
// Logging
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// OpenPose wrapper
......@@ -208,7 +210,8 @@ int openPoseDemo()
op::flagsToRenderMode(FLAGS_render_pose), poseModel,
!FLAGS_disable_blending, (float)FLAGS_alpha_pose,
(float)FLAGS_alpha_heatmap, FLAGS_part_to_show, FLAGS_model_folder,
heatMapTypes, op::ScaleMode::UnsignedChar, (float)FLAGS_render_threshold};
heatMapTypes, op::ScaleMode::UnsignedChar, (float)FLAGS_render_threshold,
enableGoogleLogging};
// Face configuration (use op::WrapperStructFace{} to disable it)
const op::WrapperStructFace wrapperStructFace{FLAGS_face, faceNetInputSize, op::flagsToRenderMode(FLAGS_face_render, FLAGS_render_pose),
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
......@@ -267,9 +270,6 @@ int openPoseDemo()
int main(int argc, char *argv[])
{
// Initializing google logging (Caffe uses it for logging)
google::InitGoogleLogging("openPoseDemo");
// Parsing command line flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
......
// ------------------------- OpenPose Library Tutorial - Real Time Pose Estimation -------------------------
// C++ std library dependencies
#include <chrono> // `std::chrono::` functions and classes, e.g. std::chrono::milliseconds
#include <thread> // std::this_thread
// Other 3rdparty dependencies
// GFlags: DEFINE_bool, _int32, _int64, _uint64, _double, _string
#include <gflags/gflags.h>
// Allow Google Flags in Ubuntu 14
#ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
#endif
#include <glog/logging.h> // google::InitGoogleLogging
// OpenPose dependencies
#include <openpose/headers.hpp>
// See all the available parameter options withe the `--help` flag. E.g. `./build/examples/openpose/openpose.bin --help`.
// Note: This command will show you flags for other unnecessary 3rdparty files. Check only the flags for the OpenPose
// executable. E.g. for `openpose.bin`, look for `Flags from examples/openpose/openpose.cpp:`.
// Producer
DEFINE_int32(camera, -1, "The camera index for cv::VideoCapture. Integer in the range [0, 9]. Select a negative"
" number (by default), to auto-detect and open the first available camera.");
DEFINE_string(camera_resolution, "1280x720", "Size of the camera frames to ask for.");
DEFINE_double(camera_fps, 30.0, "Frame rate for the webcam (only used when saving video from webcam). Set this value to the"
" minimum value between the OpenPose displayed speed and the webcam real frame rate.");
DEFINE_string(video, "", "Use a video file instead of the camera. Use `examples/media/video.avi` for our default"
" example video.");
DEFINE_string(image_dir, "", "Process a directory of images. Use `examples/media/` for our default example folder with 20"
" images. Read all standard formats (jpg, png, bmp, etc.).");
DEFINE_string(ip_camera, "", "String with the IP camera URL. It supports protocols like RTSP and HTTP.");
// Display
DEFINE_bool(no_gui_verbose, false, "Do not write text on output images on GUI (e.g. number of current frame and people). It"
" does not affect the pose rendering.");
DEFINE_bool(no_display, false, "Do not open a display window. Useful if there is no X server and/or to slightly speed up"
" the processing if visual output is not required.");
int openPoseDemo()
{
op::log("Starting pose estimation demo.", op::Priority::High);
const auto timerBegin = std::chrono::high_resolution_clock::now();
// Applying user defined configuration - Google flags to program variables
const auto producerSharedPtr = op::flagsToProducer(FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera,
FLAGS_camera_resolution, FLAGS_camera_fps);
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// OpenPose wrapper
op::log("Configuring OpenPose wrapper.", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
op::Wrapper<std::vector<op::Datum>> opWrapper;
// Pose configuration (use WrapperStructPose{} for default and recommended configuration)
op::WrapperStructPose wrapperStructPose{};
wrapperStructPose.renderMode = op::RenderMode::Gpu;
// Producer (use default to disable any input)
const op::WrapperStructInput wrapperStructInput{producerSharedPtr};
// Consumer (comment or use default argument to disable any output)
const op::WrapperStructOutput wrapperStructOutput{!FLAGS_no_display, !FLAGS_no_gui_verbose};
// Configure wrapper
opWrapper.configure(wrapperStructPose, wrapperStructInput, wrapperStructOutput);
// Set to single-thread running (e.g. for debugging purposes)
// opWrapper.disableMultiThreading();
// Start processing
// Two different ways of running the program on multithread environment
op::log("Starting thread(s)", op::Priority::High);
opWrapper.exec(); // It blocks this thread until all threads have finished
// Measuring total time
const auto now = std::chrono::high_resolution_clock::now();
const auto totalTimeSec = (double)std::chrono::duration_cast<std::chrono::nanoseconds>(now-timerBegin).count() * 1e-9;
const auto message = "Real-time pose estimation demo successfully finished. Total time: " + std::to_string(totalTimeSec) + " seconds.";
op::log(message, op::Priority::High);
return 0;
}
int main(int argc, char *argv[])
{
// Initializing google logging (Caffe uses it for logging)
google::InitGoogleLogging("openPoseDemo");
// Parsing command line flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
// Running openPoseDemo
return openPoseDemo();
}
......@@ -8,7 +8,6 @@
#ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
#endif
#include <glog/logging.h> // google::InitGoogleLogging
#include <openpose/headers.hpp>
#include "wrapperHandFromJsonTest.hpp"
......@@ -36,7 +35,8 @@ DEFINE_string(write_keypoint_json, "", "");
int handFromJsonTest()
{
// logging_level
op::check(0 <= FLAGS_logging_level && FLAGS_logging_level <= 255, "Wrong logging_level value.", __LINE__, __FUNCTION__, __FILE__);
op::check(0 <= FLAGS_logging_level && FLAGS_logging_level <= 255, "Wrong logging_level value.",
__LINE__, __FUNCTION__, __FILE__);
op::ConfigureLog::setPriorityThreshold((op::Priority)FLAGS_logging_level);
// op::ConfigureLog::setPriorityThreshold(op::Priority::None); // To print all logging messages
......@@ -48,22 +48,26 @@ int handFromJsonTest()
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
// producerType
const auto producerSharedPtr = op::flagsToProducer(FLAGS_image_dir, "", "", 0);
// Enabling Google Logging
const bool enableGoogleLogging = true;
// Logging
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// OpenPose wrapper
op::log("Configuring OpenPose wrapper.", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
op::WrapperHandFromJsonTest<std::vector<op::Datum>> opWrapper;
// Pose configuration (use WrapperStructPose{} for default and recommended configuration)
op::WrapperStructPose wrapperStructPose{true, op::flagsToPoint("656x368"), op::flagsToPoint("1280x720"),
op::ScaleMode::InputResolution, FLAGS_num_gpu, FLAGS_num_gpu_start};
op::WrapperStructPose wrapperStructPose{false, op::flagsToPoint("656x368"), op::flagsToPoint("1280x720"),
op::ScaleMode::InputResolution, FLAGS_num_gpu, FLAGS_num_gpu_start,
true, enableGoogleLogging};
wrapperStructPose.modelFolder = FLAGS_model_folder;
// Hand configuration (use op::WrapperStructHand{} to disable it)
const op::WrapperStructHand wrapperStructHand{FLAGS_hand, handNetInputSize, FLAGS_hand_scale_number,
(float)FLAGS_hand_scale_range, FLAGS_hand_tracking,
op::flagsToRenderMode(1)};
// Configure wrapper
opWrapper.configure(wrapperStructPose, wrapperStructHand, producerSharedPtr, FLAGS_hand_ground_truth, FLAGS_write_keypoint_json,
!FLAGS_no_display);
opWrapper.configure(wrapperStructPose, wrapperStructHand, producerSharedPtr, FLAGS_hand_ground_truth,
FLAGS_write_keypoint_json, !FLAGS_no_display);
// Start processing
op::log("Starting thread(s)", op::Priority::High);
......@@ -72,7 +76,8 @@ int handFromJsonTest()
// Measuring total time
const auto now = std::chrono::high_resolution_clock::now();
const auto totalTimeSec = (double)std::chrono::duration_cast<std::chrono::nanoseconds>(now-timerBegin).count() * 1e-9;
const auto message = "Real-time pose estimation demo successfully finished. Total time: " + std::to_string(totalTimeSec) + " seconds.";
const auto message = "Real-time pose estimation demo successfully finished. Total time: "
+ std::to_string(totalTimeSec) + " seconds.";
op::log(message, op::Priority::High);
return 0;
......@@ -80,9 +85,6 @@ int handFromJsonTest()
int main(int argc, char *argv[])
{
// Initializing google logging (Caffe uses it for logging)
google::InitGoogleLogging("handFromJsonTest");
// Parsing command line flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
......
......@@ -15,7 +15,6 @@
#ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
#endif
#include <glog/logging.h> // google::InitGoogleLogging
// OpenPose dependencies
#include <openpose/core/headers.hpp>
#include <openpose/filestream/headers.hpp>
......@@ -86,6 +85,8 @@ int openPoseTutorialPose1()
if (FLAGS_scale_gap <= 0. && FLAGS_scale_number > 1)
op::error("Incompatible flag configuration: scale_gap must be greater than 0 or scale_number = 1.",
__LINE__, __FUNCTION__, __FILE__);
// Enabling Google Logging
const bool enableGoogleLogging = true;
// Logging
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// Step 3 - Initialize all required classes
......@@ -93,7 +94,8 @@ int openPoseTutorialPose1()
op::CvMatToOpInput cvMatToOpInput;
op::CvMatToOpOutput cvMatToOpOutput;
op::PoseExtractorCaffe poseExtractorCaffe{netInputSize, netOutputSize, outputSize, FLAGS_scale_number, poseModel,
FLAGS_model_folder, FLAGS_num_gpu_start};
FLAGS_model_folder, FLAGS_num_gpu_start, {}, op::ScaleMode::ZeroToOne,
enableGoogleLogging};
op::PoseCpuRenderer poseRenderer{poseModel, (float)FLAGS_render_threshold, !FLAGS_disable_blending,
(float)FLAGS_alpha_pose};
op::OpOutputToCvMat opOutputToCvMat;
......@@ -138,9 +140,6 @@ int openPoseTutorialPose1()
int main(int argc, char *argv[])
{
// Initializing google logging (Caffe uses it for logging)
google::InitGoogleLogging("openPoseTutorialPose1");
// Parsing command line flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
......
......@@ -15,7 +15,6 @@
#ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
#endif
#include <glog/logging.h> // google::InitGoogleLogging
// OpenPose dependencies
#include <openpose/core/headers.hpp>
#include <openpose/filestream/headers.hpp>
......@@ -91,6 +90,8 @@ int openPoseTutorialPose2()
if (FLAGS_scale_gap <= 0. && FLAGS_scale_number > 1)
op::error("Incompatible flag configuration: scale_gap must be greater than 0 or scale_number = 1.",
__LINE__, __FUNCTION__, __FILE__);
// Enabling Google Logging
const bool enableGoogleLogging = true;
// Logging
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// Step 3 - Initialize all required classes
......@@ -98,7 +99,8 @@ int openPoseTutorialPose2()
op::CvMatToOpInput cvMatToOpInput;
op::CvMatToOpOutput cvMatToOpOutput;
auto poseExtractorPtr = std::make_shared<op::PoseExtractorCaffe>(
netInputSize, netOutputSize, outputSize, FLAGS_scale_number, poseModel, FLAGS_model_folder, FLAGS_num_gpu_start
netInputSize, netOutputSize, outputSize, FLAGS_scale_number, poseModel, FLAGS_model_folder,
FLAGS_num_gpu_start, std::vector<op::HeatMapType>{}, op::ScaleMode::ZeroToOne, enableGoogleLogging
);
op::PoseGpuRenderer poseGpuRenderer{poseModel, poseExtractorPtr, (float)FLAGS_render_threshold,
!FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap};
......@@ -146,9 +148,6 @@ int openPoseTutorialPose2()
int main(int argc, char *argv[])
{
// Initializing google logging (Caffe uses it for logging)
google::InitGoogleLogging("openPoseTutorialPose2");
// Parsing command line flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
......
......@@ -14,7 +14,6 @@
#ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
#endif
#include <glog/logging.h> // google::InitGoogleLogging
// OpenPose dependencies
#include <openpose/core/headers.hpp>
#include <openpose/gui/headers.hpp>
......@@ -71,7 +70,7 @@ int openPoseTutorialThread1()
videoSeekSharedPtr->first = false;
videoSeekSharedPtr->second = 0;
const op::Point<int> producerSize{(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_WIDTH),
(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_HEIGHT)};
(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_HEIGHT)};
// Step 4 - Setting thread workers && manager
typedef std::vector<op::Datum> TypedefDatumsNoPtr;
typedef std::shared_ptr<TypedefDatumsNoPtr> TypedefDatums;
......@@ -138,9 +137,6 @@ int openPoseTutorialThread1()
int main(int argc, char *argv[])
{
// Initializing google logging (Caffe uses it for logging)
google::InitGoogleLogging("openPoseTutorialThread1");
// Parsing command line flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
......
......@@ -15,7 +15,6 @@
#ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
#endif
#include <glog/logging.h> // google::InitGoogleLogging
// OpenPose dependencies
#include <openpose/core/headers.hpp>
#include <openpose/gui/headers.hpp>
......@@ -180,9 +179,6 @@ int openPoseTutorialThread2()
int main(int argc, char *argv[])
{
// Initializing google logging (Caffe uses it for logging)
google::InitGoogleLogging("openPoseTutorialThread2");
// Parsing command line flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
......
......@@ -15,7 +15,6 @@
#ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
#endif
#include <glog/logging.h> // google::InitGoogleLogging
// OpenPose dependencies
// Option a) Importing all modules
#include <openpose/headers.hpp>
......@@ -228,9 +227,6 @@ int openPoseTutorialThread3()
int main(int argc, char *argv[])
{
// Initializing google logging (Caffe uses it for logging)
google::InitGoogleLogging("openPoseTutorialThread3");
// Parsing command line flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
......
......@@ -15,7 +15,6 @@
#ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
#endif
#include <glog/logging.h> // google::InitGoogleLogging
// OpenPose dependencies
// Option a) Importing all modules
#include <openpose/headers.hpp>
......@@ -241,9 +240,6 @@ int openPoseTutorialThread4()
int main(int argc, char *argv[])
{
// Initializing google logging (Caffe uses it for logging)
google::InitGoogleLogging("openPoseTutorialThread4");
// Parsing command line flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
......
......@@ -25,7 +25,6 @@
#ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
#endif
#include <glog/logging.h> // google::InitGoogleLogging
// OpenPose dependencies
#include <openpose/headers.hpp>
......@@ -289,6 +288,9 @@ int openPoseTutorialWrapper3()
op::check(FLAGS_heatmaps_scale >= 0 && FLAGS_heatmaps_scale <= 2, "Non valid `heatmaps_scale`.", __LINE__, __FUNCTION__, __FILE__);
const auto heatMapScale = (FLAGS_heatmaps_scale == 0 ? op::ScaleMode::PlusMinusOne
: (FLAGS_heatmaps_scale == 1 ? op::ScaleMode::ZeroToOne : op::ScaleMode::UnsignedChar ));
// Enabling Google Logging
const bool enableGoogleLogging = true;
// Logging
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// Configure OpenPose
......@@ -300,7 +302,8 @@ int openPoseTutorialWrapper3()
op::flagsToRenderMode(FLAGS_render_pose), poseModel,
!FLAGS_disable_blending, (float)FLAGS_alpha_pose,
(float)FLAGS_alpha_heatmap, FLAGS_part_to_show, FLAGS_model_folder,
heatMapTypes, heatMapScale, (float)FLAGS_render_threshold};
heatMapTypes, heatMapScale, (float)FLAGS_render_threshold,
enableGoogleLogging};
// Face configuration (use op::WrapperStructFace{} to disable it)
const op::WrapperStructFace wrapperStructFace{FLAGS_face, faceNetInputSize, op::flagsToRenderMode(FLAGS_face_render, FLAGS_render_pose),
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
......@@ -357,9 +360,6 @@ int openPoseTutorialWrapper3()
int main(int argc, char *argv[])
{
// Initializing google logging (Caffe uses it for logging)
google::InitGoogleLogging("openPoseTutorialWrapper3");
// Parsing command line flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
......
......@@ -25,7 +25,6 @@
#ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
#endif
#include <glog/logging.h> // google::InitGoogleLogging
// OpenPose dependencies
#include <openpose/headers.hpp>
......@@ -365,6 +364,9 @@ int openPoseTutorialWrapper2()
op::check(FLAGS_heatmaps_scale >= 0 && FLAGS_heatmaps_scale <= 2, "Non valid `heatmaps_scale`.", __LINE__, __FUNCTION__, __FILE__);
const auto heatMapScale = (FLAGS_heatmaps_scale == 0 ? op::ScaleMode::PlusMinusOne
: (FLAGS_heatmaps_scale == 1 ? op::ScaleMode::ZeroToOne : op::ScaleMode::UnsignedChar ));
// Enabling Google Logging
const bool enableGoogleLogging = true;
// Logging
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// Initializing the user custom classes
......@@ -392,7 +394,8 @@ int openPoseTutorialWrapper2()
op::flagsToRenderMode(FLAGS_render_pose), poseModel,
!FLAGS_disable_blending, (float)FLAGS_alpha_pose,
(float)FLAGS_alpha_heatmap, FLAGS_part_to_show, FLAGS_model_folder,
heatMapTypes, heatMapScale, (float)FLAGS_render_threshold};
heatMapTypes, heatMapScale, (float)FLAGS_render_threshold,
enableGoogleLogging};
// Face configuration (use op::WrapperStructFace{} to disable it)
const op::WrapperStructFace wrapperStructFace{FLAGS_face, faceNetInputSize, op::flagsToRenderMode(FLAGS_face_render, FLAGS_render_pose),
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
......@@ -448,9 +451,6 @@ int openPoseTutorialWrapper2()
int main(int argc, char *argv[])
{
// Initializing google logging (Caffe uses it for logging)
google::InitGoogleLogging("openPoseTutorialWrapper2");
// Parsing command line flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
......
......@@ -25,7 +25,6 @@
#ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
#endif
#include <glog/logging.h> // google::InitGoogleLogging
// OpenPose dependencies
#include <openpose/headers.hpp>
......@@ -324,6 +323,9 @@ int openPoseTutorialWrapper1()
op::check(FLAGS_heatmaps_scale >= 0 && FLAGS_heatmaps_scale <= 2, "Non valid `heatmaps_scale`.", __LINE__, __FUNCTION__, __FILE__);
const auto heatMapScale = (FLAGS_heatmaps_scale == 0 ? op::ScaleMode::PlusMinusOne
: (FLAGS_heatmaps_scale == 1 ? op::ScaleMode::ZeroToOne : op::ScaleMode::UnsignedChar ));
// Enabling Google Logging
const bool enableGoogleLogging = true;
// Logging
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// Configure OpenPose
......@@ -334,7 +336,8 @@ int openPoseTutorialWrapper1()
op::flagsToRenderMode(FLAGS_render_pose), poseModel,
!FLAGS_disable_blending, (float)FLAGS_alpha_pose,
(float)FLAGS_alpha_heatmap, FLAGS_part_to_show, FLAGS_model_folder,
heatMapTypes, heatMapScale, (float)FLAGS_render_threshold};
heatMapTypes, heatMapScale, (float)FLAGS_render_threshold,
enableGoogleLogging};
// Face configuration (use op::WrapperStructFace{} to disable it)
const op::WrapperStructFace wrapperStructFace{FLAGS_face, faceNetInputSize, op::flagsToRenderMode(FLAGS_face_render, FLAGS_render_pose),
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
......@@ -396,9 +399,6 @@ int openPoseTutorialWrapper1()
int main(int argc, char *argv[])
{
// Initializing google logging (Caffe uses it for logging)
google::InitGoogleLogging("openPoseTutorialWrapper1");
// Parsing command line flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
......
......@@ -25,7 +25,6 @@
#ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
#endif
#include <glog/logging.h> // google::InitGoogleLogging
// OpenPose dependencies
#include <openpose/headers.hpp>
......@@ -177,6 +176,9 @@ int openpose3d()
op::check(FLAGS_heatmaps_scale >= 0 && FLAGS_heatmaps_scale <= 2, "Non valid `heatmaps_scale`.", __LINE__, __FUNCTION__, __FILE__);
const auto heatMapScale = (FLAGS_heatmaps_scale == 0 ? op::ScaleMode::PlusMinusOne
: (FLAGS_heatmaps_scale == 1 ? op::ScaleMode::ZeroToOne : op::ScaleMode::UnsignedChar ));
// Enabling Google Logging
const bool enableGoogleLogging = true;
// Logging
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// Initializing the user custom classes
......@@ -203,7 +205,8 @@ int openpose3d()
op::flagsToRenderMode(FLAGS_render_pose), poseModel,
!FLAGS_disable_blending, (float)FLAGS_alpha_pose,
(float)FLAGS_alpha_heatmap, FLAGS_part_to_show, FLAGS_model_folder,
heatMapTypes, heatMapScale, (float)FLAGS_render_threshold};
heatMapTypes, heatMapScale, (float)FLAGS_render_threshold,
enableGoogleLogging};
// Face configuration (use op::WrapperStructFace{} to disable it)
const op::WrapperStructFace wrapperStructFace{FLAGS_face, faceNetInputSize, op::flagsToRenderMode(FLAGS_face_render, FLAGS_render_pose),
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
......@@ -239,9 +242,6 @@ int openpose3d()
int main(int argc, char *argv[])
{
// Initializing google logging (Caffe uses it for logging)
google::InitGoogleLogging("openpose3d");
// Parsing command line flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
......
......@@ -11,6 +11,7 @@ namespace op
public:
NetCaffe(const std::array<int, 4>& netInputSize4D, const std::string& caffeProto,
const std::string& caffeTrainedModel, const int gpuId = 0,
const bool enableGoogleLogging = true,
const std::string& lastBlobName = "net_output");
virtual ~NetCaffe();
......
......@@ -19,10 +19,11 @@ namespace op
* @param netInputSize Size at which the cropped image (where the face is located) is resized.
* @param netOutputSize Size of the final results. At the moment, it must be equal than netOutputSize.
*/
explicit FaceExtractorCaffe(const Point<int>& netInputSize, const Point<int>& netOutputSize,
const std::string& modelFolder, const int gpuId,
const std::vector<HeatMapType>& heatMapTypes = {},
const ScaleMode heatMapScale = ScaleMode::ZeroToOne);
FaceExtractorCaffe(const Point<int>& netInputSize, const Point<int>& netOutputSize,
const std::string& modelFolder, const int gpuId,
const std::vector<HeatMapType>& heatMapTypes = {},
const ScaleMode heatMapScale = ScaleMode::ZeroToOne,
const bool enableGoogleLogging = true);
virtual ~FaceExtractorCaffe();
......
......@@ -24,11 +24,12 @@ namespace op
* accurate.
* @param rangeScales The range between the smaller and bigger scale.
*/
explicit HandExtractorCaffe(const Point<int>& netInputSize, const Point<int>& netOutputSize,
const std::string& modelFolder, const int gpuId,
const unsigned short numberScales = 1, const float rangeScales = 0.4f,
const std::vector<HeatMapType>& heatMapTypes = {},
const ScaleMode heatMapScale = ScaleMode::ZeroToOne);
HandExtractorCaffe(const Point<int>& netInputSize, const Point<int>& netOutputSize,
const std::string& modelFolder, const int gpuId,
const unsigned short numberScales = 1, const float rangeScales = 0.4f,
const std::vector<HeatMapType>& heatMapTypes = {},
const ScaleMode heatMapScale = ScaleMode::ZeroToOne,
const bool enableGoogleLogging = true);
/**
* Virtual destructor of the HandExtractor class.
......
......@@ -14,7 +14,8 @@ namespace op
const Point<int>& outputSize, const int scaleNumber, const PoseModel poseModel,
const std::string& modelFolder, const int gpuId,
const std::vector<HeatMapType>& heatMapTypes = {},
const ScaleMode heatMapScale = ScaleMode::ZeroToOne);
const ScaleMode heatMapScale = ScaleMode::ZeroToOne,
const bool enableGoogleLogging = true);
virtual ~PoseExtractorCaffe();
......
......@@ -641,7 +641,8 @@ namespace op
poseExtractors.emplace_back(std::make_shared<PoseExtractorCaffe>(
poseNetInputSize, poseNetOutputSize, finalOutputSize, wrapperStructPose.scalesNumber,
wrapperStructPose.poseModel, modelFolder, gpuId + gpuNumberStart,
wrapperStructPose.heatMapTypes, wrapperStructPose.heatMapScale
wrapperStructPose.heatMapTypes, wrapperStructPose.heatMapScale,
wrapperStructPose.enableGoogleLogging
));
// Pose renderers
......@@ -714,7 +715,8 @@ namespace op
const auto netOutputSize = wrapperStructFace.netInputSize;
const auto faceExtractor = std::make_shared<FaceExtractorCaffe>(
wrapperStructFace.netInputSize, netOutputSize, modelFolder,
gpu + gpuNumberStart, wrapperStructPose.heatMapTypes, wrapperStructPose.heatMapScale
gpu + gpuNumberStart, wrapperStructPose.heatMapTypes, wrapperStructPose.heatMapScale,
wrapperStructPose.enableGoogleLogging
);
spWPoses.at(gpu).emplace_back(std::make_shared<WFaceExtractor<TDatumsPtr>>(faceExtractor));
}
......@@ -740,7 +742,8 @@ namespace op
const auto handExtractor = std::make_shared<HandExtractorCaffe>(
wrapperStructHand.netInputSize, netOutputSize, modelFolder,
gpu + gpuNumberStart, wrapperStructHand.scalesNumber, wrapperStructHand.scaleRange,
wrapperStructPose.heatMapTypes, wrapperStructPose.heatMapScale
wrapperStructPose.heatMapTypes, wrapperStructPose.heatMapScale,
wrapperStructPose.enableGoogleLogging
);
spWPoses.at(gpu).emplace_back(std::make_shared<WHandExtractor<TDatumsPtr>>(handExtractor));
// If tracking
......
......@@ -141,6 +141,15 @@ namespace op
*/
float renderThreshold;
/**
* Whether to internally enable Google Logging.
* This option is only applicable if Caffe is used.
* Only disable it if the user is already calling google::InitGoogleLogging() in his code.
* If the user disables Google Logging and he does not call it by himself, then Caffe will start to pop up
* all the verbose messages.
*/
bool enableGoogleLogging;
/**
* Constructor of the struct.
* It has the recommended and default values we recommend for each element of the struct.
......@@ -157,7 +166,8 @@ namespace op
const int defaultPartToRender = 0, const std::string& modelFolder = "models/",
const std::vector<HeatMapType>& heatMapTypes = {},
const ScaleMode heatMapScale = ScaleMode::ZeroToOne,
const float renderThreshold = 0.05f);
const float renderThreshold = 0.05f,
const bool enableGoogleLogging = true);
};
}
......
#include <numeric> // std::accumulate
#ifdef USE_CAFFE
#include <atomic>
#include <mutex>
#include <caffe/net.hpp>
#include <glog/logging.h> // google::InitGoogleLogging
#endif
#include <openpose/utilities/cuda.hpp>
#include <openpose/utilities/fileSystem.hpp>
......@@ -8,6 +11,9 @@
namespace op
{
std::mutex sMutex;
std::atomic<bool> sGoogleLoggingInitialized{false};
struct NetCaffe::ImplNetCaffe
{
#ifdef USE_CAFFE
......@@ -23,7 +29,8 @@ namespace op
boost::shared_ptr<caffe::Blob<float>> spOutputBlob;
ImplNetCaffe(const std::array<int, 4>& netInputSize4D, const std::string& caffeProto,
const std::string& caffeTrainedModel, const int gpuId, const std::string& lastBlobName) :
const std::string& caffeTrainedModel, const int gpuId,
const bool enableGoogleLogging, const std::string& lastBlobName) :
mGpuId{gpuId},
// mNetInputSize4D{netInputSize4D}, // This line crashes on some devices with old G++
mNetInputSize4D{netInputSize4D[0], netInputSize4D[1], netInputSize4D[2], netInputSize4D[3]},
......@@ -41,14 +48,26 @@ namespace op
if (!existFile(mCaffeTrainedModel))
error("Caffe trained model file not found: " + mCaffeTrainedModel + message,
__LINE__, __FUNCTION__, __FILE__);
// Double if condition in order to speed up the program if it is called several times
if (enableGoogleLogging && !sGoogleLoggingInitialized)
{
std::lock_guard<std::mutex> lock{sMutex};
if (enableGoogleLogging && !sGoogleLoggingInitialized)
{
google::InitGoogleLogging("OpenPose");
sGoogleLoggingInitialized = true;
}
}
}
#endif
};
NetCaffe::NetCaffe(const std::array<int, 4>& netInputSize4D, const std::string& caffeProto,
const std::string& caffeTrainedModel, const int gpuId, const std::string& lastBlobName)
const std::string& caffeTrainedModel, const int gpuId,
const bool enableGoogleLogging, const std::string& lastBlobName)
#ifdef USE_CAFFE
: upImpl{new ImplNetCaffe{netInputSize4D, caffeProto, caffeTrainedModel, gpuId, lastBlobName}}
: upImpl{new ImplNetCaffe{netInputSize4D, caffeProto, caffeTrainedModel, gpuId, enableGoogleLogging,
lastBlobName}}
#endif
{
try
......
......@@ -25,10 +25,11 @@ namespace op
std::shared_ptr<caffe::Blob<float>> spPeaksBlob;
ImplFaceExtractorCaffe(const Point<int>& netOutputSize,
const std::string& modelFolder, const int gpuId) :
const std::string& modelFolder, const int gpuId,
const bool enableGoogleLogging) :
spNetCaffe{std::make_shared<NetCaffe>(std::array<int,4>{1, 3, netOutputSize.y, netOutputSize.x},
modelFolder + FACE_PROTOTXT, modelFolder + FACE_TRAINED_MODEL,
gpuId)},
gpuId, enableGoogleLogging)},
spResizeAndMergeCaffe{std::make_shared<ResizeAndMergeCaffe<float>>()},
spMaximumCaffe{std::make_shared<MaximumCaffe<float>>()}
{
......@@ -73,10 +74,10 @@ namespace op
FaceExtractorCaffe::FaceExtractorCaffe(const Point<int>& netInputSize, const Point<int>& netOutputSize,
const std::string& modelFolder, const int gpuId,
const std::vector<HeatMapType>& heatMapTypes,
const ScaleMode heatMapScale) :
const ScaleMode heatMapScale, const bool enableGoogleLogging) :
FaceExtractor{netInputSize, netOutputSize, heatMapTypes, heatMapScale}
#if defined USE_CAFFE && defined USE_CUDA
, upImpl{new ImplFaceExtractorCaffe{mNetOutputSize, modelFolder, gpuId}}
, upImpl{new ImplFaceExtractorCaffe{mNetOutputSize, modelFolder, gpuId, enableGoogleLogging}}
#endif
{
try
......
......@@ -26,10 +26,11 @@ namespace op
std::shared_ptr<caffe::Blob<float>> spPeaksBlob;
ImplHandExtractorCaffe(const Point<int>& netOutputSize,
const std::string& modelFolder, const int gpuId) :
const std::string& modelFolder, const int gpuId,
const bool enableGoogleLogging) :
spNetCaffe{std::make_shared<NetCaffe>(std::array<int,4>{1, 3, netOutputSize.y, netOutputSize.x},
modelFolder + HAND_PROTOTXT, modelFolder + HAND_TRAINED_MODEL,
gpuId)},
gpuId, enableGoogleLogging)},
spResizeAndMergeCaffe{std::make_shared<ResizeAndMergeCaffe<float>>()},
spMaximumCaffe{std::make_shared<MaximumCaffe<float>>()}
{
......@@ -159,10 +160,11 @@ namespace op
const std::string& modelFolder, const int gpuId,
const unsigned short numberScales,
const float rangeScales, const std::vector<HeatMapType>& heatMapTypes,
const ScaleMode heatMapScale) :
const ScaleMode heatMapScale,
const bool enableGoogleLogging) :
HandExtractor{netInputSize, netOutputSize, numberScales, rangeScales, heatMapTypes, heatMapScale}
#if defined USE_CAFFE && defined USE_CUDA
, upImpl{new ImplHandExtractorCaffe{mNetOutputSize, modelFolder, gpuId}}
, upImpl{new ImplHandExtractorCaffe{mNetOutputSize, modelFolder, gpuId, enableGoogleLogging}}
#endif
{
try
......
......@@ -30,12 +30,13 @@ namespace op
ImplPoseExtractorCaffe(const Point<int>& netInputSize, const Point<int>& netOutputSize,
const int scaleNumber, const PoseModel poseModel, const int gpuId,
const std::string& modelFolder) :
const std::string& modelFolder, const bool enableGoogleLogging) :
mResizeScale{netOutputSize.x / (float)netInputSize.x},
spNetCaffe{std::make_shared<NetCaffe>(std::array<int,4>{scaleNumber, 3, (int)netInputSize.y,
(int)netInputSize.x},
modelFolder + POSE_PROTOTXT[(int)poseModel],
modelFolder + POSE_TRAINED_MODEL[(int)poseModel], gpuId)},
modelFolder + POSE_TRAINED_MODEL[(int)poseModel], gpuId,
enableGoogleLogging)},
spResizeAndMergeCaffe{std::make_shared<ResizeAndMergeCaffe<float>>()},
spNmsCaffe{std::make_shared<NmsCaffe<float>>()},
spBodyPartConnectorCaffe{std::make_shared<BodyPartConnectorCaffe<float>>()}
......@@ -48,11 +49,11 @@ namespace op
const Point<int>& outputSize, const int scaleNumber,
const PoseModel poseModel, const std::string& modelFolder,
const int gpuId, const std::vector<HeatMapType>& heatMapTypes,
const ScaleMode heatMapScale) :
const ScaleMode heatMapScale, const bool enableGoogleLogging) :
PoseExtractor{netOutputSize, outputSize, poseModel, heatMapTypes, heatMapScale}
#ifdef USE_CAFFE
, upImpl{new ImplPoseExtractorCaffe{netInputSize, netOutputSize, scaleNumber, poseModel,
gpuId, modelFolder}}
gpuId, modelFolder, enableGoogleLogging}}
#endif
{
try
......
......@@ -11,7 +11,8 @@ namespace op
const float alphaHeatMap_, const int defaultPartToRender_,
const std::string& modelFolder_,
const std::vector<HeatMapType>& heatMapTypes_,
const ScaleMode heatMapScale_, const float renderThreshold_) :
const ScaleMode heatMapScale_, const float renderThreshold_,
const bool enableGoogleLogging_) :
enable{enable_},
netInputSize{netInputSize_},
outputSize{outputSize_},
......@@ -29,7 +30,8 @@ namespace op
modelFolder{modelFolder_},
heatMapTypes{heatMapTypes_},
heatMapScale{heatMapScale_},
renderThreshold{renderThreshold_}
renderThreshold{renderThreshold_},
enableGoogleLogging{enableGoogleLogging_}
{
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册