Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add downsample_rate param and use image header header time. #274 #947

Open
wants to merge 2 commits into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions image_view/include/image_view/extract_images_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class ExtractImagesNode
int count_;
rclcpp::Time _time;
double sec_per_frame_;
double downsample_rate_;

void image_cb(const sensor_msgs::msg::Image::ConstSharedPtr & msg);
};
Expand Down
16 changes: 12 additions & 4 deletions image_view/src/extract_images_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace image_view

ExtractImagesNode::ExtractImagesNode(const rclcpp::NodeOptions & options)
: rclcpp::Node("extract_images_node", options),
filename_format_(""), count_(0), _time(this->now())
filename_format_(""), count_(0), _time(0.0)
{
// For compressed topics to remap appropriately, we need to pass a
// fully expanded and remapped topic name to image_transport
Expand Down Expand Up @@ -96,6 +96,14 @@ ExtractImagesNode::ExtractImagesNode(const rclcpp::NodeOptions & options)
this->declare_parameter<std::string>("filename_format", std::string("frame%04i.jpg"));
filename_format_ = this->get_parameter("filename_format").as_string();

this->declare_parameter<double>("downsample_rate", 1.0);
downsample_rate_ = this->get_parameter("downsample_rate").as_double();

if (downsample_rate_ < 1.0) {
RCLCPP_WARN(
this->get_logger(), "extract_images: downsample_rate < 1 does not make any sense.");
}

this->declare_parameter<double>("sec_per_frame", 0.1);
sec_per_frame_ = this->get_parameter("sec_per_frame").as_double();

Expand All @@ -122,10 +130,10 @@ void ExtractImagesNode::image_cb(const sensor_msgs::msg::Image::ConstSharedPtr &
RCLCPP_ERROR(this->get_logger(), "Unable to convert %s image to bgr8", msg->encoding.c_str());
}

rclcpp::Duration delay = this->now() - _time;
double delay = msg->header.stamp.sec - _time.seconds();

if (delay.seconds() >= sec_per_frame_) {
_time = this->now();
if (delay >= downsample_rate_ * sec_per_frame_) {
_time = msg->header.stamp;

if (!image.empty()) {
std::string filename = string_format(filename_format_, count_);
Expand Down