mirror of
https://github.com/gosticks/openpose.git
synced 2026-08-12 20:30:20 +00:00
Wrapper template simplified
This commit is contained in:
@@ -13,7 +13,7 @@ DEFINE_string(image_path, "examples/media/COCO_val2014_000000000192.jpg",
|
||||
"Process an image. Read all standard formats (jpg, png, bmp, etc.).");
|
||||
|
||||
// This worker will just read and return all the jpg files in a directory
|
||||
void display(const std::shared_ptr<std::vector<op::Datum>>& datumsPtr)
|
||||
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
|
||||
@@ -21,20 +21,20 @@ void display(const std::shared_ptr<std::vector<op::Datum>>& datumsPtr)
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
// Display image
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData);
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData);
|
||||
cv::waitKey(0);
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
}
|
||||
|
||||
void printKeypoints(const std::shared_ptr<std::vector<op::Datum>>& 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())
|
||||
{
|
||||
// Alternative 1
|
||||
op::log("Body keypoints: " + datumsPtr->at(0).poseKeypoints.toString());
|
||||
op::log("Body keypoints: " + datumsPtr->at(0)->poseKeypoints.toString());
|
||||
|
||||
// // Alternative 2
|
||||
// op::log(datumsPtr->at(0).poseKeypoints);
|
||||
|
||||
@@ -13,7 +13,7 @@ DEFINE_string(image_path, "examples/media/COCO_val2014_000000000241.jpg",
|
||||
"Process an image. Read all standard formats (jpg, png, bmp, etc.).");
|
||||
|
||||
// This worker will just read and return all the jpg files in a directory
|
||||
void display(const std::shared_ptr<std::vector<op::Datum>>& datumsPtr)
|
||||
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
|
||||
@@ -21,22 +21,22 @@ void display(const std::shared_ptr<std::vector<op::Datum>>& datumsPtr)
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
// Display image
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData);
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData);
|
||||
cv::waitKey(0);
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
}
|
||||
|
||||
void printKeypoints(const std::shared_ptr<std::vector<op::Datum>>& 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())
|
||||
{
|
||||
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());
|
||||
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);
|
||||
|
||||
@@ -15,7 +15,7 @@ DEFINE_string(image_path, "examples/media/COCO_val2014_000000000294.jpg",
|
||||
"Process an image. Read all standard formats (jpg, png, bmp, etc.).");
|
||||
|
||||
// This worker will just read and return all the jpg files in a directory
|
||||
void display(const std::shared_ptr<std::vector<op::Datum>>& datumsPtr)
|
||||
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
|
||||
@@ -23,22 +23,22 @@ void display(const std::shared_ptr<std::vector<op::Datum>>& datumsPtr)
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
// Display image
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData);
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0)->cvOutputData);
|
||||
cv::waitKey(0);
|
||||
}
|
||||
else
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High);
|
||||
}
|
||||
|
||||
void printKeypoints(const std::shared_ptr<std::vector<op::Datum>>& 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())
|
||||
{
|
||||
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());
|
||||
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);
|
||||
|
||||
@@ -29,7 +29,8 @@ DEFINE_string(image_dir, "examples/media/",
|
||||
|
||||
// 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<UserDatum>> instead of Wrapper (or equivalently WrapperT<std::vector<UserDatum>>)
|
||||
// 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;
|
||||
@@ -58,7 +59,7 @@ public:
|
||||
op::error("No images found on: " + directoryPath, __LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
std::shared_ptr<std::vector<UserDatum>> createDatum()
|
||||
std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>> createDatum()
|
||||
{
|
||||
// Close program when empty frame
|
||||
if (mClosed || mImageFiles.size() <= mCounter)
|
||||
@@ -72,15 +73,15 @@ public:
|
||||
else // if (!mClosed)
|
||||
{
|
||||
// Create new datum
|
||||
auto datumsPtr = std::make_shared<std::vector<UserDatum>>();
|
||||
auto datumsPtr = std::make_shared<std::vector<std::shared_ptr<UserDatum>>>();
|
||||
datumsPtr->emplace_back();
|
||||
auto& datum = datumsPtr->at(0);
|
||||
auto& datumPtr = datumsPtr->at(0);
|
||||
|
||||
// Fill datum
|
||||
datum.cvInputData = cv::imread(mImageFiles.at(mCounter++));
|
||||
datumPtr->cvInputData = cv::imread(mImageFiles.at(mCounter++));
|
||||
|
||||
// If empty frame -> return nullptr
|
||||
if (datum.cvInputData.empty())
|
||||
if (datumPtr->cvInputData.empty())
|
||||
{
|
||||
op::log("Empty frame detected on path: " + mImageFiles.at(mCounter-1) + ". Closing program.",
|
||||
op::Priority::High);
|
||||
@@ -107,15 +108,15 @@ private:
|
||||
class UserOutputClass
|
||||
{
|
||||
public:
|
||||
bool display(const std::shared_ptr<std::vector<UserDatum>>& datumsPtr)
|
||||
bool display(const std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>& datumsPtr)
|
||||
{
|
||||
// User's displaying/saving/other processing here
|
||||
// datum.cvOutputData: rendered frame with pose or heatmaps
|
||||
// datum.poseKeypoints: Array<float> with the estimated pose
|
||||
// datumPtr->cvOutputData: rendered frame with pose or heatmaps
|
||||
// datumPtr->poseKeypoints: Array<float> with the estimated pose
|
||||
char key = ' ';
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData);
|
||||
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);
|
||||
}
|
||||
@@ -123,14 +124,14 @@ public:
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__);
|
||||
return (key == 27);
|
||||
}
|
||||
void printKeypoints(const std::shared_ptr<std::vector<UserDatum>>& datumsPtr)
|
||||
void printKeypoints(const std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>& datumsPtr)
|
||||
{
|
||||
// Example: How to use the pose keypoints
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
op::log("\nKeypoints:");
|
||||
// Accesing each element of the keypoints
|
||||
const auto& poseKeypoints = datumsPtr->at(0).poseKeypoints;
|
||||
const auto& poseKeypoints = datumsPtr->at(0)->poseKeypoints;
|
||||
op::log("Person pose keypoints:");
|
||||
for (auto person = 0 ; person < poseKeypoints.getSize(0) ; person++)
|
||||
{
|
||||
@@ -145,22 +146,22 @@ public:
|
||||
}
|
||||
op::log(" ");
|
||||
// Alternative: just getting std::string equivalent
|
||||
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());
|
||||
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());
|
||||
// Heatmaps
|
||||
const auto& poseHeatMaps = datumsPtr->at(0).poseHeatMaps;
|
||||
const auto& poseHeatMaps = datumsPtr->at(0)->poseHeatMaps;
|
||||
if (!poseHeatMaps.empty())
|
||||
{
|
||||
op::log("Pose heatmaps size: [" + std::to_string(poseHeatMaps.getSize(0)) + ", "
|
||||
+ std::to_string(poseHeatMaps.getSize(1)) + ", "
|
||||
+ std::to_string(poseHeatMaps.getSize(2)) + "]");
|
||||
const auto& faceHeatMaps = datumsPtr->at(0).faceHeatMaps;
|
||||
const auto& faceHeatMaps = datumsPtr->at(0)->faceHeatMaps;
|
||||
op::log("Face heatmaps size: [" + std::to_string(faceHeatMaps.getSize(0)) + ", "
|
||||
+ std::to_string(faceHeatMaps.getSize(1)) + ", "
|
||||
+ std::to_string(faceHeatMaps.getSize(2)) + ", "
|
||||
+ std::to_string(faceHeatMaps.getSize(3)) + "]");
|
||||
const auto& handHeatMaps = datumsPtr->at(0).handHeatMaps;
|
||||
const auto& handHeatMaps = datumsPtr->at(0)->handHeatMaps;
|
||||
op::log("Left hand heatmaps size: [" + std::to_string(handHeatMaps[0].getSize(0)) + ", "
|
||||
+ std::to_string(handHeatMaps[0].getSize(1)) + ", "
|
||||
+ std::to_string(handHeatMaps[0].getSize(2)) + ", "
|
||||
@@ -217,7 +218,7 @@ int tutorialApiCpp4()
|
||||
|
||||
// Configuring OpenPose
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::WrapperT<std::vector<UserDatum>> opWrapperT{op::ThreadManagerMode::Asynchronous};
|
||||
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, keypointScale, FLAGS_num_gpu, FLAGS_num_gpu_start,
|
||||
@@ -271,7 +272,7 @@ int tutorialApiCpp4()
|
||||
{
|
||||
auto successfullyEmplaced = opWrapperT.waitAndEmplace(datumToProcess);
|
||||
// Pop frame
|
||||
std::shared_ptr<std::vector<UserDatum>> datumProcessed;
|
||||
std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>> datumProcessed;
|
||||
if (successfullyEmplaced && opWrapperT.waitAndPop(datumProcessed))
|
||||
{
|
||||
userWantsToExit = userOutputClass.display(datumProcessed);
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
|
||||
// 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<UserDatum>> instead of Wrapper (or equivalently WrapperT<std::vector<UserDatum>>)
|
||||
// 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;
|
||||
@@ -41,15 +42,15 @@ struct UserDatum : public op::Datum
|
||||
class UserOutputClass
|
||||
{
|
||||
public:
|
||||
bool display(const std::shared_ptr<std::vector<UserDatum>>& datumsPtr)
|
||||
bool display(const std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>& datumsPtr)
|
||||
{
|
||||
// User's displaying/saving/other processing here
|
||||
// datum.cvOutputData: rendered frame with pose or heatmaps
|
||||
// datum.poseKeypoints: Array<float> with the estimated pose
|
||||
// datumPtr->cvOutputData: rendered frame with pose or heatmaps
|
||||
// datumPtr->poseKeypoints: Array<float> with the estimated pose
|
||||
char key = ' ';
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData);
|
||||
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);
|
||||
}
|
||||
@@ -57,14 +58,14 @@ public:
|
||||
op::log("Nullptr or empty datumsPtr found.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__);
|
||||
return (key == 27);
|
||||
}
|
||||
void printKeypoints(const std::shared_ptr<std::vector<UserDatum>>& datumsPtr)
|
||||
void printKeypoints(const std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>& datumsPtr)
|
||||
{
|
||||
// Example: How to use the pose keypoints
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
op::log("\nKeypoints:");
|
||||
// Accesing each element of the keypoints
|
||||
const auto& poseKeypoints = datumsPtr->at(0).poseKeypoints;
|
||||
const auto& poseKeypoints = datumsPtr->at(0)->poseKeypoints;
|
||||
op::log("Person pose keypoints:");
|
||||
for (auto person = 0 ; person < poseKeypoints.getSize(0) ; person++)
|
||||
{
|
||||
@@ -81,22 +82,22 @@ public:
|
||||
}
|
||||
op::log(" ");
|
||||
// Alternative: just getting std::string equivalent
|
||||
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());
|
||||
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());
|
||||
// Heatmaps
|
||||
const auto& poseHeatMaps = datumsPtr->at(0).poseHeatMaps;
|
||||
const auto& poseHeatMaps = datumsPtr->at(0)->poseHeatMaps;
|
||||
if (!poseHeatMaps.empty())
|
||||
{
|
||||
op::log("Pose heatmaps size: [" + std::to_string(poseHeatMaps.getSize(0)) + ", "
|
||||
+ std::to_string(poseHeatMaps.getSize(1)) + ", "
|
||||
+ std::to_string(poseHeatMaps.getSize(2)) + "]");
|
||||
const auto& faceHeatMaps = datumsPtr->at(0).faceHeatMaps;
|
||||
const auto& faceHeatMaps = datumsPtr->at(0)->faceHeatMaps;
|
||||
op::log("Face heatmaps size: [" + std::to_string(faceHeatMaps.getSize(0)) + ", "
|
||||
+ std::to_string(faceHeatMaps.getSize(1)) + ", "
|
||||
+ std::to_string(faceHeatMaps.getSize(2)) + ", "
|
||||
+ std::to_string(faceHeatMaps.getSize(3)) + "]");
|
||||
const auto& handHeatMaps = datumsPtr->at(0).handHeatMaps;
|
||||
const auto& handHeatMaps = datumsPtr->at(0)->handHeatMaps;
|
||||
op::log("Left hand heatmaps size: [" + std::to_string(handHeatMaps[0].getSize(0)) + ", "
|
||||
+ std::to_string(handHeatMaps[0].getSize(1)) + ", "
|
||||
+ std::to_string(handHeatMaps[0].getSize(2)) + ", "
|
||||
@@ -160,7 +161,7 @@ int tutorialApiCpp5()
|
||||
|
||||
// Configuring OpenPose
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::WrapperT<std::vector<UserDatum>> opWrapperT{op::ThreadManagerMode::AsynchronousOut};
|
||||
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, keypointScale, FLAGS_num_gpu, FLAGS_num_gpu_start,
|
||||
@@ -214,7 +215,7 @@ int tutorialApiCpp5()
|
||||
while (!userWantsToExit)
|
||||
{
|
||||
// Pop frame
|
||||
std::shared_ptr<std::vector<UserDatum>> datumProcessed;
|
||||
std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>> datumProcessed;
|
||||
if (opWrapperT.waitAndPop(datumProcessed))
|
||||
{
|
||||
userWantsToExit = userOutputClass.display(datumProcessed);;
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
|
||||
// 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<UserDatum>> instead of Wrapper (or equivalently WrapperT<std::vector<UserDatum>>)
|
||||
// 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;
|
||||
@@ -38,7 +39,7 @@ struct UserDatum : public op::Datum
|
||||
// in this case we assume a std::shared_ptr of a std::vector of UserDatum
|
||||
|
||||
// This worker will just invert the image
|
||||
class WUserPostProcessing : public op::Worker<std::shared_ptr<std::vector<UserDatum>>>
|
||||
class WUserPostProcessing : public op::Worker<std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>>
|
||||
{
|
||||
public:
|
||||
WUserPostProcessing()
|
||||
@@ -48,16 +49,16 @@ public:
|
||||
|
||||
void initializationOnThread() {}
|
||||
|
||||
void work(std::shared_ptr<std::vector<UserDatum>>& datumsPtr)
|
||||
void work(std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>& datumsPtr)
|
||||
{
|
||||
// User's post-processing (after OpenPose processing & before OpenPose outputs) here
|
||||
// datum.cvOutputData: rendered frame with pose or heatmaps
|
||||
// datum.poseKeypoints: Array<float> with the estimated pose
|
||||
// datumPtr->cvOutputData: rendered frame with pose or heatmaps
|
||||
// datumPtr->poseKeypoints: Array<float> with the estimated pose
|
||||
try
|
||||
{
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
for (auto& datum : *datumsPtr)
|
||||
cv::bitwise_not(datum.cvOutputData, datum.cvOutputData);
|
||||
for (auto& datumPtr : *datumsPtr)
|
||||
cv::bitwise_not(datumPtr->cvOutputData, datumPtr->cvOutputData);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
@@ -120,7 +121,7 @@ int tutorialApiCpp6()
|
||||
|
||||
// OpenPose wrapper
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::WrapperT<std::vector<UserDatum>> opWrapperT;
|
||||
op::WrapperT<UserDatum> opWrapperT;
|
||||
|
||||
// Initializing the user custom classes
|
||||
// Processing
|
||||
|
||||
@@ -29,7 +29,8 @@ DEFINE_string(image_dir, "examples/media/",
|
||||
|
||||
// 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<UserDatum>> instead of Wrapper (or equivalently WrapperT<std::vector<UserDatum>>)
|
||||
// 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;
|
||||
@@ -44,7 +45,7 @@ struct UserDatum : public op::Datum
|
||||
// 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
|
||||
class WUserInput : public op::WorkerProducer<std::shared_ptr<std::vector<UserDatum>>>
|
||||
class WUserInput : public op::WorkerProducer<std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>>
|
||||
{
|
||||
public:
|
||||
WUserInput(const std::string& directoryPath) :
|
||||
@@ -59,7 +60,7 @@ public:
|
||||
|
||||
void initializationOnThread() {}
|
||||
|
||||
std::shared_ptr<std::vector<UserDatum>> workProducer()
|
||||
std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>> workProducer()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -76,15 +77,15 @@ public:
|
||||
else
|
||||
{
|
||||
// Create new datum
|
||||
auto datumsPtr = std::make_shared<std::vector<UserDatum>>();
|
||||
auto datumsPtr = std::make_shared<std::vector<std::shared_ptr<UserDatum>>>();
|
||||
datumsPtr->emplace_back();
|
||||
auto& datum = datumsPtr->at(0);
|
||||
auto& datumPtr = datumsPtr->at(0);
|
||||
|
||||
// Fill datum
|
||||
datum.cvInputData = cv::imread(mImageFiles.at(mCounter++));
|
||||
datumPtr->cvInputData = cv::imread(mImageFiles.at(mCounter++));
|
||||
|
||||
// If empty frame -> return nullptr
|
||||
if (datum.cvInputData.empty())
|
||||
if (datumPtr->cvInputData.empty())
|
||||
{
|
||||
op::log("Empty frame detected on path: " + mImageFiles.at(mCounter-1) + ". Closing program.",
|
||||
op::Priority::High);
|
||||
@@ -155,7 +156,7 @@ int tutorialApiCpp7()
|
||||
|
||||
// OpenPose wrapper
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::WrapperT<std::vector<UserDatum>> opWrapperT;
|
||||
op::WrapperT<UserDatum> opWrapperT;
|
||||
|
||||
// Initializing the user custom classes
|
||||
// Frames producer (e.g., video, webcam, ...)
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
|
||||
// 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<UserDatum>> instead of Wrapper (or equivalently WrapperT<std::vector<UserDatum>>)
|
||||
// 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;
|
||||
@@ -39,24 +40,24 @@ struct UserDatum : public op::Datum
|
||||
// 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
|
||||
class WUserOutput : public op::WorkerConsumer<std::shared_ptr<std::vector<UserDatum>>>
|
||||
class WUserOutput : public op::WorkerConsumer<std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>>
|
||||
{
|
||||
public:
|
||||
void initializationOnThread() {}
|
||||
|
||||
void workConsumer(const std::shared_ptr<std::vector<UserDatum>>& datumsPtr)
|
||||
void workConsumer(const std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>& 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
|
||||
// datumPtr->cvOutputData: rendered frame with pose or heatmaps
|
||||
// datumPtr->poseKeypoints: Array<float> with the estimated pose
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
// Show in command line the resulting pose keypoints for body, face and hands
|
||||
op::log("\nKeypoints:");
|
||||
// Accesing each element of the keypoints
|
||||
const auto& poseKeypoints = datumsPtr->at(0).poseKeypoints;
|
||||
const auto& poseKeypoints = datumsPtr->at(0)->poseKeypoints;
|
||||
op::log("Person pose keypoints:");
|
||||
for (auto person = 0 ; person < poseKeypoints.getSize(0) ; person++)
|
||||
{
|
||||
@@ -73,22 +74,22 @@ public:
|
||||
}
|
||||
op::log(" ");
|
||||
// Alternative: just getting std::string equivalent
|
||||
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());
|
||||
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());
|
||||
// Heatmaps
|
||||
const auto& poseHeatMaps = datumsPtr->at(0).poseHeatMaps;
|
||||
const auto& poseHeatMaps = datumsPtr->at(0)->poseHeatMaps;
|
||||
if (!poseHeatMaps.empty())
|
||||
{
|
||||
op::log("Pose heatmaps size: [" + std::to_string(poseHeatMaps.getSize(0)) + ", "
|
||||
+ std::to_string(poseHeatMaps.getSize(1)) + ", "
|
||||
+ std::to_string(poseHeatMaps.getSize(2)) + "]");
|
||||
const auto& faceHeatMaps = datumsPtr->at(0).faceHeatMaps;
|
||||
const auto& faceHeatMaps = datumsPtr->at(0)->faceHeatMaps;
|
||||
op::log("Face heatmaps size: [" + std::to_string(faceHeatMaps.getSize(0)) + ", "
|
||||
+ std::to_string(faceHeatMaps.getSize(1)) + ", "
|
||||
+ std::to_string(faceHeatMaps.getSize(2)) + ", "
|
||||
+ std::to_string(faceHeatMaps.getSize(3)) + "]");
|
||||
const auto& handHeatMaps = datumsPtr->at(0).handHeatMaps;
|
||||
const auto& handHeatMaps = datumsPtr->at(0)->handHeatMaps;
|
||||
op::log("Left hand heatmaps size: [" + std::to_string(handHeatMaps[0].getSize(0)) + ", "
|
||||
+ std::to_string(handHeatMaps[0].getSize(1)) + ", "
|
||||
+ std::to_string(handHeatMaps[0].getSize(2)) + ", "
|
||||
@@ -100,7 +101,7 @@ public:
|
||||
}
|
||||
|
||||
// Display rendered output image
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData);
|
||||
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)
|
||||
@@ -168,7 +169,7 @@ int tutorialApiCpp8()
|
||||
|
||||
// OpenPose wrapper
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::WrapperT<std::vector<UserDatum>> opWrapperT;
|
||||
op::WrapperT<UserDatum> opWrapperT;
|
||||
|
||||
// Initializing the user custom classes
|
||||
// GUI (Display)
|
||||
|
||||
@@ -29,7 +29,8 @@ DEFINE_string(image_dir, "examples/media/",
|
||||
|
||||
// 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<UserDatum>> instead of Wrapper (or equivalently WrapperT<std::vector<UserDatum>>)
|
||||
// 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;
|
||||
@@ -44,7 +45,7 @@ struct UserDatum : public op::Datum
|
||||
// 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
|
||||
class WUserInput : public op::WorkerProducer<std::shared_ptr<std::vector<UserDatum>>>
|
||||
class WUserInput : public op::WorkerProducer<std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>>
|
||||
{
|
||||
public:
|
||||
WUserInput(const std::string& directoryPath) :
|
||||
@@ -59,7 +60,7 @@ public:
|
||||
|
||||
void initializationOnThread() {}
|
||||
|
||||
std::shared_ptr<std::vector<UserDatum>> workProducer()
|
||||
std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>> workProducer()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -76,15 +77,15 @@ public:
|
||||
else
|
||||
{
|
||||
// Create new datum
|
||||
auto datumsPtr = std::make_shared<std::vector<UserDatum>>();
|
||||
auto datumsPtr = std::make_shared<std::vector<std::shared_ptr<UserDatum>>>();
|
||||
datumsPtr->emplace_back();
|
||||
auto& datum = datumsPtr->at(0);
|
||||
auto& datumPtr = datumsPtr->at(0);
|
||||
|
||||
// Fill datum
|
||||
datum.cvInputData = cv::imread(mImageFiles.at(mCounter++));
|
||||
datumPtr->cvInputData = cv::imread(mImageFiles.at(mCounter++));
|
||||
|
||||
// If empty frame -> return nullptr
|
||||
if (datum.cvInputData.empty())
|
||||
if (datumPtr->cvInputData.empty())
|
||||
{
|
||||
op::log("Empty frame detected on path: " + mImageFiles.at(mCounter-1) + ". Closing program.",
|
||||
op::Priority::High);
|
||||
@@ -109,7 +110,7 @@ private:
|
||||
};
|
||||
|
||||
// This worker will just invert the image
|
||||
class WUserPostProcessing : public op::Worker<std::shared_ptr<std::vector<UserDatum>>>
|
||||
class WUserPostProcessing : public op::Worker<std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>>
|
||||
{
|
||||
public:
|
||||
WUserPostProcessing()
|
||||
@@ -119,16 +120,16 @@ public:
|
||||
|
||||
void initializationOnThread() {}
|
||||
|
||||
void work(std::shared_ptr<std::vector<UserDatum>>& datumsPtr)
|
||||
void work(std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>& datumsPtr)
|
||||
{
|
||||
// User's post-processing (after OpenPose processing & before OpenPose outputs) here
|
||||
// datum.cvOutputData: rendered frame with pose or heatmaps
|
||||
// datum.poseKeypoints: Array<float> with the estimated pose
|
||||
// datumPtr->cvOutputData: rendered frame with pose or heatmaps
|
||||
// datumPtr->poseKeypoints: Array<float> with the estimated pose
|
||||
try
|
||||
{
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
for (auto& datum : *datumsPtr)
|
||||
cv::bitwise_not(datum.cvOutputData, datum.cvOutputData);
|
||||
for (auto& datumPtr : *datumsPtr)
|
||||
cv::bitwise_not(datumPtr->cvOutputData, datumPtr->cvOutputData);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
@@ -139,24 +140,24 @@ public:
|
||||
};
|
||||
|
||||
// This worker will just read and return all the jpg files in a directory
|
||||
class WUserOutput : public op::WorkerConsumer<std::shared_ptr<std::vector<UserDatum>>>
|
||||
class WUserOutput : public op::WorkerConsumer<std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>>
|
||||
{
|
||||
public:
|
||||
void initializationOnThread() {}
|
||||
|
||||
void workConsumer(const std::shared_ptr<std::vector<UserDatum>>& datumsPtr)
|
||||
void workConsumer(const std::shared_ptr<std::vector<std::shared_ptr<UserDatum>>>& 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
|
||||
// datumPtr->cvOutputData: rendered frame with pose or heatmaps
|
||||
// datumPtr->poseKeypoints: Array<float> with the estimated pose
|
||||
if (datumsPtr != nullptr && !datumsPtr->empty())
|
||||
{
|
||||
// Show in command line the resulting pose keypoints for body, face and hands
|
||||
op::log("\nKeypoints:");
|
||||
// Accesing each element of the keypoints
|
||||
const auto& poseKeypoints = datumsPtr->at(0).poseKeypoints;
|
||||
const auto& poseKeypoints = datumsPtr->at(0)->poseKeypoints;
|
||||
op::log("Person pose keypoints:");
|
||||
for (auto person = 0 ; person < poseKeypoints.getSize(0) ; person++)
|
||||
{
|
||||
@@ -173,22 +174,22 @@ public:
|
||||
}
|
||||
op::log(" ");
|
||||
// Alternative: just getting std::string equivalent
|
||||
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());
|
||||
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());
|
||||
// Heatmaps
|
||||
const auto& poseHeatMaps = datumsPtr->at(0).poseHeatMaps;
|
||||
const auto& poseHeatMaps = datumsPtr->at(0)->poseHeatMaps;
|
||||
if (!poseHeatMaps.empty())
|
||||
{
|
||||
op::log("Pose heatmaps size: [" + std::to_string(poseHeatMaps.getSize(0)) + ", "
|
||||
+ std::to_string(poseHeatMaps.getSize(1)) + ", "
|
||||
+ std::to_string(poseHeatMaps.getSize(2)) + "]");
|
||||
const auto& faceHeatMaps = datumsPtr->at(0).faceHeatMaps;
|
||||
const auto& faceHeatMaps = datumsPtr->at(0)->faceHeatMaps;
|
||||
op::log("Face heatmaps size: [" + std::to_string(faceHeatMaps.getSize(0)) + ", "
|
||||
+ std::to_string(faceHeatMaps.getSize(1)) + ", "
|
||||
+ std::to_string(faceHeatMaps.getSize(2)) + ", "
|
||||
+ std::to_string(faceHeatMaps.getSize(3)) + "]");
|
||||
const auto& handHeatMaps = datumsPtr->at(0).handHeatMaps;
|
||||
const auto& handHeatMaps = datumsPtr->at(0)->handHeatMaps;
|
||||
op::log("Left hand heatmaps size: [" + std::to_string(handHeatMaps[0].getSize(0)) + ", "
|
||||
+ std::to_string(handHeatMaps[0].getSize(1)) + ", "
|
||||
+ std::to_string(handHeatMaps[0].getSize(2)) + ", "
|
||||
@@ -200,7 +201,7 @@ public:
|
||||
}
|
||||
|
||||
// Display rendered output image
|
||||
cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData);
|
||||
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)
|
||||
@@ -264,7 +265,7 @@ int tutorialApiCpp9()
|
||||
|
||||
// OpenPose wrapper
|
||||
op::log("Configuring OpenPose...", op::Priority::High);
|
||||
op::WrapperT<std::vector<UserDatum>> opWrapperT;
|
||||
op::WrapperT<UserDatum> opWrapperT;
|
||||
// Add custom input
|
||||
const auto workerInputOnNewThread = false;
|
||||
opWrapperT.setWorker(op::WorkerType::Input, wUserInput, workerInputOnNewThread);
|
||||
|
||||
Reference in New Issue
Block a user