0
$\begingroup$

Rosanswers logo

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.


Originally posted by DanielSeita on ROS Answers with karma: 46 on 2017-12-03

Post score: 1


Original comments

Comment by jayess on 2017-12-03:
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...

Comment by clyde on 2017-12-03:
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.

Comment by DanielSeita on 2017-12-03:
@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.

Comment by jayess on 2017-12-03:
You would have to increase it from what ever driver/node your camera is using/publishing from.

Comment by DanielSeita on 2017-12-04:
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.

Comment by jayess on 2017-12-04:
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?

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by DanielSeita with karma: 46 on 2018-05-16

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.