Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

openpose.cpp 8.3 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
  1. // ------------------------------------------------ OpenPose C++ Demo ------------------------------------------------
  2. // This example summarizes all the functionality of the OpenPose library. It can...
  3. // 1. Read a frames source (images, video, webcam, 3D stereo Flir cameras, etc.).
  4. // 2. Extract and render body/hand/face/foot keypoint/heatmap/PAF of that image.
  5. // 3. Save the results on disk.
  6. // 4. Display the rendered pose.
  7. // If the user wants to learn to use the OpenPose C++ library, we highly recommend to start with the examples in
  8. // `examples/tutorial_api_cpp/`.
  9. // Command-line user interface
  10. #include <openpose/flags.hpp>
  11. // OpenPose dependencies
  12. #include <openpose/headers.hpp>
  13. void configureWrapper(op::Wrapper& opWrapper)
  14. {
  15. try
  16. {
  17. // Configuring OpenPose
  18. // logging_level
  19. op::checkBool(
  20. 0 <= FLAGS_logging_level && FLAGS_logging_level <= 255, "Wrong logging_level value.",
  21. __LINE__, __FUNCTION__, __FILE__);
  22. op::ConfigureLog::setPriorityThreshold((op::Priority)FLAGS_logging_level);
  23. op::Profiler::setDefaultX(FLAGS_profile_speed);
  24. // Applying user defined configuration - GFlags to program variables
  25. // producerType
  26. op::ProducerType producerType;
  27. op::String producerString;
  28. std::tie(producerType, producerString) = op::flagsToProducer(
  29. op::String(FLAGS_image_dir), op::String(FLAGS_video), op::String(FLAGS_ip_camera), FLAGS_camera,
  30. FLAGS_flir_camera, FLAGS_flir_camera_index);
  31. // cameraSize
  32. const auto cameraSize = op::flagsToPoint(op::String(FLAGS_camera_resolution), "-1x-1");
  33. // outputSize
  34. const auto outputSize = op::flagsToPoint(op::String(FLAGS_output_resolution), "-1x-1");
  35. // netInputSize
  36. const auto netInputSize = op::flagsToPoint(op::String(FLAGS_net_resolution), "-1x368");
  37. // faceNetInputSize
  38. const auto faceNetInputSize = op::flagsToPoint(op::String(FLAGS_face_net_resolution), "368x368 (multiples of 16)");
  39. // handNetInputSize
  40. const auto handNetInputSize = op::flagsToPoint(op::String(FLAGS_hand_net_resolution), "368x368 (multiples of 16)");
  41. // poseMode
  42. const auto poseMode = op::flagsToPoseMode(FLAGS_body);
  43. // poseModel
  44. const auto poseModel = op::flagsToPoseModel(op::String(FLAGS_model_pose));
  45. // JSON saving
  46. if (!FLAGS_write_keypoint.empty())
  47. op::opLog(
  48. "Flag `write_keypoint` is deprecated and will eventually be removed. Please, use `write_json`"
  49. " instead.", op::Priority::Max);
  50. // keypointScaleMode
  51. const auto keypointScaleMode = op::flagsToScaleMode(FLAGS_keypoint_scale);
  52. // heatmaps to add
  53. const auto heatMapTypes = op::flagsToHeatMaps(FLAGS_heatmaps_add_parts, FLAGS_heatmaps_add_bkg,
  54. FLAGS_heatmaps_add_PAFs);
  55. const auto heatMapScaleMode = op::flagsToHeatMapScaleMode(FLAGS_heatmaps_scale);
  56. // >1 camera view?
  57. const auto multipleView = (FLAGS_3d || FLAGS_3d_views > 1 || FLAGS_flir_camera);
  58. // Face and hand detectors
  59. const auto faceDetector = op::flagsToDetector(FLAGS_face_detector);
  60. const auto handDetector = op::flagsToDetector(FLAGS_hand_detector);
  61. // Enabling Google Logging
  62. const bool enableGoogleLogging = true;
  63. // Pose configuration (use WrapperStructPose{} for default and recommended configuration)
  64. const op::WrapperStructPose wrapperStructPose{
  65. poseMode, netInputSize, outputSize, keypointScaleMode, FLAGS_num_gpu, FLAGS_num_gpu_start,
  66. FLAGS_scale_number, (float)FLAGS_scale_gap, op::flagsToRenderMode(FLAGS_render_pose, multipleView),
  67. poseModel, !FLAGS_disable_blending, (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap,
  68. FLAGS_part_to_show, op::String(FLAGS_model_folder), heatMapTypes, heatMapScaleMode, FLAGS_part_candidates,
  69. (float)FLAGS_render_threshold, FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max,
  70. op::String(FLAGS_prototxt_path), op::String(FLAGS_caffemodel_path),
  71. (float)FLAGS_upsampling_ratio, enableGoogleLogging};
  72. opWrapper.configure(wrapperStructPose);
  73. // Face configuration (use op::WrapperStructFace{} to disable it)
  74. const op::WrapperStructFace wrapperStructFace{
  75. FLAGS_face, faceDetector, faceNetInputSize,
  76. op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
  77. (float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
  78. opWrapper.configure(wrapperStructFace);
  79. // Hand configuration (use op::WrapperStructHand{} to disable it)
  80. const op::WrapperStructHand wrapperStructHand{
  81. FLAGS_hand, handDetector, handNetInputSize, FLAGS_hand_scale_number, (float)FLAGS_hand_scale_range,
  82. op::flagsToRenderMode(FLAGS_hand_render, multipleView, FLAGS_render_pose), (float)FLAGS_hand_alpha_pose,
  83. (float)FLAGS_hand_alpha_heatmap, (float)FLAGS_hand_render_threshold};
  84. opWrapper.configure(wrapperStructHand);
  85. // Extra functionality configuration (use op::WrapperStructExtra{} to disable it)
  86. const op::WrapperStructExtra wrapperStructExtra{
  87. FLAGS_3d, FLAGS_3d_min_views, FLAGS_identification, FLAGS_tracking, FLAGS_ik_threads};
  88. opWrapper.configure(wrapperStructExtra);
  89. // Producer (use default to disable any input)
  90. const op::WrapperStructInput wrapperStructInput{
  91. producerType, producerString, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last,
  92. FLAGS_process_real_time, FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat,
  93. cameraSize, op::String(FLAGS_camera_parameter_path), FLAGS_frame_undistort, FLAGS_3d_views};
  94. opWrapper.configure(wrapperStructInput);
  95. // Output (comment or use default argument to disable any output)
  96. const op::WrapperStructOutput wrapperStructOutput{
  97. FLAGS_cli_verbose, op::String(FLAGS_write_keypoint), op::stringToDataFormat(FLAGS_write_keypoint_format),
  98. op::String(FLAGS_write_json), op::String(FLAGS_write_coco_json), FLAGS_write_coco_json_variants,
  99. FLAGS_write_coco_json_variant, op::String(FLAGS_write_images), op::String(FLAGS_write_images_format),
  100. op::String(FLAGS_write_video), FLAGS_write_video_fps, FLAGS_write_video_with_audio,
  101. op::String(FLAGS_write_heatmaps), op::String(FLAGS_write_heatmaps_format), op::String(FLAGS_write_video_3d),
  102. op::String(FLAGS_write_video_adam), op::String(FLAGS_write_bvh), op::String(FLAGS_udp_host),
  103. op::String(FLAGS_udp_port)};
  104. opWrapper.configure(wrapperStructOutput);
  105. // GUI (comment or use default argument to disable any visual output)
  106. const op::WrapperStructGui wrapperStructGui{
  107. op::flagsToDisplayMode(FLAGS_display, FLAGS_3d), !FLAGS_no_gui_verbose, FLAGS_fullscreen};
  108. opWrapper.configure(wrapperStructGui);
  109. // Set to single-thread (for sequential processing and/or debugging and/or reducing latency)
  110. if (FLAGS_disable_multi_thread)
  111. opWrapper.disableMultiThreading();
  112. }
  113. catch (const std::exception& e)
  114. {
  115. op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
  116. }
  117. }
  118. int openPoseDemo()
  119. {
  120. try
  121. {
  122. op::opLog("Starting OpenPose demo...", op::Priority::High);
  123. const auto opTimer = op::getTimerInit();
  124. // Configure OpenPose
  125. op::opLog("Configuring OpenPose...", op::Priority::High);
  126. op::Wrapper opWrapper;
  127. configureWrapper(opWrapper);
  128. // Start, run, and stop processing - exec() blocks this thread until OpenPose wrapper has finished
  129. op::opLog("Starting thread(s)...", op::Priority::High);
  130. opWrapper.exec();
  131. // Measuring total time
  132. op::printTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", op::Priority::High);
  133. // Return successful message
  134. return 0;
  135. }
  136. catch (const std::exception&)
  137. {
  138. return -1;
  139. }
  140. }
  141. int main(int argc, char *argv[])
  142. {
  143. // Parsing command line flags
  144. gflags::ParseCommandLineFlags(&argc, &argv, true);
  145. // Running openPoseDemo
  146. return openPoseDemo();
  147. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...