mirror of
https://github.com/gosticks/openpose.git
synced 2026-08-12 20:30:20 +00:00
Examples highly improved
This commit is contained in:
+8
-5
@@ -80,11 +80,12 @@ void printKeypoints(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>
|
||||
}
|
||||
}
|
||||
|
||||
int tutorialApiCpp1()
|
||||
int tutorialApiCpp()
|
||||
{
|
||||
try
|
||||
{
|
||||
op::log("Starting OpenPose demo...", op::Priority::High);
|
||||
const auto opTimer = op::getTimerInit();
|
||||
|
||||
// Configuring OpenPose
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
@@ -109,8 +110,10 @@ int tutorialApiCpp1()
|
||||
else
|
||||
op::log("Image could not be processed.", op::Priority::High);
|
||||
|
||||
// Return successful message
|
||||
op::log("Stopping OpenPose...", op::Priority::High);
|
||||
// Measuring total time
|
||||
op::printTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", op::Priority::High);
|
||||
|
||||
// Return
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
@@ -124,6 +127,6 @@ int main(int argc, char *argv[])
|
||||
// Parsing command line flags
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Running tutorialApiCpp1
|
||||
return tutorialApiCpp1();
|
||||
// Running tutorialApiCpp
|
||||
return tutorialApiCpp();
|
||||
}
|
||||
+8
-5
@@ -59,11 +59,12 @@ void printKeypoints(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>
|
||||
}
|
||||
}
|
||||
|
||||
int tutorialApiCpp2()
|
||||
int tutorialApiCpp()
|
||||
{
|
||||
try
|
||||
{
|
||||
op::log("Starting OpenPose demo...", op::Priority::High);
|
||||
const auto opTimer = op::getTimerInit();
|
||||
|
||||
// Configuring OpenPose
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
@@ -91,8 +92,10 @@ int tutorialApiCpp2()
|
||||
else
|
||||
op::log("Image could not be processed.", op::Priority::High);
|
||||
|
||||
// Return successful message
|
||||
op::log("Stopping OpenPose...", op::Priority::High);
|
||||
// Measuring total time
|
||||
op::printTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", op::Priority::High);
|
||||
|
||||
// Return
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
@@ -106,6 +109,6 @@ int main(int argc, char *argv[])
|
||||
// Parsing command line flags
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Running tutorialApiCpp2
|
||||
return tutorialApiCpp2();
|
||||
// Running tutorialApiCpp
|
||||
return tutorialApiCpp();
|
||||
}
|
||||
+20
-13
@@ -67,6 +67,12 @@ void configureWrapper(op::Wrapper& opWrapper)
|
||||
{
|
||||
// Configuring OpenPose
|
||||
|
||||
// logging_level
|
||||
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::Profiler::setDefaultX(FLAGS_profile_speed);
|
||||
|
||||
// Applying user defined configuration - GFlags to program variables
|
||||
// outputSize
|
||||
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
|
||||
@@ -90,6 +96,9 @@ void configureWrapper(op::Wrapper& opWrapper)
|
||||
const auto heatMapScaleMode = op::flagsToHeatMapScaleMode(FLAGS_heatmaps_scale);
|
||||
// >1 camera view?
|
||||
const auto multipleView = (FLAGS_3d || FLAGS_3d_views > 1);
|
||||
// Face and hand detectors
|
||||
const auto faceDetector = op::flagsToDetector(FLAGS_face_detector);
|
||||
const auto handDetector = op::flagsToDetector(FLAGS_hand_detector);
|
||||
// Enabling Google Logging
|
||||
const bool enableGoogleLogging = true;
|
||||
|
||||
@@ -104,12 +113,13 @@ void configureWrapper(op::Wrapper& opWrapper)
|
||||
opWrapper.configure(wrapperStructPose);
|
||||
// Face configuration (use op::WrapperStructFace{} to disable it)
|
||||
const op::WrapperStructFace wrapperStructFace{
|
||||
FLAGS_face, faceNetInputSize, op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
FLAGS_face, faceDetector, faceNetInputSize,
|
||||
op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
|
||||
opWrapper.configure(wrapperStructFace);
|
||||
// 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,
|
||||
FLAGS_hand, handDetector, handNetInputSize, FLAGS_hand_scale_number, (float)FLAGS_hand_scale_range,
|
||||
op::flagsToRenderMode(FLAGS_hand_render, multipleView, FLAGS_render_pose), (float)FLAGS_hand_alpha_pose,
|
||||
(float)FLAGS_hand_alpha_heatmap, (float)FLAGS_hand_render_threshold};
|
||||
opWrapper.configure(wrapperStructHand);
|
||||
@@ -136,17 +146,12 @@ void configureWrapper(op::Wrapper& opWrapper)
|
||||
}
|
||||
}
|
||||
|
||||
int tutorialApiCpp3()
|
||||
int tutorialApiCpp()
|
||||
{
|
||||
try
|
||||
{
|
||||
op::log("Starting OpenPose demo...", op::Priority::High);
|
||||
|
||||
// logging_level
|
||||
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::Profiler::setDefaultX(FLAGS_profile_speed);
|
||||
const auto opTimer = op::getTimerInit();
|
||||
|
||||
// Configuring OpenPose
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
@@ -169,8 +174,10 @@ int tutorialApiCpp3()
|
||||
else
|
||||
op::log("Image could not be processed.", op::Priority::High);
|
||||
|
||||
// Return successful message
|
||||
op::log("Stopping OpenPose...", op::Priority::High);
|
||||
// Measuring total time
|
||||
op::printTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", op::Priority::High);
|
||||
|
||||
// Return
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
@@ -184,6 +191,6 @@ int main(int argc, char *argv[])
|
||||
// Parsing command line flags
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Running tutorialApiCpp3
|
||||
return tutorialApiCpp3();
|
||||
// Running tutorialApiCpp
|
||||
return tutorialApiCpp();
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
// ----------------------- OpenPose C++ API Tutorial - Example 4 - Body from images configurable ----------------------
|
||||
// It reads images, process them, and display them with the pose (and optionally hand and face) keypoints. In addition,
|
||||
// it includes all the OpenPose configuration flags (enable/disable hand, face, output saving, etc.).
|
||||
|
||||
// Command-line user intraface
|
||||
#define OPENPOSE_FLAGS_DISABLE_PRODUCER
|
||||
#define OPENPOSE_FLAGS_DISABLE_DISPLAY
|
||||
#include <openpose/flags.hpp>
|
||||
// OpenPose dependencies
|
||||
#include <openpose/headers.hpp>
|
||||
|
||||
// Custom OpenPose flags
|
||||
// Producer
|
||||
DEFINE_string(image_dir, "examples/media/",
|
||||
"Process a directory of images. Read all standard formats (jpg, png, bmp, etc.).");
|
||||
// Display
|
||||
DEFINE_bool(no_display, false,
|
||||
"Enable to disable the visual display.");
|
||||
|
||||
// This worker will just read and return all the jpg files in a directory
|
||||
bool display(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>>& datumsPtr)
|
||||
{
|
||||
try
|
||||
{
|
||||
// User's displaying/saving/other processing here
|
||||
// datum.cvOutputData: rendered frame with pose or heatmaps
|
||||
// datum.poseKeypoints: Array<float> with the estimated pose
|
||||
char key = ' ';
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
// Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image)
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData);
|
||||
key = (char)cv::waitKey(1);
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
return (key == 27);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void printKeypoints(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>>& datumsPtr)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Example: How to use the pose keypoints
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
op::log("Body keypoints: " + datumsPtr->at(0)->poseKeypoints.toString());
|
||||
op::log("Face keypoints: " + datumsPtr->at(0)->faceKeypoints.toString());
|
||||
op::log("Left hand keypoints: " + datumsPtr->at(0)->handKeypoints[0].toString());
|
||||
op::log("Right hand keypoints: " + datumsPtr->at(0)->handKeypoints[1].toString());
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
}
|
||||
|
||||
void configureWrapper(op::Wrapper& opWrapper)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Configuring OpenPose
|
||||
|
||||
// logging_level
|
||||
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::Profiler::setDefaultX(FLAGS_profile_speed);
|
||||
|
||||
// Applying user defined configuration - GFlags to program variables
|
||||
// outputSize
|
||||
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
|
||||
// netInputSize
|
||||
const auto netInputSize = op::flagsToPoint(FLAGS_net_resolution, "-1x368");
|
||||
// faceNetInputSize
|
||||
const auto faceNetInputSize = op::flagsToPoint(FLAGS_face_net_resolution, "368x368 (multiples of 16)");
|
||||
// handNetInputSize
|
||||
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
|
||||
// poseModel
|
||||
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
|
||||
// JSON saving
|
||||
if (!FLAGS_write_keypoint.empty())
|
||||
op::log("Flag `write_keypoint` is deprecated and will eventually be removed."
|
||||
" Please, use `write_json` instead.", op::Priority::Max);
|
||||
// keypointScaleMode
|
||||
const auto keypointScaleMode = 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);
|
||||
const auto heatMapScaleMode = op::flagsToHeatMapScaleMode(FLAGS_heatmaps_scale);
|
||||
// >1 camera view?
|
||||
const auto multipleView = (FLAGS_3d || FLAGS_3d_views > 1);
|
||||
// Face and hand detectors
|
||||
const auto faceDetector = op::flagsToDetector(FLAGS_face_detector);
|
||||
const auto handDetector = op::flagsToDetector(FLAGS_hand_detector);
|
||||
// Enabling Google Logging
|
||||
const bool enableGoogleLogging = true;
|
||||
|
||||
// Pose configuration (use WrapperStructPose{} for default and recommended configuration)
|
||||
const op::WrapperStructPose wrapperStructPose{
|
||||
!FLAGS_body_disable, netInputSize, outputSize, keypointScaleMode, FLAGS_num_gpu, FLAGS_num_gpu_start,
|
||||
FLAGS_scale_number, (float)FLAGS_scale_gap, op::flagsToRenderMode(FLAGS_render_pose, multipleView),
|
||||
poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
|
||||
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScaleMode, FLAGS_part_candidates,
|
||||
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
|
||||
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
|
||||
opWrapper.configure(wrapperStructPose);
|
||||
// Face configuration (use op::WrapperStructFace{} to disable it)
|
||||
const op::WrapperStructFace wrapperStructFace{
|
||||
FLAGS_face, faceDetector, faceNetInputSize,
|
||||
op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
|
||||
opWrapper.configure(wrapperStructFace);
|
||||
// Hand configuration (use op::WrapperStructHand{} to disable it)
|
||||
const op::WrapperStructHand wrapperStructHand{
|
||||
FLAGS_hand, handDetector, handNetInputSize, FLAGS_hand_scale_number, (float)FLAGS_hand_scale_range,
|
||||
op::flagsToRenderMode(FLAGS_hand_render, multipleView, FLAGS_render_pose), (float)FLAGS_hand_alpha_pose,
|
||||
(float)FLAGS_hand_alpha_heatmap, (float)FLAGS_hand_render_threshold};
|
||||
opWrapper.configure(wrapperStructHand);
|
||||
// Extra functionality configuration (use op::WrapperStructExtra{} to disable it)
|
||||
const op::WrapperStructExtra wrapperStructExtra{
|
||||
FLAGS_3d, FLAGS_3d_min_views, FLAGS_identification, FLAGS_tracking, FLAGS_ik_threads};
|
||||
opWrapper.configure(wrapperStructExtra);
|
||||
// Output (comment or use default argument to disable any output)
|
||||
const op::WrapperStructOutput wrapperStructOutput{
|
||||
FLAGS_cli_verbose, FLAGS_write_keypoint, op::stringToDataFormat(FLAGS_write_keypoint_format),
|
||||
FLAGS_write_json, FLAGS_write_coco_json, FLAGS_write_coco_foot_json, FLAGS_write_coco_json_variant,
|
||||
FLAGS_write_images, FLAGS_write_images_format, FLAGS_write_video, FLAGS_write_video_fps,
|
||||
FLAGS_write_video_with_audio, FLAGS_write_heatmaps, FLAGS_write_heatmaps_format, FLAGS_write_video_3d,
|
||||
FLAGS_write_video_adam, FLAGS_write_bvh, FLAGS_udp_host, FLAGS_udp_port};
|
||||
opWrapper.configure(wrapperStructOutput);
|
||||
// No GUI. Equivalent to: opWrapper.configure(op::WrapperStructGui{});
|
||||
// Set to single-thread (for sequential processing and/or debugging and/or reducing latency)
|
||||
if (FLAGS_disable_multi_thread)
|
||||
opWrapper.disableMultiThreading();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
}
|
||||
|
||||
int tutorialApiCpp()
|
||||
{
|
||||
try
|
||||
{
|
||||
op::log("Starting OpenPose demo...", op::Priority::High);
|
||||
const auto opTimer = op::getTimerInit();
|
||||
|
||||
// Configuring OpenPose
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::Wrapper opWrapper{op::ThreadManagerMode::Asynchronous};
|
||||
configureWrapper(opWrapper);
|
||||
|
||||
// Starting OpenPose
|
||||
op::log("Starting thread(s)...", op::Priority::High);
|
||||
opWrapper.start();
|
||||
|
||||
// Read frames on directory
|
||||
const auto imagePaths = op::getFilesOnDirectory(FLAGS_image_dir, op::Extensions::Images);
|
||||
|
||||
// Process and display images
|
||||
for (const auto& imagePath : imagePaths)
|
||||
{
|
||||
const auto imageToProcess = cv::imread(imagePath);
|
||||
auto datumProcessed = opWrapper.emplaceAndPop(imageToProcess);
|
||||
if (datumProcessed != nullptr)
|
||||
{
|
||||
printKeypoints(datumProcessed);
|
||||
if (!FLAGS_no_display)
|
||||
{
|
||||
const auto userWantsToExit = display(datumProcessed);
|
||||
if (userWantsToExit)
|
||||
{
|
||||
op::log("User pressed Esc to exit demo.", op::Priority::High);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
op::log("Image " + imagePath + " could not be processed.", op::Priority::High);
|
||||
}
|
||||
|
||||
// Measuring total time
|
||||
op::printTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", op::Priority::High);
|
||||
|
||||
// Return
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Parsing command line flags
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Running tutorialApiCpp
|
||||
return tutorialApiCpp();
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
// --------------- OpenPose C++ API Tutorial - Example 5 - Body from images configurable and multi GPU ---------------
|
||||
// It reads images, process them, and display them with the pose (and optionally hand and face) keypoints. In addition,
|
||||
// it includes all the OpenPose configuration flags (enable/disable hand, face, output saving, etc.).
|
||||
|
||||
// Command-line user intraface
|
||||
#define OPENPOSE_FLAGS_DISABLE_PRODUCER
|
||||
#define OPENPOSE_FLAGS_DISABLE_DISPLAY
|
||||
#include <openpose/flags.hpp>
|
||||
// OpenPose dependencies
|
||||
#include <openpose/headers.hpp>
|
||||
|
||||
// Custom OpenPose flags
|
||||
// Producer
|
||||
DEFINE_string(image_dir, "examples/media/",
|
||||
"Process a directory of images. Read all standard formats (jpg, png, bmp, etc.).");
|
||||
// Display
|
||||
DEFINE_bool(no_display, false,
|
||||
"Enable to disable the visual display.");
|
||||
|
||||
// This worker will just read and return all the jpg files in a directory
|
||||
bool display(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>>& datumsPtr)
|
||||
{
|
||||
try
|
||||
{
|
||||
// User's displaying/saving/other processing here
|
||||
// datum.cvOutputData: rendered frame with pose or heatmaps
|
||||
// datum.poseKeypoints: Array<float> with the estimated pose
|
||||
char key = ' ';
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
// Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image)
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData);
|
||||
key = (char)cv::waitKey(1);
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
return (key == 27);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void printKeypoints(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>>& datumsPtr)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Example: How to use the pose keypoints
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
op::log("Body keypoints: " + datumsPtr->at(0)->poseKeypoints.toString());
|
||||
op::log("Face keypoints: " + datumsPtr->at(0)->faceKeypoints.toString());
|
||||
op::log("Left hand keypoints: " + datumsPtr->at(0)->handKeypoints[0].toString());
|
||||
op::log("Right hand keypoints: " + datumsPtr->at(0)->handKeypoints[1].toString());
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
}
|
||||
|
||||
void configureWrapper(op::Wrapper& opWrapper)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Configuring OpenPose
|
||||
|
||||
// logging_level
|
||||
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::Profiler::setDefaultX(FLAGS_profile_speed);
|
||||
|
||||
// Applying user defined configuration - GFlags to program variables
|
||||
// outputSize
|
||||
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
|
||||
// netInputSize
|
||||
const auto netInputSize = op::flagsToPoint(FLAGS_net_resolution, "-1x368");
|
||||
// faceNetInputSize
|
||||
const auto faceNetInputSize = op::flagsToPoint(FLAGS_face_net_resolution, "368x368 (multiples of 16)");
|
||||
// handNetInputSize
|
||||
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
|
||||
// poseModel
|
||||
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
|
||||
// JSON saving
|
||||
if (!FLAGS_write_keypoint.empty())
|
||||
op::log("Flag `write_keypoint` is deprecated and will eventually be removed."
|
||||
" Please, use `write_json` instead.", op::Priority::Max);
|
||||
// keypointScaleMode
|
||||
const auto keypointScaleMode = 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);
|
||||
const auto heatMapScaleMode = op::flagsToHeatMapScaleMode(FLAGS_heatmaps_scale);
|
||||
// >1 camera view?
|
||||
const auto multipleView = (FLAGS_3d || FLAGS_3d_views > 1);
|
||||
// Face and hand detectors
|
||||
const auto faceDetector = op::flagsToDetector(FLAGS_face_detector);
|
||||
const auto handDetector = op::flagsToDetector(FLAGS_hand_detector);
|
||||
// Enabling Google Logging
|
||||
const bool enableGoogleLogging = true;
|
||||
|
||||
// Pose configuration (use WrapperStructPose{} for default and recommended configuration)
|
||||
const op::WrapperStructPose wrapperStructPose{
|
||||
!FLAGS_body_disable, netInputSize, outputSize, keypointScaleMode, FLAGS_num_gpu, FLAGS_num_gpu_start,
|
||||
FLAGS_scale_number, (float)FLAGS_scale_gap, op::flagsToRenderMode(FLAGS_render_pose, multipleView),
|
||||
poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
|
||||
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScaleMode, FLAGS_part_candidates,
|
||||
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
|
||||
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
|
||||
opWrapper.configure(wrapperStructPose);
|
||||
// Face configuration (use op::WrapperStructFace{} to disable it)
|
||||
const op::WrapperStructFace wrapperStructFace{
|
||||
FLAGS_face, faceDetector, faceNetInputSize,
|
||||
op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
|
||||
opWrapper.configure(wrapperStructFace);
|
||||
// Hand configuration (use op::WrapperStructHand{} to disable it)
|
||||
const op::WrapperStructHand wrapperStructHand{
|
||||
FLAGS_hand, handDetector, handNetInputSize, FLAGS_hand_scale_number, (float)FLAGS_hand_scale_range,
|
||||
op::flagsToRenderMode(FLAGS_hand_render, multipleView, FLAGS_render_pose), (float)FLAGS_hand_alpha_pose,
|
||||
(float)FLAGS_hand_alpha_heatmap, (float)FLAGS_hand_render_threshold};
|
||||
opWrapper.configure(wrapperStructHand);
|
||||
// Extra functionality configuration (use op::WrapperStructExtra{} to disable it)
|
||||
const op::WrapperStructExtra wrapperStructExtra{
|
||||
FLAGS_3d, FLAGS_3d_min_views, FLAGS_identification, FLAGS_tracking, FLAGS_ik_threads};
|
||||
opWrapper.configure(wrapperStructExtra);
|
||||
// Output (comment or use default argument to disable any output)
|
||||
const op::WrapperStructOutput wrapperStructOutput{
|
||||
FLAGS_cli_verbose, FLAGS_write_keypoint, op::stringToDataFormat(FLAGS_write_keypoint_format),
|
||||
FLAGS_write_json, FLAGS_write_coco_json, FLAGS_write_coco_foot_json, FLAGS_write_coco_json_variant,
|
||||
FLAGS_write_images, FLAGS_write_images_format, FLAGS_write_video, FLAGS_write_video_fps,
|
||||
FLAGS_write_video_with_audio, FLAGS_write_heatmaps, FLAGS_write_heatmaps_format, FLAGS_write_video_3d,
|
||||
FLAGS_write_video_adam, FLAGS_write_bvh, FLAGS_udp_host, FLAGS_udp_port};
|
||||
opWrapper.configure(wrapperStructOutput);
|
||||
// No GUI. Equivalent to: opWrapper.configure(op::WrapperStructGui{});
|
||||
// Set to single-thread (for sequential processing and/or debugging and/or reducing latency)
|
||||
if (FLAGS_disable_multi_thread)
|
||||
opWrapper.disableMultiThreading();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
}
|
||||
|
||||
int tutorialApiCpp()
|
||||
{
|
||||
try
|
||||
{
|
||||
op::log("Starting OpenPose demo...", op::Priority::High);
|
||||
const auto opTimer = op::getTimerInit();
|
||||
|
||||
// Configuring OpenPose
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::Wrapper opWrapper{op::ThreadManagerMode::Asynchronous};
|
||||
configureWrapper(opWrapper);
|
||||
|
||||
// Starting OpenPose
|
||||
op::log("Starting thread(s)...", op::Priority::High);
|
||||
opWrapper.start();
|
||||
|
||||
// Read frames on directory
|
||||
const auto imagePaths = op::getFilesOnDirectory(FLAGS_image_dir, op::Extensions::Images);
|
||||
|
||||
// Read number of GPUs in your system
|
||||
const auto numberGPUs = op::getGpuNumber();
|
||||
|
||||
// Process and display images
|
||||
// Option a) Harder to implement but the fastest method
|
||||
// Create 2 different threads:
|
||||
// 1. One pushing images to OpenPose all the time.
|
||||
// 2. A second one retrieving those frames.
|
||||
// Option b) Much easier and faster to implement but slightly slower runtime performance
|
||||
for (auto imageId = 0u ; imageId < imagePaths.size() ; imageId+=numberGPUs)
|
||||
{
|
||||
// Read and push images into OpenPose wrapper
|
||||
for (auto gpuId = 0 ; gpuId < numberGPUs ; gpuId++)
|
||||
{
|
||||
const auto& imagePath = imagePaths.at(imageId+gpuId);
|
||||
// Faster alternative that moves imageToProcess
|
||||
auto imageToProcess = cv::imread(imagePath);
|
||||
opWrapper.waitAndEmplace(imageToProcess);
|
||||
// // Slower but safer alternative that copies imageToProcess
|
||||
// const auto imageToProcess = cv::imread(imagePath);
|
||||
// opWrapper.waitAndPush(imageToProcess);
|
||||
}
|
||||
// Retrieve processed results from OpenPose wrapper
|
||||
for (auto gpuId = 0 ; gpuId < numberGPUs ; gpuId++)
|
||||
{
|
||||
std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>> datumProcessed;
|
||||
const auto status = opWrapper.waitAndPop(datumProcessed);
|
||||
if (status && datumProcessed != nullptr)
|
||||
{
|
||||
printKeypoints(datumProcessed);
|
||||
if (!FLAGS_no_display)
|
||||
{
|
||||
const auto userWantsToExit = display(datumProcessed);
|
||||
if (userWantsToExit)
|
||||
{
|
||||
op::log("User pressed Esc to exit demo.", op::Priority::High);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
op::log("Image could not be processed.", op::Priority::High);
|
||||
}
|
||||
}
|
||||
|
||||
// Measuring total time
|
||||
op::printTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", op::Priority::High);
|
||||
|
||||
// Return
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Parsing command line flags
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Running tutorialApiCpp
|
||||
return tutorialApiCpp();
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
// ------------------------- OpenPose C++ API Tutorial - Example 6 - Custom Input -------------------------
|
||||
// Asynchronous mode: ideal for fast prototyping when performance is not an issue.
|
||||
// In this function, the user can implement its own way to create frames (e.g., reading his own folder of images)
|
||||
// and emplaces/pushes the frames to OpenPose.
|
||||
|
||||
// Command-line user intraface
|
||||
#define OPENPOSE_FLAGS_DISABLE_PRODUCER
|
||||
#include <openpose/flags.hpp>
|
||||
// OpenPose dependencies
|
||||
#include <openpose/headers.hpp>
|
||||
|
||||
// Custom OpenPose flags
|
||||
// Producer
|
||||
DEFINE_string(image_dir, "examples/media/",
|
||||
"Process a directory of images. Read all standard formats (jpg, png, bmp, etc.).");
|
||||
|
||||
// The W-classes can be implemented either as a template or as simple classes given
|
||||
// that the user usually knows which kind of data he will move between the queues,
|
||||
// in this case we assume a std::shared_ptr of a std::vector of op::Datum
|
||||
|
||||
// This worker will just read and return all the basic image file formats in a directory
|
||||
class UserInputClass
|
||||
{
|
||||
public:
|
||||
UserInputClass(const std::string& directoryPath) :
|
||||
mImageFiles{op::getFilesOnDirectory(directoryPath, op::Extensions::Images)}, // For all basic image formats
|
||||
// If we want only e.g., "jpg" + "png" images
|
||||
// mImageFiles{op::getFilesOnDirectory(directoryPath, std::vector<std::string>{"jpg", "png"})},
|
||||
mCounter{0},
|
||||
mClosed{false}
|
||||
{
|
||||
if (mImageFiles.empty())
|
||||
op::error("No images found on: " + directoryPath, __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>> createDatum()
|
||||
{
|
||||
// Close program when empty frame
|
||||
if (mClosed || mImageFiles.size() <= mCounter)
|
||||
{
|
||||
op::log("Last frame read and added to queue. Closing program after it is processed.", op::Priority::High);
|
||||
// This funtion stops this worker, which will eventually stop the whole thread system once all the frames
|
||||
// have been processed
|
||||
mClosed = true;
|
||||
return nullptr;
|
||||
}
|
||||
else // if (!mClosed)
|
||||
{
|
||||
// Create new datum
|
||||
auto datumsPtr = std::make_shared<std::vector<std::shared_ptr<op::Datum>>>();
|
||||
datumsPtr->emplace_back();
|
||||
auto& datumPtr = datumsPtr->at(0);
|
||||
datumPtr = std::make_shared<op::Datum>();
|
||||
|
||||
// Fill datum
|
||||
datumPtr->cvInputData = cv::imread(mImageFiles.at(mCounter++));
|
||||
|
||||
// If empty frame -> return nullptr
|
||||
if (datumPtr->cvInputData.empty())
|
||||
{
|
||||
op::log("Empty frame detected on path: " + mImageFiles.at(mCounter-1) + ". Closing program.",
|
||||
op::Priority::High);
|
||||
mClosed = true;
|
||||
datumsPtr = nullptr;
|
||||
}
|
||||
|
||||
return datumsPtr;
|
||||
}
|
||||
}
|
||||
|
||||
bool isFinished() const
|
||||
{
|
||||
return mClosed;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::vector<std::string> mImageFiles;
|
||||
unsigned long long mCounter;
|
||||
bool mClosed;
|
||||
};
|
||||
|
||||
void configureWrapper(op::Wrapper& opWrapper)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Configuring OpenPose
|
||||
|
||||
// logging_level
|
||||
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::Profiler::setDefaultX(FLAGS_profile_speed);
|
||||
|
||||
// Applying user defined configuration - GFlags to program variables
|
||||
// outputSize
|
||||
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
|
||||
// netInputSize
|
||||
const auto netInputSize = op::flagsToPoint(FLAGS_net_resolution, "-1x368");
|
||||
// faceNetInputSize
|
||||
const auto faceNetInputSize = op::flagsToPoint(FLAGS_face_net_resolution, "368x368 (multiples of 16)");
|
||||
// handNetInputSize
|
||||
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
|
||||
// poseModel
|
||||
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
|
||||
// JSON saving
|
||||
if (!FLAGS_write_keypoint.empty())
|
||||
op::log("Flag `write_keypoint` is deprecated and will eventually be removed."
|
||||
" Please, use `write_json` instead.", op::Priority::Max);
|
||||
// keypointScaleMode
|
||||
const auto keypointScaleMode = 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);
|
||||
const auto heatMapScaleMode = op::flagsToHeatMapScaleMode(FLAGS_heatmaps_scale);
|
||||
// >1 camera view?
|
||||
const auto multipleView = (FLAGS_3d || FLAGS_3d_views > 1);
|
||||
// Face and hand detectors
|
||||
const auto faceDetector = op::flagsToDetector(FLAGS_face_detector);
|
||||
const auto handDetector = op::flagsToDetector(FLAGS_hand_detector);
|
||||
// Enabling Google Logging
|
||||
const bool enableGoogleLogging = true;
|
||||
|
||||
// Pose configuration (use WrapperStructPose{} for default and recommended configuration)
|
||||
const op::WrapperStructPose wrapperStructPose{
|
||||
!FLAGS_body_disable, netInputSize, outputSize, keypointScaleMode, FLAGS_num_gpu, FLAGS_num_gpu_start,
|
||||
FLAGS_scale_number, (float)FLAGS_scale_gap, op::flagsToRenderMode(FLAGS_render_pose, multipleView),
|
||||
poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
|
||||
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScaleMode, FLAGS_part_candidates,
|
||||
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
|
||||
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
|
||||
opWrapper.configure(wrapperStructPose);
|
||||
// Face configuration (use op::WrapperStructFace{} to disable it)
|
||||
const op::WrapperStructFace wrapperStructFace{
|
||||
FLAGS_face, faceDetector, faceNetInputSize,
|
||||
op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
|
||||
opWrapper.configure(wrapperStructFace);
|
||||
// Hand configuration (use op::WrapperStructHand{} to disable it)
|
||||
const op::WrapperStructHand wrapperStructHand{
|
||||
FLAGS_hand, handDetector, handNetInputSize, FLAGS_hand_scale_number, (float)FLAGS_hand_scale_range,
|
||||
op::flagsToRenderMode(FLAGS_hand_render, multipleView, FLAGS_render_pose), (float)FLAGS_hand_alpha_pose,
|
||||
(float)FLAGS_hand_alpha_heatmap, (float)FLAGS_hand_render_threshold};
|
||||
opWrapper.configure(wrapperStructHand);
|
||||
// Extra functionality configuration (use op::WrapperStructExtra{} to disable it)
|
||||
const op::WrapperStructExtra wrapperStructExtra{
|
||||
FLAGS_3d, FLAGS_3d_min_views, FLAGS_identification, FLAGS_tracking, FLAGS_ik_threads};
|
||||
opWrapper.configure(wrapperStructExtra);
|
||||
// Output (comment or use default argument to disable any output)
|
||||
const op::WrapperStructOutput wrapperStructOutput{
|
||||
FLAGS_cli_verbose, FLAGS_write_keypoint, op::stringToDataFormat(FLAGS_write_keypoint_format),
|
||||
FLAGS_write_json, FLAGS_write_coco_json, FLAGS_write_coco_foot_json, FLAGS_write_coco_json_variant,
|
||||
FLAGS_write_images, FLAGS_write_images_format, FLAGS_write_video, FLAGS_write_video_fps,
|
||||
FLAGS_write_video_with_audio, FLAGS_write_heatmaps, FLAGS_write_heatmaps_format, FLAGS_write_video_3d,
|
||||
FLAGS_write_video_adam, FLAGS_write_bvh, FLAGS_udp_host, FLAGS_udp_port};
|
||||
opWrapper.configure(wrapperStructOutput);
|
||||
// GUI (comment or use default argument to disable any visual output)
|
||||
const op::WrapperStructGui wrapperStructGui{
|
||||
op::flagsToDisplayMode(FLAGS_display, FLAGS_3d), !FLAGS_no_gui_verbose, FLAGS_fullscreen};
|
||||
opWrapper.configure(wrapperStructGui);
|
||||
// Set to single-thread (for sequential processing and/or debugging and/or reducing latency)
|
||||
if (FLAGS_disable_multi_thread)
|
||||
opWrapper.disableMultiThreading();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
}
|
||||
|
||||
int tutorialApiCpp()
|
||||
{
|
||||
try
|
||||
{
|
||||
op::log("Starting OpenPose demo...", op::Priority::High);
|
||||
const auto opTimer = op::getTimerInit();
|
||||
|
||||
// Configuring OpenPose
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::Wrapper opWrapper{op::ThreadManagerMode::AsynchronousIn};
|
||||
configureWrapper(opWrapper);
|
||||
|
||||
// Start, run, and stop processing - exec() blocks this thread until OpenPose wrapper has finished
|
||||
op::log("Starting thread(s)...", op::Priority::High);
|
||||
opWrapper.start();
|
||||
|
||||
// User processing
|
||||
UserInputClass userInputClass(FLAGS_image_dir);
|
||||
bool userWantsToExit = false;
|
||||
while (!userWantsToExit && !userInputClass.isFinished())
|
||||
{
|
||||
// Push frame
|
||||
auto datumToProcess = userInputClass.createDatum();
|
||||
if (datumToProcess != nullptr)
|
||||
{
|
||||
auto successfullyEmplaced = opWrapper.waitAndEmplace(datumToProcess);
|
||||
if (!successfullyEmplaced)
|
||||
op::log("Processed datum could not be emplaced.", op::Priority::High);
|
||||
}
|
||||
}
|
||||
|
||||
op::log("Stopping thread(s)", op::Priority::High);
|
||||
opWrapper.stop();
|
||||
|
||||
// Measuring total time
|
||||
op::printTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", op::Priority::High);
|
||||
|
||||
// Return
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Parsing command line flags
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Running tutorialApiCpp
|
||||
return tutorialApiCpp();
|
||||
}
|
||||
+56
-69
@@ -1,19 +1,6 @@
|
||||
// ------------------------- OpenPose C++ API Tutorial - Example 5 - XXXXXXXXXXXXX -------------------------
|
||||
// Asynchronous output mode: ideal for fast prototyping when performance is not an issue and user wants to use the
|
||||
// output OpenPose format. The user simply gets the processed frames from the OpenPose wrapper when he desires to.
|
||||
|
||||
// This example shows the user how to use the OpenPose wrapper class:
|
||||
// 1. Read folder of images / video / webcam
|
||||
// 2. Extract and render keypoint / heatmap / PAF of that image
|
||||
// 3. Save the results on disk
|
||||
// 4. User displays the rendered pose
|
||||
// Everything in a multi-thread scenario
|
||||
// In addition to the previous OpenPose modules, we also need to use:
|
||||
// 1. `core` module:
|
||||
// For the Array<float> class that the `pose` module needs
|
||||
// For the Datum struct that the `thread` module sends between the queues
|
||||
// 2. `utilities` module: for the error & logging functions, i.e., op::error & op::log respectively
|
||||
// This file should only be used for the user to take specific examples.
|
||||
// ------------------------- OpenPose C++ API Tutorial - Example 7 - Custom Output -------------------------
|
||||
// Asynchronous mode: ideal for fast prototyping when performance is not an issue.
|
||||
// In this function, the user can implement its own way to render/display the frames.
|
||||
|
||||
// Command-line user intraface
|
||||
#define OPENPOSE_FLAGS_DISABLE_DISPLAY
|
||||
@@ -26,28 +13,15 @@
|
||||
DEFINE_bool(no_display, false,
|
||||
"Enable to disable the visual display.");
|
||||
|
||||
// If the user needs his own variables, he can inherit the op::Datum struct and add them in there.
|
||||
// UserDatum can be directly used by the OpenPose wrapper because it inherits from op::Datum, just define
|
||||
// WrapperT<std::vector<std::shared_ptr<UserDatum>>> instead of Wrapper
|
||||
// (or equivalently WrapperT<std::vector<std::shared_ptr<UserDatum>>>)
|
||||
struct UserDatum : public op::Datum
|
||||
{
|
||||
bool boolThatUserNeedsForSomeReason;
|
||||
|
||||
UserDatum(const bool boolThatUserNeedsForSomeReason_ = false) :
|
||||
boolThatUserNeedsForSomeReason{boolThatUserNeedsForSomeReason_}
|
||||
{}
|
||||
};
|
||||
|
||||
// The W-classes can be implemented either as a template or as simple classes given
|
||||
// that the user usually knows which kind of data he will move between the queues,
|
||||
// in this case we assume a std::shared_ptr of a std::vector of UserDatum
|
||||
// in this case we assume a std::shared_ptr of a std::vector of op::Datum
|
||||
|
||||
// This worker will just read and return all the jpg files in a directory
|
||||
class UserOutputClass
|
||||
{
|
||||
public:
|
||||
bool display(const std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>& datumsPtr)
|
||||
bool display(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>>& datumsPtr)
|
||||
{
|
||||
// User's displaying/saving/other processing here
|
||||
// datumPtr->cvOutputData: rendered frame with pose or heatmaps
|
||||
@@ -60,10 +34,10 @@ public:
|
||||
key = (char)cv::waitKey(1);
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__);
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
return (key == 27);
|
||||
}
|
||||
void printKeypoints(const std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>& datumsPtr)
|
||||
void printKeypoints(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>>& datumsPtr)
|
||||
{
|
||||
// Example: How to use the pose keypoints
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
@@ -114,16 +88,15 @@ public:
|
||||
}
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__);
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
}
|
||||
};
|
||||
|
||||
int tutorialApiCpp5()
|
||||
void configureWrapper(op::Wrapper& opWrapper)
|
||||
{
|
||||
try
|
||||
{
|
||||
op::log("Starting OpenPose demo...", op::Priority::High);
|
||||
const auto timerBegin = std::chrono::high_resolution_clock::now();
|
||||
// Configuring OpenPose
|
||||
|
||||
// logging_level
|
||||
op::check(0 <= FLAGS_logging_level && FLAGS_logging_level <= 255, "Wrong logging_level value.",
|
||||
@@ -132,6 +105,11 @@ int tutorialApiCpp5()
|
||||
op::Profiler::setDefaultX(FLAGS_profile_speed);
|
||||
|
||||
// Applying user defined configuration - GFlags to program variables
|
||||
// producerType
|
||||
op::ProducerType producerType;
|
||||
std::string producerString;
|
||||
std::tie(producerType, producerString) = op::flagsToProducer(
|
||||
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
|
||||
// cameraSize
|
||||
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
|
||||
// outputSize
|
||||
@@ -142,11 +120,6 @@ int tutorialApiCpp5()
|
||||
const auto faceNetInputSize = op::flagsToPoint(FLAGS_face_net_resolution, "368x368 (multiples of 16)");
|
||||
// handNetInputSize
|
||||
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
|
||||
// producerType
|
||||
op::ProducerType producerType;
|
||||
std::string producerString;
|
||||
std::tie(producerType, producerString) = op::flagsToProducer(
|
||||
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
|
||||
// poseModel
|
||||
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
|
||||
// JSON saving
|
||||
@@ -161,12 +134,12 @@ int tutorialApiCpp5()
|
||||
const auto heatMapScaleMode = op::flagsToHeatMapScaleMode(FLAGS_heatmaps_scale);
|
||||
// >1 camera view?
|
||||
const auto multipleView = (FLAGS_3d || FLAGS_3d_views > 1 || FLAGS_flir_camera);
|
||||
// Face and hand detectors
|
||||
const auto faceDetector = op::flagsToDetector(FLAGS_face_detector);
|
||||
const auto handDetector = op::flagsToDetector(FLAGS_hand_detector);
|
||||
// Enabling Google Logging
|
||||
const bool enableGoogleLogging = true;
|
||||
|
||||
// Configuring OpenPose
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::WrapperT<UserDatum> opWrapperT{op::ThreadManagerMode::AsynchronousOut};
|
||||
// Pose configuration (use WrapperStructPose{} for default and recommended configuration)
|
||||
const op::WrapperStructPose wrapperStructPose{
|
||||
!FLAGS_body_disable, netInputSize, outputSize, keypointScaleMode, FLAGS_num_gpu, FLAGS_num_gpu_start,
|
||||
@@ -175,28 +148,29 @@ int tutorialApiCpp5()
|
||||
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScaleMode, FLAGS_part_candidates,
|
||||
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
|
||||
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
|
||||
opWrapperT.configure(wrapperStructPose);
|
||||
opWrapper.configure(wrapperStructPose);
|
||||
// Face configuration (use op::WrapperStructFace{} to disable it)
|
||||
const op::WrapperStructFace wrapperStructFace{
|
||||
FLAGS_face, faceNetInputSize, op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
FLAGS_face, faceDetector, faceNetInputSize,
|
||||
op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
|
||||
opWrapperT.configure(wrapperStructFace);
|
||||
opWrapper.configure(wrapperStructFace);
|
||||
// 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,
|
||||
FLAGS_hand, handDetector, handNetInputSize, FLAGS_hand_scale_number, (float)FLAGS_hand_scale_range,
|
||||
op::flagsToRenderMode(FLAGS_hand_render, multipleView, FLAGS_render_pose), (float)FLAGS_hand_alpha_pose,
|
||||
(float)FLAGS_hand_alpha_heatmap, (float)FLAGS_hand_render_threshold};
|
||||
opWrapperT.configure(wrapperStructHand);
|
||||
opWrapper.configure(wrapperStructHand);
|
||||
// Extra functionality configuration (use op::WrapperStructExtra{} to disable it)
|
||||
const op::WrapperStructExtra wrapperStructExtra{
|
||||
FLAGS_3d, FLAGS_3d_min_views, FLAGS_identification, FLAGS_tracking, FLAGS_ik_threads};
|
||||
opWrapperT.configure(wrapperStructExtra);
|
||||
opWrapper.configure(wrapperStructExtra);
|
||||
// Producer (use default to disable any input)
|
||||
const op::WrapperStructInput wrapperStructInput{
|
||||
producerType, producerString, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last,
|
||||
FLAGS_process_real_time, FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat,
|
||||
cameraSize, FLAGS_camera_parameter_path, FLAGS_frame_undistort, FLAGS_3d_views};
|
||||
opWrapperT.configure(wrapperStructInput);
|
||||
opWrapper.configure(wrapperStructInput);
|
||||
// Output (comment or use default argument to disable any output)
|
||||
const op::WrapperStructOutput wrapperStructOutput{
|
||||
FLAGS_cli_verbose, FLAGS_write_keypoint, op::stringToDataFormat(FLAGS_write_keypoint_format),
|
||||
@@ -204,15 +178,33 @@ int tutorialApiCpp5()
|
||||
FLAGS_write_images, FLAGS_write_images_format, FLAGS_write_video, FLAGS_write_video_fps,
|
||||
FLAGS_write_video_with_audio, FLAGS_write_heatmaps, FLAGS_write_heatmaps_format, FLAGS_write_video_3d,
|
||||
FLAGS_write_video_adam, FLAGS_write_bvh, FLAGS_udp_host, FLAGS_udp_port};
|
||||
opWrapperT.configure(wrapperStructOutput);
|
||||
opWrapper.configure(wrapperStructOutput);
|
||||
// No GUI. Equivalent to: opWrapper.configure(op::WrapperStructGui{});
|
||||
// Set to single-thread (for sequential processing and/or debugging and/or reducing latency)
|
||||
if (FLAGS_disable_multi_thread)
|
||||
opWrapperT.disableMultiThreading();
|
||||
opWrapper.disableMultiThreading();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
}
|
||||
|
||||
int tutorialApiCpp()
|
||||
{
|
||||
try
|
||||
{
|
||||
op::log("Starting OpenPose demo...", op::Priority::High);
|
||||
const auto opTimer = op::getTimerInit();
|
||||
|
||||
// Configuring OpenPose
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::Wrapper opWrapper{op::ThreadManagerMode::AsynchronousOut};
|
||||
configureWrapper(opWrapper);
|
||||
|
||||
// Start, run, and stop processing - exec() blocks this thread until OpenPose wrapper has finished
|
||||
op::log("Starting thread(s)...", op::Priority::High);
|
||||
opWrapperT.start();
|
||||
opWrapper.start();
|
||||
|
||||
// User processing
|
||||
UserOutputClass userOutputClass;
|
||||
@@ -220,33 +212,28 @@ int tutorialApiCpp5()
|
||||
while (!userWantsToExit)
|
||||
{
|
||||
// Pop frame
|
||||
std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>> datumProcessed;
|
||||
if (opWrapperT.waitAndPop(datumProcessed))
|
||||
std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>> datumProcessed;
|
||||
if (opWrapper.waitAndPop(datumProcessed))
|
||||
{
|
||||
if (!FLAGS_no_display)
|
||||
userWantsToExit = userOutputClass.display(datumProcessed);;
|
||||
userOutputClass.printKeypoints(datumProcessed);
|
||||
}
|
||||
// If OpenPose finished reading images
|
||||
else if (!opWrapperT.isRunning())
|
||||
else if (!opWrapper.isRunning())
|
||||
break;
|
||||
// Something else happened
|
||||
else
|
||||
op::log("Processed datum could not be emplaced.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__);
|
||||
op::log("Processed datum could not be emplaced.", op::Priority::High);
|
||||
}
|
||||
|
||||
op::log("Stopping thread(s)", op::Priority::High);
|
||||
opWrapperT.stop();
|
||||
opWrapper.stop();
|
||||
|
||||
// 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 = "OpenPose demo successfully finished. Total time: "
|
||||
+ std::to_string(totalTimeSec) + " seconds.";
|
||||
op::log(message, op::Priority::High);
|
||||
op::printTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", op::Priority::High);
|
||||
|
||||
// Return successful message
|
||||
// Return
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
@@ -260,6 +247,6 @@ int main(int argc, char *argv[])
|
||||
// Parsing command line flags
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Running tutorialApiCpp5
|
||||
return tutorialApiCpp5();
|
||||
// Running tutorialApiCpp
|
||||
return tutorialApiCpp();
|
||||
}
|
||||
+55
-47
@@ -1,19 +1,7 @@
|
||||
// ------------------------- OpenPose C++ API Tutorial - Example 4 - Custom Input and Output -------------------------
|
||||
// Asynchronous mode: ideal for fast prototyping when performance is not an issue. The user emplaces/pushes and pops frames from the OpenPose wrapper
|
||||
// when he desires to.
|
||||
|
||||
// This example shows the user how to use the OpenPose wrapper class:
|
||||
// 1. User reads images
|
||||
// 2. Extract and render keypoint / heatmap / PAF of that image
|
||||
// 3. Save the results on disk
|
||||
// 4. User displays the rendered pose
|
||||
// Everything in a multi-thread scenario
|
||||
// In addition to the previous OpenPose modules, we also need to use:
|
||||
// 1. `core` module:
|
||||
// For the Array<float> class that the `pose` module needs
|
||||
// For the Datum struct that the `thread` module sends between the queues
|
||||
// 2. `utilities` module: for the error & logging functions, i.e., op::error & op::log respectively
|
||||
// This file should only be used for the user to take specific examples.
|
||||
// ------------------------- OpenPose C++ API Tutorial - Example 8 - Custom Input and Output -------------------------
|
||||
// Asynchronous mode: ideal for fast prototyping when performance is not an issue.
|
||||
// In this function, the user can implement its own way to create frames (e.g., reading his own folder of images)
|
||||
// and its own way to render/display them after being processed by OpenPose.
|
||||
|
||||
// Command-line user intraface
|
||||
#define OPENPOSE_FLAGS_DISABLE_PRODUCER
|
||||
@@ -114,19 +102,27 @@ class UserOutputClass
|
||||
public:
|
||||
bool display(const std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>& datumsPtr)
|
||||
{
|
||||
// User's displaying/saving/other processing here
|
||||
// datumPtr->cvOutputData: rendered frame with pose or heatmaps
|
||||
// datumPtr->poseKeypoints: Array<float> with the estimated pose
|
||||
char key = ' ';
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
try
|
||||
{
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData);
|
||||
// Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image)
|
||||
key = (char)cv::waitKey(1);
|
||||
// User's displaying/saving/other processing here
|
||||
// datumPtr->cvOutputData: rendered frame with pose or heatmaps
|
||||
// datumPtr->poseKeypoints: Array<float> with the estimated pose
|
||||
char key = ' ';
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
// Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image)
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData);
|
||||
key = (char)cv::waitKey(1);
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
return (key == 27);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__);
|
||||
return (key == 27);
|
||||
}
|
||||
void printKeypoints(const std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>& datumsPtr)
|
||||
{
|
||||
@@ -177,16 +173,15 @@ public:
|
||||
}
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__);
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
}
|
||||
};
|
||||
|
||||
int tutorialApiCpp4()
|
||||
void configureWrapper(op::WrapperT<UserDatum>& opWrapperT)
|
||||
{
|
||||
try
|
||||
{
|
||||
op::log("Starting OpenPose demo...", op::Priority::High);
|
||||
const auto timerBegin = std::chrono::high_resolution_clock::now();
|
||||
// Configuring OpenPose
|
||||
|
||||
// logging_level
|
||||
op::check(0 <= FLAGS_logging_level && FLAGS_logging_level <= 255, "Wrong logging_level value.",
|
||||
@@ -217,12 +212,12 @@ int tutorialApiCpp4()
|
||||
const auto heatMapScaleMode = op::flagsToHeatMapScaleMode(FLAGS_heatmaps_scale);
|
||||
// >1 camera view?
|
||||
const auto multipleView = (FLAGS_3d || FLAGS_3d_views > 1);
|
||||
// Face and hand detectors
|
||||
const auto faceDetector = op::flagsToDetector(FLAGS_face_detector);
|
||||
const auto handDetector = op::flagsToDetector(FLAGS_hand_detector);
|
||||
// Enabling Google Logging
|
||||
const bool enableGoogleLogging = true;
|
||||
|
||||
// Configuring OpenPose
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::WrapperT<UserDatum> opWrapperT{op::ThreadManagerMode::Asynchronous};
|
||||
// Pose configuration (use WrapperStructPose{} for default and recommended configuration)
|
||||
const op::WrapperStructPose wrapperStructPose{
|
||||
!FLAGS_body_disable, netInputSize, outputSize, keypointScaleMode, FLAGS_num_gpu, FLAGS_num_gpu_start,
|
||||
@@ -234,12 +229,13 @@ int tutorialApiCpp4()
|
||||
opWrapperT.configure(wrapperStructPose);
|
||||
// Face configuration (use op::WrapperStructFace{} to disable it)
|
||||
const op::WrapperStructFace wrapperStructFace{
|
||||
FLAGS_face, faceNetInputSize, op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
FLAGS_face, faceDetector, faceNetInputSize,
|
||||
op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
|
||||
opWrapperT.configure(wrapperStructFace);
|
||||
// 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,
|
||||
FLAGS_hand, handDetector, handNetInputSize, FLAGS_hand_scale_number, (float)FLAGS_hand_scale_range,
|
||||
op::flagsToRenderMode(FLAGS_hand_render, multipleView, FLAGS_render_pose), (float)FLAGS_hand_alpha_pose,
|
||||
(float)FLAGS_hand_alpha_heatmap, (float)FLAGS_hand_render_threshold};
|
||||
opWrapperT.configure(wrapperStructHand);
|
||||
@@ -259,6 +255,24 @@ int tutorialApiCpp4()
|
||||
// Set to single-thread (for sequential processing and/or debugging and/or reducing latency)
|
||||
if (FLAGS_disable_multi_thread)
|
||||
opWrapperT.disableMultiThreading();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
}
|
||||
|
||||
int tutorialApiCpp()
|
||||
{
|
||||
try
|
||||
{
|
||||
op::log("Starting OpenPose demo...", op::Priority::High);
|
||||
const auto opTimer = op::getTimerInit();
|
||||
|
||||
// Configuring OpenPose
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::WrapperT<UserDatum> opWrapperT{op::ThreadManagerMode::Asynchronous};
|
||||
configureWrapper(opWrapperT);
|
||||
|
||||
// Start, run, and stop processing - exec() blocks this thread until OpenPose wrapper has finished
|
||||
op::log("Starting thread(s)...", op::Priority::High);
|
||||
@@ -284,8 +298,7 @@ int tutorialApiCpp4()
|
||||
userOutputClass.printKeypoints(datumProcessed);
|
||||
}
|
||||
else
|
||||
op::log("Processed datum could not be emplaced.", op::Priority::High,
|
||||
__LINE__, __FUNCTION__, __FILE__);
|
||||
op::log("Processed datum could not be emplaced.", op::Priority::High);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,14 +306,9 @@ int tutorialApiCpp4()
|
||||
opWrapperT.stop();
|
||||
|
||||
// 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 = "OpenPose demo successfully finished. Total time: "
|
||||
+ std::to_string(totalTimeSec) + " seconds.";
|
||||
op::log(message, op::Priority::High);
|
||||
op::printTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", op::Priority::High);
|
||||
|
||||
// Return successful message
|
||||
// Return
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
@@ -314,6 +322,6 @@ int main(int argc, char *argv[])
|
||||
// Parsing command line flags
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Running tutorialApiCpp4
|
||||
return tutorialApiCpp4();
|
||||
// Running tutorialApiCpp
|
||||
return tutorialApiCpp();
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
// ----------------------------- OpenPose C++ API Tutorial - Example 9 - Face from Image -----------------------------
|
||||
// It reads an image and the face location, process it, and displays the face keypoints. In addition,
|
||||
// it includes all the OpenPose configuration flags.
|
||||
// Input: An image and the face rectangle locations.
|
||||
// Output: OpenPose face keypoint detection.
|
||||
// NOTE: This demo is auto-selecting the following flags: `--body_disable --face --face_detector 2`
|
||||
|
||||
// Command-line user intraface
|
||||
#define OPENPOSE_FLAGS_DISABLE_PRODUCER
|
||||
#define OPENPOSE_FLAGS_DISABLE_DISPLAY
|
||||
#include <openpose/flags.hpp>
|
||||
// OpenPose dependencies
|
||||
#include <openpose/headers.hpp>
|
||||
|
||||
// Custom OpenPose flags
|
||||
// Producer
|
||||
DEFINE_string(image_path, "examples/media/COCO_val2014_000000000241.jpg",
|
||||
"Process an image. Read all standard formats (jpg, png, bmp, etc.).");
|
||||
// Display
|
||||
DEFINE_bool(no_display, false,
|
||||
"Enable to disable the visual display.");
|
||||
|
||||
// This worker will just read and return all the jpg files in a directory
|
||||
void display(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>>& datumsPtr)
|
||||
{
|
||||
try
|
||||
{
|
||||
// User's displaying/saving/other processing here
|
||||
// datum.cvOutputData: rendered frame with pose or heatmaps
|
||||
// datum.poseKeypoints: Array<float> with the estimated pose
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
// Display image
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData);
|
||||
cv::waitKey(0);
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
}
|
||||
|
||||
void printKeypoints(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>>& datumsPtr)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Example: How to use the pose keypoints
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
op::log("Body keypoints: " + datumsPtr->at(0)->poseKeypoints.toString());
|
||||
op::log("Face keypoints: " + datumsPtr->at(0)->faceKeypoints.toString());
|
||||
op::log("Left hand keypoints: " + datumsPtr->at(0)->handKeypoints[0].toString());
|
||||
op::log("Right hand keypoints: " + datumsPtr->at(0)->handKeypoints[1].toString());
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
}
|
||||
|
||||
void configureWrapper(op::Wrapper& opWrapper)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Configuring OpenPose
|
||||
|
||||
// logging_level
|
||||
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::Profiler::setDefaultX(FLAGS_profile_speed);
|
||||
|
||||
// Applying user defined configuration - GFlags to program variables
|
||||
// outputSize
|
||||
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
|
||||
// netInputSize
|
||||
const auto netInputSize = op::flagsToPoint(FLAGS_net_resolution, "-1x368");
|
||||
// faceNetInputSize
|
||||
const auto faceNetInputSize = op::flagsToPoint(FLAGS_face_net_resolution, "368x368 (multiples of 16)");
|
||||
// handNetInputSize
|
||||
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
|
||||
// poseModel
|
||||
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
|
||||
// JSON saving
|
||||
if (!FLAGS_write_keypoint.empty())
|
||||
op::log("Flag `write_keypoint` is deprecated and will eventually be removed."
|
||||
" Please, use `write_json` instead.", op::Priority::Max);
|
||||
// keypointScaleMode
|
||||
const auto keypointScaleMode = 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);
|
||||
const auto heatMapScaleMode = op::flagsToHeatMapScaleMode(FLAGS_heatmaps_scale);
|
||||
// >1 camera view?
|
||||
const auto multipleView = (FLAGS_3d || FLAGS_3d_views > 1);
|
||||
// Face and hand detectors
|
||||
const auto faceDetector = op::Detector::Provided;
|
||||
const auto handDetector = op::flagsToDetector(FLAGS_hand_detector);
|
||||
// Enabling Google Logging
|
||||
const bool enableGoogleLogging = true;
|
||||
|
||||
// Pose configuration (use WrapperStructPose{} for default and recommended configuration)
|
||||
const auto bodyEnable = false;
|
||||
const op::WrapperStructPose wrapperStructPose{
|
||||
bodyEnable, netInputSize, outputSize, keypointScaleMode, FLAGS_num_gpu, FLAGS_num_gpu_start,
|
||||
FLAGS_scale_number, (float)FLAGS_scale_gap, op::flagsToRenderMode(FLAGS_render_pose, multipleView),
|
||||
poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
|
||||
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScaleMode, FLAGS_part_candidates,
|
||||
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
|
||||
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
|
||||
opWrapper.configure(wrapperStructPose);
|
||||
// Face configuration (use op::WrapperStructFace{} to disable it)
|
||||
const auto face = true;
|
||||
const op::WrapperStructFace wrapperStructFace{
|
||||
face, faceDetector, faceNetInputSize,
|
||||
op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
|
||||
opWrapper.configure(wrapperStructFace);
|
||||
// Hand configuration (use op::WrapperStructHand{} to disable it)
|
||||
const op::WrapperStructHand wrapperStructHand{
|
||||
FLAGS_hand, handDetector, handNetInputSize, FLAGS_hand_scale_number, (float)FLAGS_hand_scale_range,
|
||||
op::flagsToRenderMode(FLAGS_hand_render, multipleView, FLAGS_render_pose), (float)FLAGS_hand_alpha_pose,
|
||||
(float)FLAGS_hand_alpha_heatmap, (float)FLAGS_hand_render_threshold};
|
||||
opWrapper.configure(wrapperStructHand);
|
||||
// Extra functionality configuration (use op::WrapperStructExtra{} to disable it)
|
||||
const op::WrapperStructExtra wrapperStructExtra{
|
||||
FLAGS_3d, FLAGS_3d_min_views, FLAGS_identification, FLAGS_tracking, FLAGS_ik_threads};
|
||||
opWrapper.configure(wrapperStructExtra);
|
||||
// Output (comment or use default argument to disable any output)
|
||||
const op::WrapperStructOutput wrapperStructOutput{
|
||||
FLAGS_cli_verbose, FLAGS_write_keypoint, op::stringToDataFormat(FLAGS_write_keypoint_format),
|
||||
FLAGS_write_json, FLAGS_write_coco_json, FLAGS_write_coco_foot_json, FLAGS_write_coco_json_variant,
|
||||
FLAGS_write_images, FLAGS_write_images_format, FLAGS_write_video, FLAGS_write_video_fps,
|
||||
FLAGS_write_video_with_audio, FLAGS_write_heatmaps, FLAGS_write_heatmaps_format, FLAGS_write_video_3d,
|
||||
FLAGS_write_video_adam, FLAGS_write_bvh, FLAGS_udp_host, FLAGS_udp_port};
|
||||
opWrapper.configure(wrapperStructOutput);
|
||||
// No GUI. Equivalent to: opWrapper.configure(op::WrapperStructGui{});
|
||||
// Set to single-thread (for sequential processing and/or debugging and/or reducing latency)
|
||||
if (FLAGS_disable_multi_thread)
|
||||
opWrapper.disableMultiThreading();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
}
|
||||
|
||||
int tutorialApiCpp()
|
||||
{
|
||||
try
|
||||
{
|
||||
op::log("Starting OpenPose demo...", op::Priority::High);
|
||||
const auto opTimer = op::getTimerInit();
|
||||
|
||||
// Configuring OpenPose
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::Wrapper opWrapper{op::ThreadManagerMode::Asynchronous};
|
||||
configureWrapper(opWrapper);
|
||||
|
||||
// Starting OpenPose
|
||||
op::log("Starting thread(s)...", op::Priority::High);
|
||||
opWrapper.start();
|
||||
|
||||
// Read image and face rectangle locations
|
||||
const auto imageToProcess = cv::imread(FLAGS_image_path);
|
||||
const std::vector<op::Rectangle<float>> faceRectangles{
|
||||
op::Rectangle<float>{330.119385f, 277.532715f, 48.717274f, 48.717274f}, // Face 0
|
||||
op::Rectangle<float>{24.036991f, 267.918793f, 65.175171f, 65.175171f}, // Face 1
|
||||
op::Rectangle<float>{151.803436f, 32.477852f, 108.295761f, 108.295761f} // Face 2
|
||||
};
|
||||
|
||||
// Create new datum
|
||||
auto datumsPtr = std::make_shared<std::vector<std::shared_ptr<op::Datum>>>();
|
||||
datumsPtr->emplace_back();
|
||||
auto& datumPtr = datumsPtr->at(0);
|
||||
datumPtr = std::make_shared<op::Datum>();
|
||||
// Fill datum with image and faceRectangles
|
||||
datumPtr->cvInputData = imageToProcess;
|
||||
datumPtr->faceRectangles = faceRectangles;
|
||||
|
||||
// Process and display image
|
||||
opWrapper.emplaceAndPop(datumsPtr);
|
||||
if (datumsPtr != nullptr)
|
||||
{
|
||||
printKeypoints(datumsPtr);
|
||||
if (!FLAGS_no_display)
|
||||
display(datumsPtr);
|
||||
}
|
||||
else
|
||||
op::log("Image could not be processed.", op::Priority::High);
|
||||
|
||||
// Info
|
||||
op::log("NOTE: In addition with the user flags, this demo has auto-selected the following flags:"
|
||||
" `--body_disable --face --face_detector 2`", op::Priority::High);
|
||||
|
||||
// Measuring total time
|
||||
op::printTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", op::Priority::High);
|
||||
|
||||
// Return
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Parsing command line flags
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Running tutorialApiCpp
|
||||
return tutorialApiCpp();
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
// ----------------------------- OpenPose C++ API Tutorial - Example 9 - Face from Image -----------------------------
|
||||
// It reads an image and the hand location, process it, and displays the hand keypoints. In addition,
|
||||
// it includes all the OpenPose configuration flags.
|
||||
// Input: An image and the hand rectangle locations.
|
||||
// Output: OpenPose hand keypoint detection.
|
||||
// NOTE: This demo is auto-selecting the following flags: `--body_disable --hand --hand_detector 2`
|
||||
|
||||
// Command-line user intraface
|
||||
#define OPENPOSE_FLAGS_DISABLE_PRODUCER
|
||||
#define OPENPOSE_FLAGS_DISABLE_DISPLAY
|
||||
#include <openpose/flags.hpp>
|
||||
// OpenPose dependencies
|
||||
#include <openpose/headers.hpp>
|
||||
|
||||
// Custom OpenPose flags
|
||||
// Producer
|
||||
DEFINE_string(image_path, "examples/media/COCO_val2014_000000000241.jpg",
|
||||
"Process an image. Read all standard formats (jpg, png, bmp, etc.).");
|
||||
// Display
|
||||
DEFINE_bool(no_display, false,
|
||||
"Enable to disable the visual display.");
|
||||
|
||||
// This worker will just read and return all the jpg files in a directory
|
||||
void display(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>>& datumsPtr)
|
||||
{
|
||||
try
|
||||
{
|
||||
// User's displaying/saving/other processing here
|
||||
// datum.cvOutputData: rendered frame with pose or heatmaps
|
||||
// datum.poseKeypoints: Array<float> with the estimated pose
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
// Display image
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData);
|
||||
cv::waitKey(0);
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
}
|
||||
|
||||
void printKeypoints(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>>& datumsPtr)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Example: How to use the pose keypoints
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
op::log("Body keypoints: " + datumsPtr->at(0)->poseKeypoints.toString());
|
||||
op::log("Face keypoints: " + datumsPtr->at(0)->faceKeypoints.toString());
|
||||
op::log("Left hand keypoints: " + datumsPtr->at(0)->handKeypoints[0].toString());
|
||||
op::log("Right hand keypoints: " + datumsPtr->at(0)->handKeypoints[1].toString());
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
}
|
||||
|
||||
void configureWrapper(op::Wrapper& opWrapper)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Configuring OpenPose
|
||||
|
||||
// logging_level
|
||||
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::Profiler::setDefaultX(FLAGS_profile_speed);
|
||||
|
||||
// Applying user defined configuration - GFlags to program variables
|
||||
// outputSize
|
||||
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
|
||||
// netInputSize
|
||||
const auto netInputSize = op::flagsToPoint(FLAGS_net_resolution, "-1x368");
|
||||
// faceNetInputSize
|
||||
const auto faceNetInputSize = op::flagsToPoint(FLAGS_face_net_resolution, "368x368 (multiples of 16)");
|
||||
// handNetInputSize
|
||||
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
|
||||
// poseModel
|
||||
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
|
||||
// JSON saving
|
||||
if (!FLAGS_write_keypoint.empty())
|
||||
op::log("Flag `write_keypoint` is deprecated and will eventually be removed."
|
||||
" Please, use `write_json` instead.", op::Priority::Max);
|
||||
// keypointScaleMode
|
||||
const auto keypointScaleMode = 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);
|
||||
const auto heatMapScaleMode = op::flagsToHeatMapScaleMode(FLAGS_heatmaps_scale);
|
||||
// >1 camera view?
|
||||
const auto multipleView = (FLAGS_3d || FLAGS_3d_views > 1);
|
||||
// Face and hand detectors
|
||||
const auto faceDetector = op::flagsToDetector(FLAGS_face_detector);
|
||||
const auto handDetector = op::Detector::Provided;
|
||||
// Enabling Google Logging
|
||||
const bool enableGoogleLogging = true;
|
||||
|
||||
// Pose configuration (use WrapperStructPose{} for default and recommended configuration)
|
||||
const auto bodyEnable = false;
|
||||
const op::WrapperStructPose wrapperStructPose{
|
||||
bodyEnable, netInputSize, outputSize, keypointScaleMode, FLAGS_num_gpu, FLAGS_num_gpu_start,
|
||||
FLAGS_scale_number, (float)FLAGS_scale_gap, op::flagsToRenderMode(FLAGS_render_pose, multipleView),
|
||||
poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
|
||||
FLAGS_part_to_show, FLAGS_model_folder, heatMapTypes, heatMapScaleMode, FLAGS_part_candidates,
|
||||
(float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
|
||||
FLAGS_prototxt_path, FLAGS_caffemodel_path, enableGoogleLogging};
|
||||
opWrapper.configure(wrapperStructPose);
|
||||
// Face configuration (use op::WrapperStructFace{} to disable it)
|
||||
const op::WrapperStructFace wrapperStructFace{
|
||||
FLAGS_face, faceDetector, faceNetInputSize,
|
||||
op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
|
||||
opWrapper.configure(wrapperStructFace);
|
||||
// Hand configuration (use op::WrapperStructHand{} to disable it)
|
||||
const auto hand = true;
|
||||
const op::WrapperStructHand wrapperStructHand{
|
||||
hand, handDetector, handNetInputSize, FLAGS_hand_scale_number, (float)FLAGS_hand_scale_range,
|
||||
op::flagsToRenderMode(FLAGS_hand_render, multipleView, FLAGS_render_pose), (float)FLAGS_hand_alpha_pose,
|
||||
(float)FLAGS_hand_alpha_heatmap, (float)FLAGS_hand_render_threshold};
|
||||
opWrapper.configure(wrapperStructHand);
|
||||
// Extra functionality configuration (use op::WrapperStructExtra{} to disable it)
|
||||
const op::WrapperStructExtra wrapperStructExtra{
|
||||
FLAGS_3d, FLAGS_3d_min_views, FLAGS_identification, FLAGS_tracking, FLAGS_ik_threads};
|
||||
opWrapper.configure(wrapperStructExtra);
|
||||
// Output (comment or use default argument to disable any output)
|
||||
const op::WrapperStructOutput wrapperStructOutput{
|
||||
FLAGS_cli_verbose, FLAGS_write_keypoint, op::stringToDataFormat(FLAGS_write_keypoint_format),
|
||||
FLAGS_write_json, FLAGS_write_coco_json, FLAGS_write_coco_foot_json, FLAGS_write_coco_json_variant,
|
||||
FLAGS_write_images, FLAGS_write_images_format, FLAGS_write_video, FLAGS_write_video_fps,
|
||||
FLAGS_write_video_with_audio, FLAGS_write_heatmaps, FLAGS_write_heatmaps_format, FLAGS_write_video_3d,
|
||||
FLAGS_write_video_adam, FLAGS_write_bvh, FLAGS_udp_host, FLAGS_udp_port};
|
||||
opWrapper.configure(wrapperStructOutput);
|
||||
// No GUI. Equivalent to: opWrapper.configure(op::WrapperStructGui{});
|
||||
// Set to single-thread (for sequential processing and/or debugging and/or reducing latency)
|
||||
if (FLAGS_disable_multi_thread)
|
||||
opWrapper.disableMultiThreading();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
}
|
||||
|
||||
int tutorialApiCpp()
|
||||
{
|
||||
try
|
||||
{
|
||||
op::log("Starting OpenPose demo...", op::Priority::High);
|
||||
const auto opTimer = op::getTimerInit();
|
||||
|
||||
// Configuring OpenPose
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::Wrapper opWrapper{op::ThreadManagerMode::Asynchronous};
|
||||
configureWrapper(opWrapper);
|
||||
|
||||
// Starting OpenPose
|
||||
op::log("Starting thread(s)...", op::Priority::High);
|
||||
opWrapper.start();
|
||||
|
||||
// Read image and hand rectangle locations
|
||||
const auto imageToProcess = cv::imread(FLAGS_image_path);
|
||||
const std::vector<std::array<op::Rectangle<float>, 2>> handRectangles{
|
||||
// Left/Right hands person 0
|
||||
std::array<op::Rectangle<float>, 2>{
|
||||
op::Rectangle<float>{320.035889f, 377.675049f, 69.300949f, 69.300949f},
|
||||
op::Rectangle<float>{0.f, 0.f, 0.f, 0.f}},
|
||||
// Left/Right hands person 1
|
||||
std::array<op::Rectangle<float>, 2>{
|
||||
op::Rectangle<float>{80.155792f, 407.673492f, 80.812706f, 80.812706f},
|
||||
op::Rectangle<float>{46.449715f, 404.559753f, 98.898178f, 98.898178f}},
|
||||
// Left/Right hands person 2
|
||||
std::array<op::Rectangle<float>, 2>{
|
||||
op::Rectangle<float>{185.692673f, 303.112244f, 157.587555f, 157.587555f},
|
||||
op::Rectangle<float>{88.984360f, 268.866547f, 117.818230f, 117.818230f}}
|
||||
};
|
||||
|
||||
// Create new datum
|
||||
auto datumsPtr = std::make_shared<std::vector<std::shared_ptr<op::Datum>>>();
|
||||
datumsPtr->emplace_back();
|
||||
auto& datumPtr = datumsPtr->at(0);
|
||||
datumPtr = std::make_shared<op::Datum>();
|
||||
// Fill datum with image and handRectangles
|
||||
datumPtr->cvInputData = imageToProcess;
|
||||
datumPtr->handRectangles = handRectangles;
|
||||
|
||||
// Process and display image
|
||||
opWrapper.emplaceAndPop(datumsPtr);
|
||||
if (datumsPtr != nullptr)
|
||||
{
|
||||
printKeypoints(datumsPtr);
|
||||
if (!FLAGS_no_display)
|
||||
display(datumsPtr);
|
||||
}
|
||||
else
|
||||
op::log("Image could not be processed.", op::Priority::High);
|
||||
|
||||
// Info
|
||||
op::log("NOTE: In addition with the user flags, this demo has auto-selected the following flags:"
|
||||
" `--body_disable --hand --hand_detector 2`", op::Priority::High);
|
||||
|
||||
// Measuring total time
|
||||
op::printTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", op::Priority::High);
|
||||
|
||||
// Return
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Parsing command line flags
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Running tutorialApiCpp
|
||||
return tutorialApiCpp();
|
||||
}
|
||||
+11
-7
@@ -110,7 +110,7 @@ private:
|
||||
unsigned long long mCounter;
|
||||
};
|
||||
|
||||
int tutorialApiCpp7()
|
||||
int tutorialApiCpp()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -152,6 +152,9 @@ int tutorialApiCpp7()
|
||||
// >1 camera view?
|
||||
// const auto multipleView = (FLAGS_3d || FLAGS_3d_views > 1 || FLAGS_flir_camera);
|
||||
const auto multipleView = false;
|
||||
// Face and hand detectors
|
||||
const auto faceDetector = op::flagsToDetector(FLAGS_face_detector);
|
||||
const auto handDetector = op::flagsToDetector(FLAGS_hand_detector);
|
||||
// Enabling Google Logging
|
||||
const bool enableGoogleLogging = true;
|
||||
|
||||
@@ -177,12 +180,13 @@ int tutorialApiCpp7()
|
||||
opWrapperT.configure(wrapperStructPose);
|
||||
// Face configuration (use op::WrapperStructFace{} to disable it)
|
||||
const op::WrapperStructFace wrapperStructFace{
|
||||
FLAGS_face, faceNetInputSize, op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
FLAGS_face, faceDetector, faceNetInputSize,
|
||||
op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
|
||||
opWrapperT.configure(wrapperStructFace);
|
||||
// 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,
|
||||
FLAGS_hand, handDetector, handNetInputSize, FLAGS_hand_scale_number, (float)FLAGS_hand_scale_range,
|
||||
op::flagsToRenderMode(FLAGS_hand_render, multipleView, FLAGS_render_pose), (float)FLAGS_hand_alpha_pose,
|
||||
(float)FLAGS_hand_alpha_heatmap, (float)FLAGS_hand_render_threshold};
|
||||
opWrapperT.configure(wrapperStructHand);
|
||||
@@ -212,8 +216,8 @@ int tutorialApiCpp7()
|
||||
|
||||
// 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 totalTimeSec = double(
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(now-timerBegin).count()* 1e-9);
|
||||
const auto message = "OpenPose demo successfully finished. Total time: "
|
||||
+ std::to_string(totalTimeSec) + " seconds.";
|
||||
op::log(message, op::Priority::High);
|
||||
@@ -232,6 +236,6 @@ int main(int argc, char *argv[])
|
||||
// Parsing command line flags
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Running tutorialApiCpp7
|
||||
return tutorialApiCpp7();
|
||||
// Running tutorialApiCpp
|
||||
return tutorialApiCpp();
|
||||
}
|
||||
+16
-12
@@ -68,7 +68,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
int tutorialApiCpp6()
|
||||
int tutorialApiCpp()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -87,6 +87,11 @@ int tutorialApiCpp6()
|
||||
// op::Profiler::setDefaultX(100);
|
||||
|
||||
// Applying user defined configuration - GFlags to program variables
|
||||
// producerType
|
||||
op::ProducerType producerType;
|
||||
std::string producerString;
|
||||
std::tie(producerType, producerString) = op::flagsToProducer(
|
||||
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
|
||||
// cameraSize
|
||||
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
|
||||
// outputSize
|
||||
@@ -97,11 +102,6 @@ int tutorialApiCpp6()
|
||||
const auto faceNetInputSize = op::flagsToPoint(FLAGS_face_net_resolution, "368x368 (multiples of 16)");
|
||||
// handNetInputSize
|
||||
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
|
||||
// producerType
|
||||
op::ProducerType producerType;
|
||||
std::string producerString;
|
||||
std::tie(producerType, producerString) = op::flagsToProducer(
|
||||
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
|
||||
// poseModel
|
||||
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
|
||||
// JSON saving
|
||||
@@ -116,6 +116,9 @@ int tutorialApiCpp6()
|
||||
const auto heatMapScaleMode = op::flagsToHeatMapScaleMode(FLAGS_heatmaps_scale);
|
||||
// >1 camera view?
|
||||
const auto multipleView = (FLAGS_3d || FLAGS_3d_views > 1 || FLAGS_flir_camera);
|
||||
// Face and hand detectors
|
||||
const auto faceDetector = op::flagsToDetector(FLAGS_face_detector);
|
||||
const auto handDetector = op::flagsToDetector(FLAGS_hand_detector);
|
||||
// Enabling Google Logging
|
||||
const bool enableGoogleLogging = true;
|
||||
|
||||
@@ -141,12 +144,13 @@ int tutorialApiCpp6()
|
||||
opWrapperT.configure(wrapperStructPose);
|
||||
// Face configuration (use op::WrapperStructFace{} to disable it)
|
||||
const op::WrapperStructFace wrapperStructFace{
|
||||
FLAGS_face, faceNetInputSize, op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
FLAGS_face, faceDetector, faceNetInputSize,
|
||||
op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
|
||||
opWrapperT.configure(wrapperStructFace);
|
||||
// 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,
|
||||
FLAGS_hand, handDetector, handNetInputSize, FLAGS_hand_scale_number, (float)FLAGS_hand_scale_range,
|
||||
op::flagsToRenderMode(FLAGS_hand_render, multipleView, FLAGS_render_pose), (float)FLAGS_hand_alpha_pose,
|
||||
(float)FLAGS_hand_alpha_heatmap, (float)FLAGS_hand_render_threshold};
|
||||
opWrapperT.configure(wrapperStructHand);
|
||||
@@ -182,8 +186,8 @@ int tutorialApiCpp6()
|
||||
|
||||
// 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 totalTimeSec = double(
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(now-timerBegin).count()* 1e-9);
|
||||
const auto message = "OpenPose demo successfully finished. Total time: "
|
||||
+ std::to_string(totalTimeSec) + " seconds.";
|
||||
op::log(message, op::Priority::High);
|
||||
@@ -202,6 +206,6 @@ int main(int argc, char *argv[])
|
||||
// Parsing command line flags
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Running tutorialApiCpp6
|
||||
return tutorialApiCpp6();
|
||||
// Running tutorialApiCpp
|
||||
return tutorialApiCpp();
|
||||
}
|
||||
+16
-12
@@ -125,7 +125,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
int tutorialApiCpp8()
|
||||
int tutorialApiCpp()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -144,6 +144,11 @@ int tutorialApiCpp8()
|
||||
// op::Profiler::setDefaultX(100);
|
||||
|
||||
// Applying user defined configuration - GFlags to program variables
|
||||
// producerType
|
||||
op::ProducerType producerType;
|
||||
std::string producerString;
|
||||
std::tie(producerType, producerString) = op::flagsToProducer(
|
||||
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
|
||||
// cameraSize
|
||||
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
|
||||
// outputSize
|
||||
@@ -154,11 +159,6 @@ int tutorialApiCpp8()
|
||||
const auto faceNetInputSize = op::flagsToPoint(FLAGS_face_net_resolution, "368x368 (multiples of 16)");
|
||||
// handNetInputSize
|
||||
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
|
||||
// producerType
|
||||
op::ProducerType producerType;
|
||||
std::string producerString;
|
||||
std::tie(producerType, producerString) = op::flagsToProducer(
|
||||
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
|
||||
// poseModel
|
||||
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
|
||||
// JSON saving
|
||||
@@ -173,6 +173,9 @@ int tutorialApiCpp8()
|
||||
const auto heatMapScaleMode = op::flagsToHeatMapScaleMode(FLAGS_heatmaps_scale);
|
||||
// >1 camera view?
|
||||
const auto multipleView = (FLAGS_3d || FLAGS_3d_views > 1 || FLAGS_flir_camera);
|
||||
// Face and hand detectors
|
||||
const auto faceDetector = op::flagsToDetector(FLAGS_face_detector);
|
||||
const auto handDetector = op::flagsToDetector(FLAGS_hand_detector);
|
||||
// Enabling Google Logging
|
||||
const bool enableGoogleLogging = true;
|
||||
|
||||
@@ -198,12 +201,13 @@ int tutorialApiCpp8()
|
||||
opWrapperT.configure(wrapperStructPose);
|
||||
// Face configuration (use op::WrapperStructFace{} to disable it)
|
||||
const op::WrapperStructFace wrapperStructFace{
|
||||
FLAGS_face, faceNetInputSize, op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
FLAGS_face, faceDetector, faceNetInputSize,
|
||||
op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
|
||||
opWrapperT.configure(wrapperStructFace);
|
||||
// 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,
|
||||
FLAGS_hand, handDetector, handNetInputSize, FLAGS_hand_scale_number, (float)FLAGS_hand_scale_range,
|
||||
op::flagsToRenderMode(FLAGS_hand_render, multipleView, FLAGS_render_pose), (float)FLAGS_hand_alpha_pose,
|
||||
(float)FLAGS_hand_alpha_heatmap, (float)FLAGS_hand_render_threshold};
|
||||
opWrapperT.configure(wrapperStructHand);
|
||||
@@ -236,8 +240,8 @@ int tutorialApiCpp8()
|
||||
|
||||
// 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 totalTimeSec = double(
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(now-timerBegin).count()* 1e-9);
|
||||
const auto message = "OpenPose demo successfully finished. Total time: "
|
||||
+ std::to_string(totalTimeSec) + " seconds.";
|
||||
op::log(message, op::Priority::High);
|
||||
@@ -256,6 +260,6 @@ int main(int argc, char *argv[])
|
||||
// Parsing command line flags
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Running tutorialApiCpp8
|
||||
return tutorialApiCpp8();
|
||||
// Running tutorialApiCpp
|
||||
return tutorialApiCpp();
|
||||
}
|
||||
+11
-7
@@ -224,7 +224,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
int tutorialApiCpp9()
|
||||
int tutorialApiCpp()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -260,6 +260,9 @@ int tutorialApiCpp9()
|
||||
const auto heatMapScaleMode = op::flagsToHeatMapScaleMode(FLAGS_heatmaps_scale);
|
||||
// >1 camera view?
|
||||
const auto multipleView = (FLAGS_3d || FLAGS_3d_views > 1);
|
||||
// Face and hand detectors
|
||||
const auto faceDetector = op::flagsToDetector(FLAGS_face_detector);
|
||||
const auto handDetector = op::flagsToDetector(FLAGS_hand_detector);
|
||||
// Enabling Google Logging
|
||||
const bool enableGoogleLogging = true;
|
||||
|
||||
@@ -295,12 +298,13 @@ int tutorialApiCpp9()
|
||||
opWrapperT.configure(wrapperStructPose);
|
||||
// Face configuration (use op::WrapperStructFace{} to disable it)
|
||||
const op::WrapperStructFace wrapperStructFace{
|
||||
FLAGS_face, faceNetInputSize, op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
FLAGS_face, faceDetector, faceNetInputSize,
|
||||
op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
|
||||
(float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
|
||||
opWrapperT.configure(wrapperStructFace);
|
||||
// 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,
|
||||
FLAGS_hand, handDetector, handNetInputSize, FLAGS_hand_scale_number, (float)FLAGS_hand_scale_range,
|
||||
op::flagsToRenderMode(FLAGS_hand_render, multipleView, FLAGS_render_pose), (float)FLAGS_hand_alpha_pose,
|
||||
(float)FLAGS_hand_alpha_heatmap, (float)FLAGS_hand_render_threshold};
|
||||
opWrapperT.configure(wrapperStructHand);
|
||||
@@ -327,8 +331,8 @@ int tutorialApiCpp9()
|
||||
|
||||
// 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 totalTimeSec = double(
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(now-timerBegin).count()* 1e-9);
|
||||
const auto message = "OpenPose demo successfully finished. Total time: "
|
||||
+ std::to_string(totalTimeSec) + " seconds.";
|
||||
op::log(message, op::Priority::High);
|
||||
@@ -347,6 +351,6 @@ int main(int argc, char *argv[])
|
||||
// Parsing command line flags
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Running tutorialApiCpp9
|
||||
return tutorialApiCpp9();
|
||||
// Running tutorialApiCpp
|
||||
return tutorialApiCpp();
|
||||
}
|
||||
@@ -1,13 +1,18 @@
|
||||
set(EXAMPLE_FILES
|
||||
1_body_from_image.cpp
|
||||
2_whole_body_from_image.cpp
|
||||
3_keypoints_from_image_configurable.cpp
|
||||
4_asynchronous_loop_custom_input_and_output.cpp
|
||||
5_asynchronous_loop_custom_output.cpp
|
||||
6_synchronous_custom_postprocessing.cpp
|
||||
7_synchronous_custom_input.cpp
|
||||
8_synchronous_custom_output.cpp
|
||||
9_synchronous_custom_all.cpp)
|
||||
01_body_from_image_default.cpp
|
||||
02_whole_body_from_image_default.cpp
|
||||
03_keypoints_from_image.cpp
|
||||
04_keypoints_from_images.cpp
|
||||
05_keypoints_from_images_multi_gpu.cpp
|
||||
06_asynchronous_custom_input.cpp
|
||||
07_asynchronous_custom_output.cpp
|
||||
08_asynchronous_custom_input_output_and_datum.cpp
|
||||
09_face_from_image.cpp
|
||||
10_hand_from_image.cpp
|
||||
11_synchronous_custom_input.cpp
|
||||
13_synchronous_custom_postprocessing.cpp
|
||||
14_synchronous_custom_output.cpp
|
||||
15_synchronous_custom_all.cpp)
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/Utils.cmake)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user