ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

rospy - strange behavior while publishing images

asked 2019-02-12 08:28:13 -0600

darioc1985 gravatar image

Dear all,

I have a problem with the following code. In particular, I would like to have a node made by a simple publisher/subscriber in order to read images, do some processing and publish an output.

image_pub = rospy.Publisher("/mycode/outputImage", Image, queue_size=1)

def main():
   rospy.init_node('node', anonymous=True)
   print('Subscribed. Waiting for images.')
   rospy.Subscriber("/usb_cam/image_raw", Image, image_callback, None, queue_size=1)

def image_callback(msg):
   cv2_img = bridge.imgmsg_to_cv2(msg, "bgr8")
   image_pub.publish(bridge.cv2_to_imgmsg(cv2_img, "bgr8"))

In the node that I created to visualize the output (but also if I publish other message made by simple vectors, I see a continuous delay of around 10 seconds, instead of a static delay of 1 second as I was expecting. Moreover, it seems that it is not throwing frames and process the last one, but all the frames that are being processed are the old one captured. If I remove the sleep(1), I get a correct streaming effect. Is this a normal effect? In case it is, since my goal is to do some processing expected to run at 4/5 fps without ROS, how can I do in order to process the last frame grabbed instead of these very old frames?

Thank you

edit retag flag offensive close merge delete


this is weird. try rospy.sleep(1.). Totally not sure if this will help :)

kolya_rage gravatar image kolya_rage  ( 2019-02-12 16:36:02 -0600 )edit

thank you for your help. The problem is that if I put any form of computation, I see this delay. In my code, I have some computation (of around 200msec) instead of the sleep. But with both sleep and my code cause that the next frame processed is some that seems old instead of the current one.

darioc1985 gravatar image darioc1985  ( 2019-02-12 17:32:47 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-02-14 02:38:51 -0600

darioc1985 gravatar image

Declaring the subscriber in such a way

self.subscriber = rospy.Subscriber("/usb_cam/image_raw/compressed", CompressedImage, self.image_callback, None, queue_size=1, buff_size=921600)

the program seems to have the right behavior. I am wondering if the buffer size must always be properly passed, or it is an anmalous behavior of ROS, also in the light of

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2019-02-12 08:24:37 -0600

Seen: 206 times

Last updated: Feb 14 '19