Added most examples to Travis

This commit is contained in:
gineshidalgo99
2019-01-18 12:38:04 -05:00
parent 1f13f818a8
commit e2995e173e
22 changed files with 338 additions and 164 deletions
+55 -36
View File
@@ -11,56 +11,73 @@
// Producer
DEFINE_string(image_path, "examples/media/COCO_val2014_000000000192.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)
{
// 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())
try
{
// Display image
cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData);
cv::waitKey(0);
// 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__);
}
else
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
}
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())
try
{
// Alternative 1
op::log("Body keypoints: " + datumsPtr->at(0)->poseKeypoints.toString());
// Example: How to use the pose keypoints
if (datumsPtr != nullptr && !datumsPtr->empty())
{
// Alternative 1
op::log("Body keypoints: " + datumsPtr->at(0)->poseKeypoints.toString());
// // Alternative 2
// op::log(datumsPtr->at(0).poseKeypoints);
// // Alternative 2
// op::log(datumsPtr->at(0).poseKeypoints);
// // Alternative 3
// std::cout << datumsPtr->at(0).poseKeypoints << std::endl;
// // Alternative 3
// std::cout << datumsPtr->at(0).poseKeypoints << std::endl;
// // Alternative 4 - Accesing each element of the keypoints
// op::log("\nKeypoints:");
// const auto& poseKeypoints = datumsPtr->at(0).poseKeypoints;
// op::log("Person pose keypoints:");
// for (auto person = 0 ; person < poseKeypoints.getSize(0) ; person++)
// {
// op::log("Person " + std::to_string(person) + " (x, y, score):");
// for (auto bodyPart = 0 ; bodyPart < poseKeypoints.getSize(1) ; bodyPart++)
// {
// std::string valueToPrint;
// for (auto xyscore = 0 ; xyscore < poseKeypoints.getSize(2) ; xyscore++)
// valueToPrint += std::to_string( poseKeypoints[{person, bodyPart, xyscore}] ) + " ";
// op::log(valueToPrint);
// }
// }
// op::log(" ");
// // Alternative 4 - Accesing each element of the keypoints
// op::log("\nKeypoints:");
// const auto& poseKeypoints = datumsPtr->at(0).poseKeypoints;
// op::log("Person pose keypoints:");
// for (auto person = 0 ; person < poseKeypoints.getSize(0) ; person++)
// {
// op::log("Person " + std::to_string(person) + " (x, y, score):");
// for (auto bodyPart = 0 ; bodyPart < poseKeypoints.getSize(1) ; bodyPart++)
// {
// std::string valueToPrint;
// for (auto xyscore = 0 ; xyscore < poseKeypoints.getSize(2) ; xyscore++)
// valueToPrint += std::to_string( poseKeypoints[{person, bodyPart, xyscore}] ) + " ";
// op::log(valueToPrint);
// }
// }
// op::log(" ");
}
else
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
}
catch (const std::exception& e)
{
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
}
else
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
}
int tutorialApiCpp1()
@@ -75,6 +92,7 @@ int tutorialApiCpp1()
// Set to single-thread (for sequential processing and/or debugging and/or reducing latency)
if (FLAGS_disable_multi_thread)
opWrapper.disableMultiThreading();
// Starting OpenPose
op::log("Starting thread(s)...", op::Priority::High);
opWrapper.start();
@@ -85,7 +103,8 @@ int tutorialApiCpp1()
if (datumProcessed != nullptr)
{
printKeypoints(datumProcessed);
display(datumProcessed);
if (!FLAGS_no_display)
display(datumProcessed);
}
else
op::log("Image could not be processed.", op::Priority::High);
@@ -11,35 +11,52 @@
// 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)
{
// 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())
try
{
// Display image
cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData);
cv::waitKey(0);
// 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__);
}
else
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
}
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())
try
{
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());
// 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__);
}
else
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
}
int tutorialApiCpp2()
@@ -57,6 +74,7 @@ int tutorialApiCpp2()
// Set to single-thread (for sequential processing and/or debugging and/or reducing latency)
if (FLAGS_disable_multi_thread)
opWrapper.disableMultiThreading();
// Starting OpenPose
op::log("Starting thread(s)...", op::Priority::High);
opWrapper.start();
@@ -67,7 +85,8 @@ int tutorialApiCpp2()
if (datumProcessed != nullptr)
{
printKeypoints(datumProcessed);
display(datumProcessed);
if (!FLAGS_no_display)
display(datumProcessed);
}
else
op::log("Image could not be processed.", op::Priority::High);
@@ -13,48 +13,59 @@
// Producer
DEFINE_string(image_path, "examples/media/COCO_val2014_000000000294.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)
{
// 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())
try
{
// Display image
cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData);
cv::waitKey(0);
// 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__);
}
else
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
}
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())
try
{
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());
// 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__);
}
else
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
}
int tutorialApiCpp3()
void configureWrapper(op::Wrapper& opWrapper)
{
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);
// Configuring OpenPose
// Applying user defined configuration - GFlags to program variables
// outputSize
@@ -82,9 +93,6 @@ int tutorialApiCpp3()
// Enabling Google Logging
const bool enableGoogleLogging = true;
// Configuring OpenPose
op::log("Configuring OpenPose...", op::Priority::High);
op::Wrapper opWrapper{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,
@@ -121,6 +129,30 @@ int tutorialApiCpp3()
// 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 tutorialApiCpp3()
{
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);
// 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();
@@ -131,7 +163,8 @@ int tutorialApiCpp3()
if (datumProcessed != nullptr)
{
printKeypoints(datumProcessed);
display(datumProcessed);
if (!FLAGS_no_display)
display(datumProcessed);
}
else
op::log("Image could not be processed.", op::Priority::High);
@@ -26,6 +26,9 @@
// 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.");
// 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
@@ -44,13 +47,13 @@ struct UserDatum : public op::Datum
// 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
// This worker will just read and return all the jpg files in a directory
// 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, "jpg")},
// If we want "jpg" + "png" images
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}
@@ -276,7 +279,8 @@ int tutorialApiCpp4()
std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>> datumProcessed;
if (successfullyEmplaced && opWrapperT.waitAndPop(datumProcessed))
{
userWantsToExit = userOutputClass.display(datumProcessed);
if (!FLAGS_no_display)
userWantsToExit = userOutputClass.display(datumProcessed);
userOutputClass.printKeypoints(datumProcessed);
}
else
@@ -21,6 +21,11 @@
// OpenPose dependencies
#include <openpose/headers.hpp>
// Custom OpenPose flags
// Display
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
@@ -218,9 +223,14 @@ int tutorialApiCpp5()
std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>> datumProcessed;
if (opWrapperT.waitAndPop(datumProcessed))
{
userWantsToExit = userOutputClass.display(datumProcessed);;
if (!FLAGS_no_display)
userWantsToExit = userOutputClass.display(datumProcessed);;
userOutputClass.printKeypoints(datumProcessed);
}
// If OpenPose finished reading images
else if (!opWrapperT.isRunning())
break;
// Something else happened
else
op::log("Processed datum could not be emplaced.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__);
}
@@ -44,13 +44,13 @@ struct UserDatum : public op::Datum
// 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
// This worker will just read and return all the jpg files in a directory
// This worker will just read and return all the basic image file formats in a directory
class WUserInput : public op::WorkerProducer<std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>>
{
public:
WUserInput(const std::string& directoryPath) :
mImageFiles{op::getFilesOnDirectory(directoryPath, "jpg")},
// If we want "jpg" + "png" images
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}
{
@@ -22,6 +22,11 @@
// OpenPose dependencies
#include <openpose/headers.hpp>
// Custom OpenPose flags
// Display
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
@@ -100,12 +105,16 @@ public:
+ std::to_string(handHeatMaps[1].getSize(3)) + "]");
}
// Display rendered output image
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)
const char key = (char)cv::waitKey(1);
if (key == 27)
this->stop();
// Display results (if enabled)
if (!FLAGS_no_display)
{
// Display rendered output image
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)
const char key = (char)cv::waitKey(1);
if (key == 27)
this->stop();
}
}
}
catch (const std::exception& e)
@@ -26,6 +26,9 @@
// 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.");
// 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
@@ -44,13 +47,13 @@ struct UserDatum : public op::Datum
// 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
// This worker will just read and return all the jpg files in a directory
// This worker will just read and return all the basic image file formats in a directory
class WUserInput : public op::WorkerProducer<std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>>
{
public:
WUserInput(const std::string& directoryPath) :
mImageFiles{op::getFilesOnDirectory(directoryPath, "jpg")},
// If we want "jpg" + "png" images
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}
{
@@ -201,12 +204,16 @@ public:
+ std::to_string(handHeatMaps[1].getSize(3)) + "]");
}
// Display rendered output image
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)
const char key = (char)cv::waitKey(1);
if (key == 27)
this->stop();
// Display results (if enabled)
if (!FLAGS_no_display)
{
// Display rendered output image
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)
const char key = (char)cv::waitKey(1);
if (key == 27)
this->stop();
}
}
}
catch (const std::exception& e)