提交 1adb1b15 编写于 作者: G gineshidalgo99

Added flag

上级 3d2c0e2f
......@@ -15,6 +15,7 @@ Each flag is divided into flag name, default value, and description.
2. Producer
- DEFINE_int32(camera, 0, "The camera index for cv::VideoCapture. Integer in the range [0, 9].");
- DEFINE_string(camera_resolution, "1280x720", "Size of the camera frames to ask for.");
- DEFINE_double(camera_fps, 30.0, "Frame rate for the webcam (only used when saving video from webcam). Set this value to the minimum value between the OpenPose displayed speed and the webcam real frame rate.");
- DEFINE_string(video, "", "Use a video file instead of the camera. Use `examples/media/video.avi` for our default example video.");
- DEFINE_string(image_dir, "", "Process a directory of images. Use `examples/media/` for our default example folder with 20 images.");
- DEFINE_uint64(frame_first, 0, "Start on desired frame number. Indexes are 0-based, i.e. the first frame has index 0.");
......
......@@ -50,7 +50,8 @@ OpenPose Library - Release Notes
2. Increased speed ~3-5% by adding CPU rendering and setting it as default rendering.
3. Check() functions give more feedback.
4. WCocoJsonSaver finished and removed its 3599-image limit.
5. Improved documentation.
5. Added `camera_fps` so generated video will use that frame rate.
6. Improved documentation.
2. Functions or parameters renamed:
1. Render flags renamed in the demo in order to incorporate the CPU/GPU rendering.
3. Main bugs fixed:
......
......@@ -51,6 +51,8 @@ DEFINE_int32(logging_level, 3, "The logging level. Inte
// Producer
DEFINE_int32(camera, 0, "The camera index for cv::VideoCapture. Integer in the range [0, 9].");
DEFINE_string(camera_resolution, "1280x720", "Size of the camera frames to ask for.");
DEFINE_double(camera_fps, 30.0, "Frame rate for the webcam (only used when saving video from webcam). Set this value to the"
" minimum value between the OpenPose displayed speed and the webcam real frame rate.");
DEFINE_string(video, "", "Use a video file instead of the camera. Use `examples/media/video.avi` for our default"
" example video.");
DEFINE_string(image_dir, "", "Process a directory of images. Use `examples/media/` for our default example folder with 20"
......@@ -198,7 +200,7 @@ op::ProducerType gflagsToProducerType(const std::string& imageDirectory, const s
}
std::shared_ptr<op::Producer> gflagsToProducer(const std::string& imageDirectory, const std::string& videoPath, const int webcamIndex,
const op::Point<int> webcamResolution)
const op::Point<int> webcamResolution, const int webcamFps)
{
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
const auto type = gflagsToProducerType(imageDirectory, videoPath, webcamIndex);
......@@ -208,7 +210,7 @@ std::shared_ptr<op::Producer> gflagsToProducer(const std::string& imageDirectory
else if (type == op::ProducerType::Video)
return std::make_shared<op::VideoReader>(videoPath);
else if (type == op::ProducerType::Webcam)
return std::make_shared<op::WebcamReader>(webcamIndex, webcamResolution);
return std::make_shared<op::WebcamReader>(webcamIndex, webcamResolution, webcamFps);
else
{
op::error("Undefined Producer selected.", __LINE__, __FUNCTION__, __FILE__);
......@@ -246,8 +248,8 @@ op::RenderMode gflagToRenderMode(const int renderFlag, const int renderPoseFlag
}
// Google flags into program variables
std::tuple<op::Point<int>, op::Point<int>, op::Point<int>, op::Point<int>, std::shared_ptr<op::Producer>, op::PoseModel,
op::ScaleMode, std::vector<op::HeatMapType>> gflagsToOpParameters()
std::tuple<op::Point<int>, op::Point<int>, op::Point<int>, std::shared_ptr<op::Producer>, op::PoseModel, op::ScaleMode,
std::vector<op::HeatMapType>> gflagsToOpParameters()
{
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// cameraFrameSize
......@@ -271,7 +273,7 @@ std::tuple<op::Point<int>, op::Point<int>, op::Point<int>, op::Point<int>, std::
op::checkE(nRead, 2, "Error, face net resolution format (" + FLAGS_face_net_resolution
+ ") invalid, should be e.g., 368x368 (multiples of 16)", __LINE__, __FUNCTION__, __FILE__);
// producerType
const auto producerSharedPtr = gflagsToProducer(FLAGS_image_dir, FLAGS_video, FLAGS_camera, cameraFrameSize);
const auto producerSharedPtr = gflagsToProducer(FLAGS_image_dir, FLAGS_video, FLAGS_camera, cameraFrameSize, FLAGS_camera_fps);
// poseModel
const auto poseModel = gflagToPoseModel(FLAGS_model_pose);
// keypointScale
......@@ -279,7 +281,7 @@ std::tuple<op::Point<int>, op::Point<int>, op::Point<int>, op::Point<int>, std::
// heatmaps to add
const auto heatMapTypes = gflagToHeatMaps(FLAGS_heatmaps_add_parts, FLAGS_heatmaps_add_bkg, FLAGS_heatmaps_add_PAFs);
// Return
return std::make_tuple(cameraFrameSize, outputSize, netInputSize, faceNetInputSize, producerSharedPtr, poseModel, keypointScale, heatMapTypes);
return std::make_tuple(outputSize, netInputSize, faceNetInputSize, producerSharedPtr, poseModel, keypointScale, heatMapTypes);
}
int opRealTimePoseDemo()
......@@ -293,7 +295,6 @@ int opRealTimePoseDemo()
const auto timerBegin = std::chrono::high_resolution_clock::now();
// Applying user defined configuration
op::Point<int> cameraFrameSize;
op::Point<int> outputSize;
op::Point<int> netInputSize;
op::Point<int> faceNetInputSize;
......@@ -301,8 +302,7 @@ int opRealTimePoseDemo()
op::PoseModel poseModel;
op::ScaleMode keypointScale;
std::vector<op::HeatMapType> heatMapTypes;
std::tie(cameraFrameSize, outputSize, netInputSize, faceNetInputSize, producerSharedPtr, poseModel, keypointScale,
heatMapTypes) = gflagsToOpParameters();
std::tie(outputSize, netInputSize, faceNetInputSize, producerSharedPtr, poseModel, keypointScale, heatMapTypes) = gflagsToOpParameters();
// OpenPose wrapper
op::log("Configuring OpenPose wrapper.", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
......
......@@ -27,6 +27,8 @@ DEFINE_int32(logging_level, 3, "The logging level. Inte
// Producer
DEFINE_int32(camera, 0, "The camera index for cv::VideoCapture. Integer in the range [0, 9].");
DEFINE_string(camera_resolution, "1280x720", "Size of the camera frames to ask for.");
DEFINE_double(camera_fps, 30.0, "Frame rate for the webcam (only used when saving video from webcam). Set this value to the"
" minimum value between the OpenPose displayed speed and the webcam real frame rate.");
DEFINE_string(video, "", "Use a video file instead of the camera. Use `examples/media/video.avi` for our default"
" example video.");
DEFINE_string(image_dir, "", "Process a directory of images. Use `examples/media/` for our default example folder with 20"
......@@ -61,7 +63,7 @@ op::ProducerType gflagsToProducerType(const std::string& imageDirectory, const s
}
std::shared_ptr<op::Producer> gflagsToProducer(const std::string& imageDirectory, const std::string& videoPath, const int webcamIndex,
const op::Point<int> webcamResolution)
const op::Point<int> webcamResolution, const int webcamFps)
{
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
const auto type = gflagsToProducerType(imageDirectory, videoPath, webcamIndex);
......@@ -71,7 +73,7 @@ std::shared_ptr<op::Producer> gflagsToProducer(const std::string& imageDirectory
else if (type == op::ProducerType::Video)
return std::make_shared<op::VideoReader>(videoPath);
else if (type == op::ProducerType::Webcam)
return std::make_shared<op::WebcamReader>(webcamIndex, webcamResolution);
return std::make_shared<op::WebcamReader>(webcamIndex, webcamResolution, webcamFps);
else
{
op::error("Undefined Producer selected.", __LINE__, __FUNCTION__, __FILE__);
......@@ -95,7 +97,7 @@ std::tuple<op::Point<int>, op::Point<int>, std::shared_ptr<op::Producer>> gflags
__LINE__, __FUNCTION__, __FILE__);
// producerType
const auto producerSharedPtr = gflagsToProducer(FLAGS_image_dir, FLAGS_video, FLAGS_camera, cameraFrameSize);
const auto producerSharedPtr = gflagsToProducer(FLAGS_image_dir, FLAGS_video, FLAGS_camera, cameraFrameSize, FLAGS_camera_fps);
const auto displayProducerFpsMode = (FLAGS_process_real_time ? op::ProducerFpsMode::OriginalFps : op::ProducerFpsMode::RetrievalFps);
producerSharedPtr->setProducerFpsMode(displayProducerFpsMode);
......
......@@ -28,6 +28,8 @@ DEFINE_int32(logging_level, 3, "The logging level. Inte
// Producer
DEFINE_int32(camera, 0, "The camera index for cv::VideoCapture. Integer in the range [0, 9].");
DEFINE_string(camera_resolution, "1280x720", "Size of the camera frames to ask for.");
DEFINE_double(camera_fps, 30.0, "Frame rate for the webcam (only used when saving video from webcam). Set this value to the"
" minimum value between the OpenPose displayed speed and the webcam real frame rate.");
DEFINE_string(video, "", "Use a video file instead of the camera. Use `examples/media/video.avi` for our default"
" example video.");
DEFINE_string(image_dir, "", "Process a directory of images. Use `examples/media/` for our default example folder with 20"
......@@ -95,7 +97,7 @@ op::ProducerType gflagsToProducerType(const std::string& imageDirectory, const s
}
std::shared_ptr<op::Producer> gflagsToProducer(const std::string& imageDirectory, const std::string& videoPath, const int webcamIndex,
const op::Point<int> webcamResolution)
const op::Point<int> webcamResolution, const int webcamFps)
{
op::log("", op::Priority::Low, __LINE__, __FUNCTION__, __FILE__);
const auto type = gflagsToProducerType(imageDirectory, videoPath, webcamIndex);
......@@ -105,7 +107,7 @@ std::shared_ptr<op::Producer> gflagsToProducer(const std::string& imageDirectory
else if (type == op::ProducerType::Video)
return std::make_shared<op::VideoReader>(videoPath);
else if (type == op::ProducerType::Webcam)
return std::make_shared<op::WebcamReader>(webcamIndex, webcamResolution);
return std::make_shared<op::WebcamReader>(webcamIndex, webcamResolution, webcamFps);
else
{
op::error("Undefined Producer selected.", __LINE__, __FUNCTION__, __FILE__);
......@@ -129,7 +131,7 @@ std::tuple<op::Point<int>, op::Point<int>, std::shared_ptr<op::Producer>> gflags
__LINE__, __FUNCTION__, __FILE__);
// producerType
const auto producerSharedPtr = gflagsToProducer(FLAGS_image_dir, FLAGS_video, FLAGS_camera, cameraFrameSize);
const auto producerSharedPtr = gflagsToProducer(FLAGS_image_dir, FLAGS_video, FLAGS_camera, cameraFrameSize, FLAGS_camera_fps);
const auto displayProducerFpsMode = (FLAGS_process_real_time ? op::ProducerFpsMode::OriginalFps : op::ProducerFpsMode::RetrievalFps);
producerSharedPtr->setProducerFpsMode(displayProducerFpsMode);
......
......@@ -44,10 +44,7 @@ namespace op
virtual double get(const int capProperty) = 0;
inline void set(const int capProperty, const double value)
{
mVideoCapture.set(capProperty, value);
}
virtual void set(const int capProperty, const double value) = 0;
inline double get(const ProducerProperty property)
{
......
......@@ -26,6 +26,11 @@ namespace op
return VideoCaptureReader::get(capProperty);
}
inline void set(const int capProperty, const double value)
{
VideoCaptureReader::set(capProperty, value);
}
private:
const std::string mPathName;
......
......@@ -21,8 +21,9 @@ namespace op
* @param webcamIndex const int indicating the camera source (see the OpenCV documentation about
* cv::VideoCapture for more details), in the range [0, 9].
* @param webcamResolution const Point<int> parameter which specifies the desired camera resolution.
* @param fps Double parameter which specifies the desired camera frame rate.
*/
explicit WebcamReader(const int webcamIndex = 0, const Point<int> webcamResolution = Point<int>{});
explicit WebcamReader(const int webcamIndex = 0, const Point<int> webcamResolution = Point<int>{}, const double fps = 30.);
~WebcamReader();
......@@ -30,7 +31,10 @@ namespace op
double get(const int capProperty);
void set(const int capProperty, const double value);
private:
double mFps;
long long mFrameNameCounter;
cv::Mat mBuffer;
std::mutex mBufferMutex;
......
......@@ -777,8 +777,7 @@ namespace op
// Write frames as *.avi video on hard disk
if (!wrapperStructOutput.writeVideo.empty() && wrapperStructInput.producerSharedPtr != nullptr)
{
const auto originalVideoFps = (wrapperStructInput.producerSharedPtr->getType() != ProducerType::Webcam
&& wrapperStructInput.producerSharedPtr->get(CV_CAP_PROP_FPS) > 0.
const auto originalVideoFps = (wrapperStructInput.producerSharedPtr->get(CV_CAP_PROP_FPS) > 0.
? wrapperStructInput.producerSharedPtr->get(CV_CAP_PROP_FPS) : 30.);
const auto videoSaver = std::make_shared<VideoSaver>(
wrapperStructOutput.writeVideo, CV_FOURCC('M','J','P','G'), originalVideoFps, finalOutputSize
......
......@@ -118,4 +118,16 @@ namespace op
return 0.;
}
}
void VideoCaptureReader::set(const int capProperty, const double value)
{
try
{
mVideoCapture.set(capProperty, value);
}
catch (const std::exception& e)
{
error(e.what(), __LINE__, __FUNCTION__, __FILE__);
}
}
}
......@@ -6,8 +6,9 @@
namespace op
{
WebcamReader::WebcamReader(const int webcamIndex, const Point<int> webcamResolution) :
WebcamReader::WebcamReader(const int webcamIndex, const Point<int> webcamResolution, const double fps) :
VideoCaptureReader{webcamIndex},
mFps{fps},
mFrameNameCounter{-1}
{
try
......@@ -68,6 +69,8 @@ namespace op
{
if (capProperty == CV_CAP_PROP_POS_FRAMES)
return (double)mFrameNameCounter;
else if (capProperty == CV_CAP_PROP_FPS)
return mFps;
else
return VideoCaptureReader::get(capProperty);
}
......@@ -78,6 +81,21 @@ namespace op
}
}
void WebcamReader::set(const int capProperty, const double value)
{
try
{
if (capProperty == CV_CAP_PROP_FPS)
mFps = value;
else
VideoCaptureReader::set(capProperty, value);
}
catch (const std::exception& e)
{
error(e.what(), __LINE__, __FUNCTION__, __FILE__);
}
}
cv::Mat WebcamReader::getRawFrame()
{
try
......@@ -100,7 +118,7 @@ namespace op
else
{
lock.unlock();
std::this_thread::sleep_for(std::chrono::microseconds{10});
std::this_thread::sleep_for(std::chrono::microseconds{5});
}
}
return cvMat;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册