rospy - strange behavior while publishing images
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)
rospy.spin()
def image_callback(msg):
cv2_img = bridge.imgmsg_to_cv2(msg, "bgr8")
time.sleep(1)
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
this is weird. try rospy.sleep(1.). Totally not sure if this will help :)
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.