Skip to content

Commit e1daa2d

Browse files
Producer inside Wrapper
1 parent 3932523 commit e1daa2d

20 files changed

+295
-160
lines changed

doc/release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ OpenPose Library - Release Notes
280280
2. Array::getPybindPtr() to get an editable const pointer.
281281
3. Array::pData as binding of spData.
282282
4. Array::Array that takes as input a pointer, so it does not re-allocate memory.
283+
12. Producer defined inside Wrapper rather than being defined on each example.
283284
2. Functions or parameters renamed:
284285
1. By default, python example `tutorial_developer/python_2_pose_from_heatmaps.py` was using 2 scales starting at -1x736, changed to 1 scale at -1x368.
285286
2. WrapperStructPose default parameters changed to match those of the OpenPose demo binary.

examples/openpose/openpose.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ int openPoseDemo()
3131
// op::Profiler::setDefaultX(100);
3232

3333
// Applying user defined configuration - GFlags to program variables
34+
// cameraSize
35+
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
3436
// outputSize
3537
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
3638
// netInputSize
@@ -40,10 +42,10 @@ int openPoseDemo()
4042
// handNetInputSize
4143
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
4244
// producerType
43-
const auto producerSharedPtr = op::flagsToProducer(
44-
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_camera_resolution,
45-
FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
46-
(unsigned int) FLAGS_3d_views, FLAGS_flir_camera_index);
45+
op::ProducerType producerType;
46+
std::string producerString;
47+
std::tie(producerType, producerString) = op::flagsToProducer(
48+
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
4749
// poseModel
4850
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
4951
// JSON saving
@@ -89,8 +91,10 @@ int openPoseDemo()
8991
opWrapper.configure(wrapperStructExtra);
9092
// Producer (use default to disable any input)
9193
const op::WrapperStructInput wrapperStructInput{
92-
producerSharedPtr, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last, FLAGS_process_real_time,
93-
FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat};
94+
producerType, producerString, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last,
95+
FLAGS_process_real_time, FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat,
96+
cameraSize, FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
97+
(unsigned int) FLAGS_3d_views};
9498
opWrapper.configure(wrapperStructInput);
9599
// Consumer (comment or use default argument to disable any output)
96100
const op::WrapperStructOutput wrapperStructOutput{

examples/tests/handFromJsonTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int handFromJsonTest()
4343
// handNetInputSize
4444
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
4545
// producerType
46-
const auto producerSharedPtr = op::flagsToProducer(FLAGS_image_dir, "", "", 0);
46+
const auto producerSharedPtr = op::createProducer(op::ProducerType::ImageDirectory, FLAGS_image_dir);
4747
// Enabling Google Logging
4848
const bool enableGoogleLogging = true;
4949

examples/tutorial_add_module/1_custom_post_processing.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ int tutorialAddModule1()
4444
op::Profiler::setDefaultX(FLAGS_profile_speed);
4545

4646
// Applying user defined configuration - GFlags to program variables
47+
// cameraSize
48+
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
4749
// outputSize
4850
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
4951
// netInputSize
@@ -53,10 +55,10 @@ int tutorialAddModule1()
5355
// handNetInputSize
5456
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
5557
// producerType
56-
const auto producerSharedPtr = op::flagsToProducer(
57-
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_camera_resolution,
58-
FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
59-
(unsigned int) FLAGS_3d_views, FLAGS_flir_camera_index);
58+
op::ProducerType producerType;
59+
std::string producerString;
60+
std::tie(producerType, producerString) = op::flagsToProducer(
61+
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
6062
// poseModel
6163
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
6264
// JSON saving
@@ -102,8 +104,10 @@ int tutorialAddModule1()
102104
opWrapperT.configure(wrapperStructExtra);
103105
// Producer (use default to disable any input)
104106
const op::WrapperStructInput wrapperStructInput{
105-
producerSharedPtr, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last, FLAGS_process_real_time,
106-
FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat};
107+
producerType, producerString, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last,
108+
FLAGS_process_real_time, FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat,
109+
cameraSize, FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
110+
(unsigned int) FLAGS_3d_views};
107111
opWrapperT.configure(wrapperStructInput);
108112
// Consumer (comment or use default argument to disable any output)
109113
const op::WrapperStructOutput wrapperStructOutput{

examples/tutorial_api_cpp/5_asynchronous_loop_custom_output.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ int tutorialApiCpp5()
126126
op::Profiler::setDefaultX(FLAGS_profile_speed);
127127

128128
// Applying user defined configuration - GFlags to program variables
129+
// cameraSize
130+
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
129131
// outputSize
130132
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
131133
// netInputSize
@@ -135,10 +137,10 @@ int tutorialApiCpp5()
135137
// handNetInputSize
136138
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
137139
// producerType
138-
const auto producerSharedPtr = op::flagsToProducer(
139-
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_camera_resolution,
140-
FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
141-
(unsigned int) FLAGS_3d_views, FLAGS_flir_camera_index);
140+
op::ProducerType producerType;
141+
std::string producerString;
142+
std::tie(producerType, producerString) = op::flagsToProducer(
143+
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
142144
// poseModel
143145
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
144146
// JSON saving
@@ -184,8 +186,10 @@ int tutorialApiCpp5()
184186
opWrapperT.configure(wrapperStructExtra);
185187
// Producer (use default to disable any input)
186188
const op::WrapperStructInput wrapperStructInput{
187-
producerSharedPtr, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last, FLAGS_process_real_time,
188-
FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat};
189+
producerType, producerString, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last,
190+
FLAGS_process_real_time, FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat,
191+
cameraSize, FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
192+
(unsigned int) FLAGS_3d_views};
189193
opWrapperT.configure(wrapperStructInput);
190194
// Consumer (comment or use default argument to disable any output)
191195
const auto displayMode = op::DisplayMode::NoDisplay;

examples/tutorial_api_cpp/6_synchronous_custom_postprocessing.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ int tutorialApiCpp6()
8686
// op::Profiler::setDefaultX(100);
8787

8888
// Applying user defined configuration - GFlags to program variables
89+
// cameraSize
90+
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
8991
// outputSize
9092
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
9193
// netInputSize
@@ -95,10 +97,10 @@ int tutorialApiCpp6()
9597
// handNetInputSize
9698
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
9799
// producerType
98-
const auto producerSharedPtr = op::flagsToProducer(
99-
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_camera_resolution,
100-
FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
101-
(unsigned int) FLAGS_3d_views, FLAGS_flir_camera_index);
100+
op::ProducerType producerType;
101+
std::string producerString;
102+
std::tie(producerType, producerString) = op::flagsToProducer(
103+
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
102104
// poseModel
103105
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
104106
// JSON saving
@@ -152,8 +154,10 @@ int tutorialApiCpp6()
152154
opWrapperT.configure(wrapperStructExtra);
153155
// Producer (use default to disable any input)
154156
const op::WrapperStructInput wrapperStructInput{
155-
producerSharedPtr, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last, FLAGS_process_real_time,
156-
FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat};
157+
producerType, producerString, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last,
158+
FLAGS_process_real_time, FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat,
159+
cameraSize, FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
160+
(unsigned int) FLAGS_3d_views};
157161
opWrapperT.configure(wrapperStructInput);
158162
// Consumer (comment or use default argument to disable any output)
159163
const op::WrapperStructOutput wrapperStructOutput{

examples/tutorial_api_cpp/8_synchronous_custom_output.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ int tutorialApiCpp8()
133133
// op::Profiler::setDefaultX(100);
134134

135135
// Applying user defined configuration - GFlags to program variables
136+
// cameraSize
137+
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
136138
// outputSize
137139
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
138140
// netInputSize
@@ -142,10 +144,10 @@ int tutorialApiCpp8()
142144
// handNetInputSize
143145
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
144146
// producerType
145-
const auto producerSharedPtr = op::flagsToProducer(
146-
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_camera_resolution,
147-
FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
148-
(unsigned int) FLAGS_3d_views, FLAGS_flir_camera_index);
147+
op::ProducerType producerType;
148+
std::string producerString;
149+
std::tie(producerType, producerString) = op::flagsToProducer(
150+
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
149151
// poseModel
150152
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
151153
// JSON saving
@@ -199,8 +201,10 @@ int tutorialApiCpp8()
199201
opWrapperT.configure(wrapperStructExtra);
200202
// Producer (use default to disable any input)
201203
const op::WrapperStructInput wrapperStructInput{
202-
producerSharedPtr, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last, FLAGS_process_real_time,
203-
FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat};
204+
producerType, producerString, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last,
205+
FLAGS_process_real_time, FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat,
206+
cameraSize, FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
207+
(unsigned int) FLAGS_3d_views};
204208
opWrapperT.configure(wrapperStructInput);
205209
// Consumer (comment or use default argument to disable any output)
206210
const auto displayMode = op::DisplayMode::NoDisplay;

examples/tutorial_developer/thread_1_openpose_read_and_display.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,29 @@ int tutorialDeveloperThread1()
7676
__LINE__, __FUNCTION__, __FILE__);
7777
op::ConfigureLog::setPriorityThreshold((op::Priority)FLAGS_logging_level);
7878
// Step 2 - Read GFlags (user defined configuration)
79+
// cameraSize
80+
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
7981
// outputSize
8082
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
8183
// producerType
82-
const auto producerSharedPtr = op::flagsToProducer(
83-
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_camera_resolution,
84-
FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
85-
(unsigned int) FLAGS_3d_views, FLAGS_flir_camera_index);
84+
op::ProducerType producerType;
85+
std::string producerString;
86+
std::tie(producerType, producerString) = op::flagsToProducer(
87+
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
8688
const auto displayProducerFpsMode = (FLAGS_process_real_time
8789
? op::ProducerFpsMode::OriginalFps : op::ProducerFpsMode::RetrievalFps);
90+
auto producerSharedPtr = createProducer(
91+
producerType, producerString, cameraSize, FLAGS_camera_fps, FLAGS_camera_parameter_folder,
92+
!FLAGS_frame_keep_distortion, (unsigned int) FLAGS_3d_views);
8893
producerSharedPtr->setProducerFpsMode(displayProducerFpsMode);
8994
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
9095
// Step 3 - Setting producer
9196
auto videoSeekSharedPtr = std::make_shared<std::pair<std::atomic<bool>, std::atomic<int>>>();
9297
videoSeekSharedPtr->first = false;
9398
videoSeekSharedPtr->second = 0;
94-
const op::Point<int> producerSize{(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_WIDTH),
95-
(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_HEIGHT)};
99+
const op::Point<int> producerSize{
100+
(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_WIDTH),
101+
(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_HEIGHT)};
96102
// Step 4 - Setting thread workers && manager
97103
typedef std::vector<op::Datum> TypedefDatumsNoPtr;
98104
typedef std::shared_ptr<TypedefDatumsNoPtr> TypedefDatums;

examples/tutorial_developer/thread_2_user_processing_function.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,29 @@ int tutorialDeveloperThread2()
110110
__LINE__, __FUNCTION__, __FILE__);
111111
op::ConfigureLog::setPriorityThreshold((op::Priority)FLAGS_logging_level);
112112
// Step 2 - Read GFlags (user defined configuration)
113+
// cameraSize
114+
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
113115
// outputSize
114116
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
115117
// producerType
116-
const auto producerSharedPtr = op::flagsToProducer(
117-
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_camera_resolution,
118-
FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
119-
(unsigned int) FLAGS_3d_views, FLAGS_flir_camera_index);
118+
op::ProducerType producerType;
119+
std::string producerString;
120+
std::tie(producerType, producerString) = op::flagsToProducer(
121+
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
120122
const auto displayProducerFpsMode = (FLAGS_process_real_time
121123
? op::ProducerFpsMode::OriginalFps : op::ProducerFpsMode::RetrievalFps);
124+
auto producerSharedPtr = createProducer(
125+
producerType, producerString, cameraSize, FLAGS_camera_fps, FLAGS_camera_parameter_folder,
126+
!FLAGS_frame_keep_distortion, (unsigned int) FLAGS_3d_views);
122127
producerSharedPtr->setProducerFpsMode(displayProducerFpsMode);
123128
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
124129
// Step 3 - Setting producer
125130
auto videoSeekSharedPtr = std::make_shared<std::pair<std::atomic<bool>, std::atomic<int>>>();
126131
videoSeekSharedPtr->first = false;
127132
videoSeekSharedPtr->second = 0;
128-
const op::Point<int> producerSize{(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_WIDTH),
129-
(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_HEIGHT)};
133+
const op::Point<int> producerSize{
134+
(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_WIDTH),
135+
(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_HEIGHT)};
130136
// Step 4 - Setting thread workers && manager
131137
typedef std::vector<op::Datum> TypedefDatumsNoPtr;
132138
typedef std::shared_ptr<TypedefDatumsNoPtr> TypedefDatums;

include/openpose/filestream/enumClasses.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ namespace op
1010
Yaml,
1111
Yml,
1212
};
13-
enum class CocoJsonFormat : bool
13+
enum class CocoJsonFormat : unsigned char
1414
{
1515
Body,
1616
Foot,
17+
Car,
18+
Size,
1719
};
1820
}
1921

include/openpose/producer/enumClasses.hpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ namespace op
55
{
66
enum class ProducerFpsMode : bool
77
{
8-
OriginalFps, /**< The frames will be extracted at the original source fps (frames might be skipped or repeated). */
9-
RetrievalFps, /**< The frames will be extracted when the software retrieves them (frames will not be skipped or repeated). */
8+
/** The frames will be extracted at the original source fps (frames might be skipped or repeated). */
9+
OriginalFps,
10+
/** The frames will be extracted when the software retrieves them (frames will not be skipped or repeated). */
11+
RetrievalFps,
1012
};
1113

1214
enum class ProducerProperty : unsigned char
@@ -25,12 +27,20 @@ namespace op
2527
*/
2628
enum class ProducerType : unsigned char
2729
{
28-
FlirCamera, /**< Stereo FLIR (Point-Grey) camera reader. Based on Spinnaker SDK. */
29-
ImageDirectory, /**< An image directory reader. It is able to read images on a folder with a interface similar to the OpenCV cv::VideoCapture. */
30-
IPCamera, /**< An IP camera frames extractor, extending the functionality of cv::VideoCapture. */
31-
Video, /**< A video frames extractor, extending the functionality of cv::VideoCapture. */
32-
Webcam, /**< A webcam frames extractor, extending the functionality of cv::VideoCapture. */
33-
None, /**< No type defined. Default state when no specific Producer has been picked yet. */
30+
/** Stereo FLIR (Point-Grey) camera reader. Based on Spinnaker SDK. */
31+
FlirCamera,
32+
/** An image directory reader. It is able to read images on a folder with a interface similar to the OpenCV
33+
* cv::VideoCapture.
34+
*/
35+
ImageDirectory,
36+
/** An IP camera frames extractor, extending the functionality of cv::VideoCapture. */
37+
IPCamera,
38+
/** A video frames extractor, extending the functionality of cv::VideoCapture. */
39+
Video,
40+
/** A webcam frames extractor, extending the functionality of cv::VideoCapture. */
41+
Webcam,
42+
/** No type defined. Default state when no specific Producer has been picked yet. */
43+
None,
3444
};
3545
}
3646

0 commit comments

Comments
 (0)