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

Update extract_images_sync to add sec_per_frame parameter #920

Merged
merged 4 commits into from
Jan 31, 2024
Merged
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
23 changes: 22 additions & 1 deletion image_view/scripts/extract_images_sync
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import cv_bridge
import rclpy

from rclpy.node import Node
from rclpy.duration import Duration
from sensor_msgs.msg import Image
from message_filters import ApproximateTimeSynchronizer, TimeSynchronizer, Subscriber

Expand All @@ -51,10 +52,19 @@ class ExtractImagesSync(Node):
super().__init__('extract_images_sync')
self.get_logger().info('Extract_Images_Sync Node has been started')
self.seq = 0
self.last_frame_time = self.get_clock().now()

self.fname_fmt = self.declare_parameter(
'filename_format', 'frame%04i_%i.jpg').value
'filename_format', 'frame%04i_%i.jpg').value

# Do not scale dynamically by default.
self.do_dynamic_scaling = self.declare_parameter(
'do_dynamic_scaling', False).value

# Limit the throughput to 10fps by default.
self.sec_per_frame = self.declare_parameter(
'sec_per_frame', 0.0).value

img_topics = self.declare_parameter('inputs', None).value

if img_topics is None:
Expand All @@ -80,6 +90,17 @@ Typical command-line usage:
sync.registerCallback(self.save)

def save(self, *imgmsgs):
delay = self.get_clock().now() - self.last_frame_time

# Decimation is enabled if it is set to greater than
# zero. If it is enabled, exit if delay is less than
# the decimation rate specified.
if (self.sec_per_frame > 0) and (delay < Duration(seconds=self.sec_per_frame)):
return

# Update the current time
self.last_frame_time = self.get_clock().now()

seq = self.seq
bridge = cv_bridge.CvBridge()
for i, imgmsg in enumerate(imgmsgs):
Expand Down
Loading