|
|
|
|
|
|
|
|
|
#include <opencv2/opencv.hpp> |
|
|
|
#define OPENPOSE_FLAGS_DISABLE_POSE |
|
#include <openpose/flags.hpp> |
|
|
|
#include <openpose/headers.hpp> |
|
|
|
|
|
|
|
DEFINE_string(image_path, "examples/media/COCO_val2014_000000000192.jpg", |
|
"Process an image. Read all standard formats (jpg, png, bmp, etc.)."); |
|
|
|
DEFINE_bool(no_display, false, |
|
"Enable to disable the visual display."); |
|
|
|
|
|
void display(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>>& datumsPtr) |
|
{ |
|
try |
|
{ |
|
|
|
|
|
|
|
if (datumsPtr != nullptr && !datumsPtr->empty()) |
|
{ |
|
|
|
const cv::Mat cvMat = OP_OP2CVCONSTMAT(datumsPtr->at(0)->cvOutputData); |
|
if (!cvMat.empty()) |
|
{ |
|
cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); |
|
cv::waitKey(0); |
|
} |
|
else |
|
op::opLog("Empty cv::Mat as output.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); |
|
} |
|
else |
|
op::opLog("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 |
|
{ |
|
|
|
if (datumsPtr != nullptr && !datumsPtr->empty()) |
|
{ |
|
|
|
op::opLog("Body keypoints: " + datumsPtr->at(0)->poseKeypoints.toString(), op::Priority::High); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
else |
|
op::opLog("Nullptr or empty datumsPtr found.", op::Priority::High); |
|
} |
|
catch (const std::exception& e) |
|
{ |
|
op::error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
|
} |
|
} |
|
|
|
int tutorialApiCpp() |
|
{ |
|
try |
|
{ |
|
op::opLog("Starting OpenPose demo...", op::Priority::High); |
|
const auto opTimer = op::getTimerInit(); |
|
|
|
|
|
op::opLog("Configuring OpenPose...", op::Priority::High); |
|
op::Wrapper opWrapper{op::ThreadManagerMode::Asynchronous}; |
|
|
|
if (FLAGS_disable_multi_thread) |
|
opWrapper.disableMultiThreading(); |
|
|
|
|
|
op::opLog("Starting thread(s)...", op::Priority::High); |
|
opWrapper.start(); |
|
|
|
|
|
const cv::Mat cvImageToProcess = cv::imread(FLAGS_image_path); |
|
const op::Matrix imageToProcess = OP_CV2OPCONSTMAT(cvImageToProcess); |
|
auto datumProcessed = opWrapper.emplaceAndPop(imageToProcess); |
|
if (datumProcessed != nullptr) |
|
{ |
|
printKeypoints(datumProcessed); |
|
if (!FLAGS_no_display) |
|
display(datumProcessed); |
|
} |
|
else |
|
op::opLog("Image could not be processed.", op::Priority::High); |
|
|
|
|
|
op::printTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", op::Priority::High); |
|
|
|
|
|
return 0; |
|
} |
|
catch (const std::exception&) |
|
{ |
|
return -1; |
|
} |
|
} |
|
|
|
int main(int argc, char *argv[]) |
|
{ |
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, true); |
|
|
|
|
|
return tutorialApiCpp(); |
|
} |
|
|