image stream published out of order
I'm trying to publish an image stream from a Flir/PointGrey Spinnaker camera, but images come out of order. How can I make sure that my publisher is putting data out in the right order?
If I use cv2.imshow()
to view the image instead of rqt_image_view after publishing them, they appear in order.
#! /usr/bin/env python
import PySpin
import cv2
import rospy
import sensor_msgs.msg
from cv_bridge import CvBridge
cv_bridge = CvBridge()
rospy.init_node('test')
image_publisher = rospy.Publisher(
"camera/image", sensor_msgs.msg.Image, queue_size=1
)
system = PySpin.System.GetInstance()
cam_list = system.GetCameras()
num_cameras = cam_list.GetSize()
cam = cam_list.GetBySerial("12345678")
# run_single_camera
nodemap_tldevice = cam.GetTLDeviceNodeMap()
cam.Init()
nodemap = cam.GetNodeMap()
# aquire_images
node_acquisition_mode = PySpin.CEnumerationPtr(nodemap.GetNode("AcquisitionMode"))
node_acquisition_mode_continuous = node_acquisition_mode.GetEntryByName("Continuous")
acquisition_mode_continuous = node_acquisition_mode_continuous.GetValue()
node_acquisition_mode.SetIntValue(acquisition_mode_continuous)
cam.BeginAcquisition()
while not rospy.is_shutdown():
image_result = cam.GetNextImage()
if image_result.IsIncomplete():
pass
else:
image_converted = image_result.Convert(PySpin.PixelFormat_RGB8, PySpin.DIRECTIONAL_FILTER)
image_data = image_converted.GetNDArray()
image_message = cv_bridge.cv2_to_imgmsg(image_data, encoding="rgb8")
image_publisher.publish(image_message)
image_result.Release()
cam.EndAcquisition()
cam.DeInit()
del cam
cam_list.Clear()
system.ReleaseInstance()
In this example I'm waving my hand back and forth, but the images come out of order. https://www.youtube.com/watch?v=1ggeb...
Try compressing the image
Does increasing the queue_size help? Maybe make it 10 or 20.
@chris_sunny, is there a way I compress the image in the python script, or did you mean republish it using compressed_image_transport? @lucasw, same result with a larger queue_size
If you
rostopic echo /image | grep stamp
on the same machine rqt_image_view is running do you see out of order timestamps? You could start setting the timestamp of image_message to rospy.Time.now() (or set sequence number to something incrementing and look at that instead).