|
| 1 | +// ------------------------- OpenPose Library Tutorial - Hand Keypoint Detection from JSON Ground-Truth Data ------------------------- |
| 2 | +// Example to test hands accuracy given ground-truth bounding boxes. |
| 3 | + |
| 4 | +#include <chrono> // `std::chrono::` functions and classes, e.g. std::chrono::milliseconds |
| 5 | +#include <gflags/gflags.h> // DEFINE_bool, DEFINE_int32, DEFINE_int64, DEFINE_uint64, DEFINE_double, DEFINE_string |
| 6 | +#include <glog/logging.h> // google::InitGoogleLogging |
| 7 | +#include <openpose/headers.hpp> |
| 8 | +#include "wrapperHandFromJsonTest.hpp" |
| 9 | + |
| 10 | +// For info about the flags, check `examples/openpose/openpose.bin`. |
| 11 | +// Debugging |
| 12 | +DEFINE_int32(logging_level, 3, ""); |
| 13 | +// Producer |
| 14 | +DEFINE_string(image_dir, "", ""); |
| 15 | +DEFINE_string(hand_ground_truth, "", ""); |
| 16 | +// OpenPose |
| 17 | +DEFINE_string(model_folder, "models/", ""); |
| 18 | +DEFINE_int32(num_gpu, -1, ""); |
| 19 | +DEFINE_int32(num_gpu_start, 0, ""); |
| 20 | +// OpenPose Hand |
| 21 | +DEFINE_bool(hand, true, ""); |
| 22 | +DEFINE_string(hand_net_resolution, "368x368", ""); |
| 23 | +DEFINE_int32(hand_scale_number, 1, ""); |
| 24 | +DEFINE_double(hand_scale_range, 0.4, ""); |
| 25 | +DEFINE_bool(hand_tracking, false, ""); |
| 26 | +// Display |
| 27 | +DEFINE_bool(no_display, false, ""); |
| 28 | +// Result Saving |
| 29 | +DEFINE_string(write_keypoint_json, "", ""); |
| 30 | + |
| 31 | +int handFromJsonTest() |
| 32 | +{ |
| 33 | + // logging_level |
| 34 | + op::check(0 <= FLAGS_logging_level && FLAGS_logging_level <= 255, "Wrong logging_level value.", __LINE__, __FUNCTION__, __FILE__); |
| 35 | + op::ConfigureLog::setPriorityThreshold((op::Priority)FLAGS_logging_level); |
| 36 | + // op::ConfigureLog::setPriorityThreshold(op::Priority::None); // To print all logging messages |
| 37 | + |
| 38 | + op::log("Starting pose estimation demo.", op::Priority::High); |
| 39 | + const auto timerBegin = std::chrono::high_resolution_clock::now(); |
| 40 | + |
| 41 | + // Applying user defined configuration - Google flags to program variables |
| 42 | + // handNetInputSize |
| 43 | + const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)"); |
| 44 | + // producerType |
| 45 | + const auto producerSharedPtr = op::flagsToProducer(FLAGS_image_dir, "", 0); |
| 46 | + op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__); |
| 47 | + |
| 48 | + // OpenPose wrapper |
| 49 | + op::log("Configuring OpenPose wrapper.", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__); |
| 50 | + op::WrapperHandFromJsonTest<std::vector<op::Datum>> opWrapper; |
| 51 | + // Pose configuration (use WrapperStructPose{} for default and recommended configuration) |
| 52 | + op::WrapperStructPose wrapperStructPose{op::flagsToPoint("656x368"), op::flagsToPoint("1280x720"), |
| 53 | + op::ScaleMode::InputResolution, FLAGS_num_gpu, FLAGS_num_gpu_start}; |
| 54 | + wrapperStructPose.modelFolder = FLAGS_model_folder; |
| 55 | + // Hand configuration (use op::WrapperStructHand{} to disable it) |
| 56 | + const op::WrapperStructHand wrapperStructHand{FLAGS_hand, handNetInputSize, FLAGS_hand_scale_number, |
| 57 | + (float)FLAGS_hand_scale_range, FLAGS_hand_tracking, |
| 58 | + op::flagsToRenderMode(1)}; |
| 59 | + // Configure wrapper |
| 60 | + opWrapper.configure(wrapperStructPose, wrapperStructHand, producerSharedPtr, FLAGS_hand_ground_truth, FLAGS_write_keypoint_json, |
| 61 | + !FLAGS_no_display); |
| 62 | + |
| 63 | + // Start processing |
| 64 | + op::log("Starting thread(s)", op::Priority::High); |
| 65 | + opWrapper.exec(); // It blocks this thread until all threads have finished |
| 66 | + |
| 67 | + // Measuring total time |
| 68 | + const auto now = std::chrono::high_resolution_clock::now(); |
| 69 | + const auto totalTimeSec = (double)std::chrono::duration_cast<std::chrono::nanoseconds>(now-timerBegin).count() * 1e-9; |
| 70 | + const auto message = "Real-time pose estimation demo successfully finished. Total time: " + std::to_string(totalTimeSec) + " seconds."; |
| 71 | + op::log(message, op::Priority::High); |
| 72 | + |
| 73 | + return 0; |
| 74 | +} |
| 75 | + |
| 76 | +int main(int argc, char *argv[]) |
| 77 | +{ |
| 78 | + // Initializing google logging (Caffe uses it for logging) |
| 79 | + google::InitGoogleLogging("handFromJsonTest"); |
| 80 | + |
| 81 | + // Parsing command line flags |
| 82 | + gflags::ParseCommandLineFlags(&argc, &argv, true); |
| 83 | + |
| 84 | + // Running handFromJsonTest |
| 85 | + return handFromJsonTest(); |
| 86 | +} |
0 commit comments