Skip to content

Commit

Permalink
Producer inside Wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
gineshidalgo99 committed Oct 28, 2018
1 parent 3932523 commit e1daa2d
Show file tree
Hide file tree
Showing 20 changed files with 295 additions and 160 deletions.
1 change: 1 addition & 0 deletions doc/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ OpenPose Library - Release Notes
2. Array::getPybindPtr() to get an editable const pointer.
3. Array::pData as binding of spData.
4. Array::Array that takes as input a pointer, so it does not re-allocate memory.
12. Producer defined inside Wrapper rather than being defined on each example.
2. Functions or parameters renamed:
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.
2. WrapperStructPose default parameters changed to match those of the OpenPose demo binary.
Expand Down
16 changes: 10 additions & 6 deletions examples/openpose/openpose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ int openPoseDemo()
// op::Profiler::setDefaultX(100);

// Applying user defined configuration - GFlags to program variables
// cameraSize
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
// outputSize
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
// netInputSize
Expand All @@ -40,10 +42,10 @@ int openPoseDemo()
// handNetInputSize
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
// producerType
const auto producerSharedPtr = op::flagsToProducer(
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_camera_resolution,
FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
(unsigned int) FLAGS_3d_views, FLAGS_flir_camera_index);
op::ProducerType producerType;
std::string producerString;
std::tie(producerType, producerString) = op::flagsToProducer(
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
// poseModel
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
// JSON saving
Expand Down Expand Up @@ -89,8 +91,10 @@ int openPoseDemo()
opWrapper.configure(wrapperStructExtra);
// Producer (use default to disable any input)
const op::WrapperStructInput wrapperStructInput{
producerSharedPtr, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last, FLAGS_process_real_time,
FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat};
producerType, producerString, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last,
FLAGS_process_real_time, FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat,
cameraSize, FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
(unsigned int) FLAGS_3d_views};
opWrapper.configure(wrapperStructInput);
// Consumer (comment or use default argument to disable any output)
const op::WrapperStructOutput wrapperStructOutput{
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/handFromJsonTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int handFromJsonTest()
// handNetInputSize
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
// producerType
const auto producerSharedPtr = op::flagsToProducer(FLAGS_image_dir, "", "", 0);
const auto producerSharedPtr = op::createProducer(op::ProducerType::ImageDirectory, FLAGS_image_dir);
// Enabling Google Logging
const bool enableGoogleLogging = true;

Expand Down
16 changes: 10 additions & 6 deletions examples/tutorial_add_module/1_custom_post_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ int tutorialAddModule1()
op::Profiler::setDefaultX(FLAGS_profile_speed);

// Applying user defined configuration - GFlags to program variables
// cameraSize
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
// outputSize
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
// netInputSize
Expand All @@ -53,10 +55,10 @@ int tutorialAddModule1()
// handNetInputSize
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
// producerType
const auto producerSharedPtr = op::flagsToProducer(
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_camera_resolution,
FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
(unsigned int) FLAGS_3d_views, FLAGS_flir_camera_index);
op::ProducerType producerType;
std::string producerString;
std::tie(producerType, producerString) = op::flagsToProducer(
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
// poseModel
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
// JSON saving
Expand Down Expand Up @@ -102,8 +104,10 @@ int tutorialAddModule1()
opWrapperT.configure(wrapperStructExtra);
// Producer (use default to disable any input)
const op::WrapperStructInput wrapperStructInput{
producerSharedPtr, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last, FLAGS_process_real_time,
FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat};
producerType, producerString, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last,
FLAGS_process_real_time, FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat,
cameraSize, FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
(unsigned int) FLAGS_3d_views};
opWrapperT.configure(wrapperStructInput);
// Consumer (comment or use default argument to disable any output)
const op::WrapperStructOutput wrapperStructOutput{
Expand Down
16 changes: 10 additions & 6 deletions examples/tutorial_api_cpp/5_asynchronous_loop_custom_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ int tutorialApiCpp5()
op::Profiler::setDefaultX(FLAGS_profile_speed);

// Applying user defined configuration - GFlags to program variables
// cameraSize
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
// outputSize
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
// netInputSize
Expand All @@ -135,10 +137,10 @@ int tutorialApiCpp5()
// handNetInputSize
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
// producerType
const auto producerSharedPtr = op::flagsToProducer(
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_camera_resolution,
FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
(unsigned int) FLAGS_3d_views, FLAGS_flir_camera_index);
op::ProducerType producerType;
std::string producerString;
std::tie(producerType, producerString) = op::flagsToProducer(
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
// poseModel
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
// JSON saving
Expand Down Expand Up @@ -184,8 +186,10 @@ int tutorialApiCpp5()
opWrapperT.configure(wrapperStructExtra);
// Producer (use default to disable any input)
const op::WrapperStructInput wrapperStructInput{
producerSharedPtr, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last, FLAGS_process_real_time,
FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat};
producerType, producerString, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last,
FLAGS_process_real_time, FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat,
cameraSize, FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
(unsigned int) FLAGS_3d_views};
opWrapperT.configure(wrapperStructInput);
// Consumer (comment or use default argument to disable any output)
const auto displayMode = op::DisplayMode::NoDisplay;
Expand Down
16 changes: 10 additions & 6 deletions examples/tutorial_api_cpp/6_synchronous_custom_postprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ int tutorialApiCpp6()
// op::Profiler::setDefaultX(100);

// Applying user defined configuration - GFlags to program variables
// cameraSize
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
// outputSize
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
// netInputSize
Expand All @@ -95,10 +97,10 @@ int tutorialApiCpp6()
// handNetInputSize
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
// producerType
const auto producerSharedPtr = op::flagsToProducer(
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_camera_resolution,
FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
(unsigned int) FLAGS_3d_views, FLAGS_flir_camera_index);
op::ProducerType producerType;
std::string producerString;
std::tie(producerType, producerString) = op::flagsToProducer(
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
// poseModel
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
// JSON saving
Expand Down Expand Up @@ -152,8 +154,10 @@ int tutorialApiCpp6()
opWrapperT.configure(wrapperStructExtra);
// Producer (use default to disable any input)
const op::WrapperStructInput wrapperStructInput{
producerSharedPtr, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last, FLAGS_process_real_time,
FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat};
producerType, producerString, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last,
FLAGS_process_real_time, FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat,
cameraSize, FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
(unsigned int) FLAGS_3d_views};
opWrapperT.configure(wrapperStructInput);
// Consumer (comment or use default argument to disable any output)
const op::WrapperStructOutput wrapperStructOutput{
Expand Down
16 changes: 10 additions & 6 deletions examples/tutorial_api_cpp/8_synchronous_custom_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ int tutorialApiCpp8()
// op::Profiler::setDefaultX(100);

// Applying user defined configuration - GFlags to program variables
// cameraSize
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
// outputSize
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
// netInputSize
Expand All @@ -142,10 +144,10 @@ int tutorialApiCpp8()
// handNetInputSize
const auto handNetInputSize = op::flagsToPoint(FLAGS_hand_net_resolution, "368x368 (multiples of 16)");
// producerType
const auto producerSharedPtr = op::flagsToProducer(
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_camera_resolution,
FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
(unsigned int) FLAGS_3d_views, FLAGS_flir_camera_index);
op::ProducerType producerType;
std::string producerString;
std::tie(producerType, producerString) = op::flagsToProducer(
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
// poseModel
const auto poseModel = op::flagsToPoseModel(FLAGS_model_pose);
// JSON saving
Expand Down Expand Up @@ -199,8 +201,10 @@ int tutorialApiCpp8()
opWrapperT.configure(wrapperStructExtra);
// Producer (use default to disable any input)
const op::WrapperStructInput wrapperStructInput{
producerSharedPtr, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last, FLAGS_process_real_time,
FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat};
producerType, producerString, FLAGS_frame_first, FLAGS_frame_step, FLAGS_frame_last,
FLAGS_process_real_time, FLAGS_frame_flip, FLAGS_frame_rotate, FLAGS_frames_repeat,
cameraSize, FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
(unsigned int) FLAGS_3d_views};
opWrapperT.configure(wrapperStructInput);
// Consumer (comment or use default argument to disable any output)
const auto displayMode = op::DisplayMode::NoDisplay;
Expand Down
18 changes: 12 additions & 6 deletions examples/tutorial_developer/thread_1_openpose_read_and_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,29 @@ int tutorialDeveloperThread1()
__LINE__, __FUNCTION__, __FILE__);
op::ConfigureLog::setPriorityThreshold((op::Priority)FLAGS_logging_level);
// Step 2 - Read GFlags (user defined configuration)
// cameraSize
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
// outputSize
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
// producerType
const auto producerSharedPtr = op::flagsToProducer(
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_camera_resolution,
FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
(unsigned int) FLAGS_3d_views, FLAGS_flir_camera_index);
op::ProducerType producerType;
std::string producerString;
std::tie(producerType, producerString) = op::flagsToProducer(
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
const auto displayProducerFpsMode = (FLAGS_process_real_time
? op::ProducerFpsMode::OriginalFps : op::ProducerFpsMode::RetrievalFps);
auto producerSharedPtr = createProducer(
producerType, producerString, cameraSize, FLAGS_camera_fps, FLAGS_camera_parameter_folder,
!FLAGS_frame_keep_distortion, (unsigned int) FLAGS_3d_views);
producerSharedPtr->setProducerFpsMode(displayProducerFpsMode);
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// Step 3 - Setting producer
auto videoSeekSharedPtr = std::make_shared<std::pair<std::atomic<bool>, std::atomic<int>>>();
videoSeekSharedPtr->first = false;
videoSeekSharedPtr->second = 0;
const op::Point<int> producerSize{(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_WIDTH),
(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_HEIGHT)};
const op::Point<int> producerSize{
(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_WIDTH),
(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_HEIGHT)};
// Step 4 - Setting thread workers && manager
typedef std::vector<op::Datum> TypedefDatumsNoPtr;
typedef std::shared_ptr<TypedefDatumsNoPtr> TypedefDatums;
Expand Down
18 changes: 12 additions & 6 deletions examples/tutorial_developer/thread_2_user_processing_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,29 @@ int tutorialDeveloperThread2()
__LINE__, __FUNCTION__, __FILE__);
op::ConfigureLog::setPriorityThreshold((op::Priority)FLAGS_logging_level);
// Step 2 - Read GFlags (user defined configuration)
// cameraSize
const auto cameraSize = op::flagsToPoint(FLAGS_camera_resolution, "-1x-1");
// outputSize
const auto outputSize = op::flagsToPoint(FLAGS_output_resolution, "-1x-1");
// producerType
const auto producerSharedPtr = op::flagsToProducer(
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_camera_resolution,
FLAGS_camera_fps, FLAGS_camera_parameter_folder, !FLAGS_frame_keep_distortion,
(unsigned int) FLAGS_3d_views, FLAGS_flir_camera_index);
op::ProducerType producerType;
std::string producerString;
std::tie(producerType, producerString) = op::flagsToProducer(
FLAGS_image_dir, FLAGS_video, FLAGS_ip_camera, FLAGS_camera, FLAGS_flir_camera, FLAGS_flir_camera_index);
const auto displayProducerFpsMode = (FLAGS_process_real_time
? op::ProducerFpsMode::OriginalFps : op::ProducerFpsMode::RetrievalFps);
auto producerSharedPtr = createProducer(
producerType, producerString, cameraSize, FLAGS_camera_fps, FLAGS_camera_parameter_folder,
!FLAGS_frame_keep_distortion, (unsigned int) FLAGS_3d_views);
producerSharedPtr->setProducerFpsMode(displayProducerFpsMode);
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// Step 3 - Setting producer
auto videoSeekSharedPtr = std::make_shared<std::pair<std::atomic<bool>, std::atomic<int>>>();
videoSeekSharedPtr->first = false;
videoSeekSharedPtr->second = 0;
const op::Point<int> producerSize{(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_WIDTH),
(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_HEIGHT)};
const op::Point<int> producerSize{
(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_WIDTH),
(int)producerSharedPtr->get(CV_CAP_PROP_FRAME_HEIGHT)};
// Step 4 - Setting thread workers && manager
typedef std::vector<op::Datum> TypedefDatumsNoPtr;
typedef std::shared_ptr<TypedefDatumsNoPtr> TypedefDatums;
Expand Down
4 changes: 3 additions & 1 deletion include/openpose/filestream/enumClasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ namespace op
Yaml,
Yml,
};
enum class CocoJsonFormat : bool
enum class CocoJsonFormat : unsigned char
{
Body,
Foot,
Car,
Size,
};
}

Expand Down
26 changes: 18 additions & 8 deletions include/openpose/producer/enumClasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ namespace op
{
enum class ProducerFpsMode : bool
{
OriginalFps, /**< The frames will be extracted at the original source fps (frames might be skipped or repeated). */
RetrievalFps, /**< The frames will be extracted when the software retrieves them (frames will not be skipped or repeated). */
/** The frames will be extracted at the original source fps (frames might be skipped or repeated). */
OriginalFps,
/** The frames will be extracted when the software retrieves them (frames will not be skipped or repeated). */
RetrievalFps,
};

enum class ProducerProperty : unsigned char
Expand All @@ -25,12 +27,20 @@ namespace op
*/
enum class ProducerType : unsigned char
{
FlirCamera, /**< Stereo FLIR (Point-Grey) camera reader. Based on Spinnaker SDK. */
ImageDirectory, /**< An image directory reader. It is able to read images on a folder with a interface similar to the OpenCV cv::VideoCapture. */
IPCamera, /**< An IP camera frames extractor, extending the functionality of cv::VideoCapture. */
Video, /**< A video frames extractor, extending the functionality of cv::VideoCapture. */
Webcam, /**< A webcam frames extractor, extending the functionality of cv::VideoCapture. */
None, /**< No type defined. Default state when no specific Producer has been picked yet. */
/** Stereo FLIR (Point-Grey) camera reader. Based on Spinnaker SDK. */
FlirCamera,
/** An image directory reader. It is able to read images on a folder with a interface similar to the OpenCV
* cv::VideoCapture.
*/
ImageDirectory,
/** An IP camera frames extractor, extending the functionality of cv::VideoCapture. */
IPCamera,
/** A video frames extractor, extending the functionality of cv::VideoCapture. */
Video,
/** A webcam frames extractor, extending the functionality of cv::VideoCapture. */
Webcam,
/** No type defined. Default state when no specific Producer has been picked yet. */
None,
};
}

Expand Down
Loading

0 comments on commit e1daa2d

Please sign in to comment.