AI Watch A1
Multi-person 3D skeleton detection using Intel RealSense and OpenPose with Kafka support.
Functions
OpenPoseCommand.cpp File Reference
#include "SystemCommand.hpp"
#include <openpose/flags.hpp>
#include <openpose/headers.hpp>

Go to the source code of this file.

Functions

void configureWrapper (op::Wrapper &opWrapper)
 
void saveOpenPoseOutput (int *argc, char ***argv)
 

Function Documentation

◆ configureWrapper()

void configureWrapper ( op::Wrapper &  opWrapper)

Definition at line 17 of file OpenPoseCommand.cpp.

17 {
18 try {
19 // logging_level
20 op::checkBool(
21 0 <= FLAGS_logging_level && FLAGS_logging_level <= 255, "Wrong logging_level value.",
22 __LINE__, __FUNCTION__, __FILE__);
23 op::ConfigureLog::setPriorityThreshold((op::Priority)FLAGS_logging_level);
24 op::Profiler::setDefaultX(FLAGS_profile_speed);
25
26 // Applying user defined configuration - GFlags to program variables
27 // outputSize
28 const auto outputSize = op::flagsToPoint(op::String(FLAGS_output_resolution), "-1x-1");
29 // netInputSize
30 const auto netInputSize = op::flagsToPoint(op::String(FLAGS_net_resolution), "-1x368");
31 // faceNetInputSize
32 const auto faceNetInputSize = op::flagsToPoint(op::String(FLAGS_face_net_resolution), "368x368 (multiples of 16)");
33 // handNetInputSize
34 const auto handNetInputSize = op::flagsToPoint(op::String(FLAGS_hand_net_resolution), "368x368 (multiples of 16)");
35 // poseMode
36 const auto poseMode = op::flagsToPoseMode(FLAGS_body);
37 // poseModel
38 const auto poseModel = op::flagsToPoseModel(op::String(FLAGS_model_pose));
39 // JSON saving
40 if (!FLAGS_write_keypoint.empty()) {
41 op::opLog("Flag 'write_keypoint' is deprecated and will eventually be removed. Please, use 'write_json'"
42 " instead.", op::Priority::Max);
43 }
44 // keypointScaleMode
45 const auto keypointScaleMode = op::flagsToScaleMode(FLAGS_keypoint_scale);
46 // heatmaps to add
47 const auto heatMapTypes = op::flagsToHeatMaps(FLAGS_heatmaps_add_parts, FLAGS_heatmaps_add_bkg,
48 FLAGS_heatmaps_add_PAFs);
49 const auto heatMapScaleMode = op::flagsToHeatMapScaleMode(FLAGS_heatmaps_scale);
50 // >1 camera view?
51 const auto multipleView = (FLAGS_3d || FLAGS_3d_views > 1);
52 // Face and hand detectors
53 const auto faceDetector = op::flagsToDetector(FLAGS_face_detector);
54 const auto handDetector = op::flagsToDetector(FLAGS_hand_detector);
55 // Enabling Google Logging
56 const bool enableGoogleLogging = true;
57
58 // Pose configuration (use WrapperStructPose{} for default and recommended configuration)
59 const op::WrapperStructPose wrapperStructPose{
60 poseMode, netInputSize, FLAGS_net_resolution_dynamic, outputSize, keypointScaleMode, FLAGS_num_gpu,
61 FLAGS_num_gpu_start, FLAGS_scale_number, (float)FLAGS_scale_gap,
62 op::flagsToRenderMode(FLAGS_render_pose, multipleView), poseModel, !FLAGS_disable_blending,
63 (float)FLAGS_alpha_pose, (float)FLAGS_alpha_heatmap, FLAGS_part_to_show, op::String(FLAGS_model_folder),
64 heatMapTypes, heatMapScaleMode, FLAGS_part_candidates, (float)FLAGS_render_threshold,
65 FLAGS_number_people_max, FLAGS_maximize_positives, FLAGS_fps_max, op::String(FLAGS_prototxt_path),
66 op::String(FLAGS_caffemodel_path), (float)FLAGS_upsampling_ratio, enableGoogleLogging};
67 opWrapper.configure(wrapperStructPose);
68 // Face configuration (use op::WrapperStructFace{} to disable it)
69 const op::WrapperStructFace wrapperStructFace{
70 FLAGS_face, faceDetector, faceNetInputSize,
71 op::flagsToRenderMode(FLAGS_face_render, multipleView, FLAGS_render_pose),
72 (float)FLAGS_face_alpha_pose, (float)FLAGS_face_alpha_heatmap, (float)FLAGS_face_render_threshold};
73 opWrapper.configure(wrapperStructFace);
74 // Hand configuration (use op::WrapperStructHand{} to disable it)
75 const op::WrapperStructHand wrapperStructHand{
76 FLAGS_hand, handDetector, handNetInputSize, FLAGS_hand_scale_number, (float)FLAGS_hand_scale_range,
77 op::flagsToRenderMode(FLAGS_hand_render, multipleView, FLAGS_render_pose), (float)FLAGS_hand_alpha_pose,
78 (float)FLAGS_hand_alpha_heatmap, (float)FLAGS_hand_render_threshold};
79 opWrapper.configure(wrapperStructHand);
80 // Extra functionality configuration (use op::WrapperStructExtra{} to disable it)
81 const op::WrapperStructExtra wrapperStructExtra{
82 FLAGS_3d, FLAGS_3d_min_views, FLAGS_identification, FLAGS_tracking, FLAGS_ik_threads};
83 opWrapper.configure(wrapperStructExtra);
84 // Output (comment or use default argument to disable any output)
85 const op::WrapperStructOutput wrapperStructOutput{
86 FLAGS_cli_verbose, op::String(FLAGS_write_keypoint), op::stringToDataFormat(FLAGS_write_keypoint_format),
87 op::String(FLAGS_write_json), op::String(FLAGS_write_coco_json), FLAGS_write_coco_json_variants,
88 FLAGS_write_coco_json_variant, op::String(FLAGS_write_images), op::String(FLAGS_write_images_format),
89 op::String(FLAGS_write_video), FLAGS_write_video_fps, FLAGS_write_video_with_audio,
90 op::String(FLAGS_write_heatmaps), op::String(FLAGS_write_heatmaps_format), op::String(FLAGS_write_video_3d),
91 op::String(FLAGS_write_video_adam), op::String(FLAGS_write_bvh), op::String(FLAGS_udp_host),
92 op::String(FLAGS_udp_port)};
93 opWrapper.configure(wrapperStructOutput);
94 // No GUI. Equivalent to: opWrapper.configure(op::WrapperStructGui{});
95 // Set to single-thread (for sequential processing and/or debugging and/or reducing latency)
96 if (FLAGS_disable_multi_thread)
97 opWrapper.disableMultiThreading();
98 } catch (const std::exception & e) {
99 op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
100 }
101}

Referenced by saveOpenPoseOutput().

◆ saveOpenPoseOutput()

void saveOpenPoseOutput ( int *  argc,
char ***  argv 
)

Definition at line 103 of file OpenPoseCommand.cpp.

103 {
104 try {
105 gflags::ParseCommandLineFlags(argc, argv, true);
106 op::Wrapper opWrapper { op::ThreadManagerMode::Asynchronous };
107 configureWrapper(opWrapper);
108 opWrapper.start();
109 // Read frames on directory
110 const auto imagePaths = op::getFilesOnDirectory(FLAGS_image_dir, op::Extensions::Images);
111
112 // Process and display images
113 for (const auto & imagePath : imagePaths) {
114 const cv::Mat cvImageToProcess = cv::imread(imagePath);
115 const op::Matrix imageToProcess = OP_CV2OPCONSTMAT(cvImageToProcess);
116 auto datumProcessed = opWrapper.emplaceAndPop(imageToProcess);
117 }
118 } catch (const std::exception & e) {
119 op::error(e.what());
120 }
121}
void configureWrapper(op::Wrapper &opWrapper)

References configureWrapper().