ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org
Ask Your Question
0

Increase the frequency at which images are updated in a subscriber

asked 2017-12-03 17:29:32 -0500

DanielSeita gravatar image

I am using code which tracks the image of a robot. Specifically, the rospy-based code I am using is here.

Here's the relevant part of the code.

"""
The DataCollector class polls data from the rostopics periodically. It manages 
the messages that come from ros.
"""
class DataCollector:

    def __init__(self, 
             camera_left_topic="/endoscope/left/",
             camera_right_topic="/endoscope/right/",
             camera_info_str='camera_info',
             camera_im_str='image_rect_color'):

        self.left_image = None
        rospy.Subscriber(camera_left_topic + camera_im_str, Image,
                     self.left_image_callback, queue_size=1)

This segment defines the DataCollector class and subscribes to a "left image callback method" which continually updates self.left_image to be the image as seen by the robot's left camera:

def left_image_callback(self, msg):
    if rospy.is_shutdown():
        return

    self.left_image = self.bridge.imgmsg_to_cv2(msg, "rgb8")

I timed how often the left_image_callback method is called, and it updates at roughly intervals of 0.5 seconds. In other words, if the robot is moving, the self.left_image will only update every 0.5 seconds.

My question is simple: how do I increase the rate at which the image gets updated? Ideally I can get this to be 0.2 seconds, if possible. If it matters, I'm using ros indigo, and the robot is Intuitive Surgical da Vinci.

edit retag flag offensive close merge delete

Comments

Callbacks get called when they receive data. So, you'd have to publish the images at the rate you want the images to be updated at. Also, if rospy is shutdown, I don't believe that your callback will be executed...

jayess gravatar imagejayess ( 2017-12-03 19:08:39 -0500 )edit

Perhaps the image processing is CPU-bound, in either the publisher or subscriber? You might also be IO-bound somewhere, particularly if the image data has to travel over wifi.

clyde gravatar imageclyde ( 2017-12-03 19:21:17 -0500 )edit

@jayess Thank you for the comment. How do I find where the images are published? Is this part of the launch files? (Sorry, I am new to ROS) Also @clyde the images should not be through wifi since the computer which records the images is directly connected to the robot computer.

DanielSeita gravatar imageDanielSeita ( 2017-12-03 19:27:04 -0500 )edit

You would have to increase it from what ever driver/node your camera is using/publishing from.

jayess gravatar imagejayess ( 2017-12-03 19:33:51 -0500 )edit
1

I resolved it, it was because my callback images were processing the images. That takes up precious time. I commented out any image processing code and now I can get images updated at 0.1 seconds.

DanielSeita gravatar imageDanielSeita ( 2017-12-04 18:05:34 -0500 )edit

Ok that makes sense. I tend to think of callbacks as interrupts. You want to keep them short and and not do too much in them. Perhaps you can write up your solution as an answer here?

jayess gravatar imagejayess ( 2017-12-04 18:23:19 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-05-16 17:26:47 -0500

DanielSeita gravatar image

The issue I was having here was that I was implementing a complicated image processing pipeline (using opencv, I was filtering the image, drawing boundaries, etc.) and that was slowing things down. It was not the publishing rate.

The solution is to save those images in a separate directory and then process them afterwards, or use a separate thread for image processing.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-12-03 17:29:32 -0500

Seen: 98 times

Last updated: May 16 '18