image stream published out of order

asked 2018-02-03 13:52:44 -0600

waspinator gravatar image

updated 2018-02-06 19:25:07 -0600

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()
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()
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()


while not rospy.is_shutdown():

    image_result = cam.GetNextImage()
    if image_result.IsIncomplete():
        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")



del cam

In this example I'm waving my hand back and forth, but the images come out of order.

edit retag flag offensive close merge delete


Try compressing the image

chris_sunny gravatar imagechris_sunny ( 2018-02-07 03:37:37 -0600 )edit

Does increasing the queue_size help? Maybe make it 10 or 20.

lucasw gravatar imagelucasw ( 2018-02-07 08:18:24 -0600 )edit

@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

waspinator gravatar imagewaspinator ( 2018-02-07 09:50:23 -0600 )edit

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 (or set sequence number to something incrementing and look at that instead).

lucasw gravatar imagelucasw ( 2018-02-08 09:55:11 -0600 )edit