"integer out of range for 'L' format code" saving image_raw to rosbag (python)

asked 2021-08-13 10:10:48 -0500

ronsm gravatar image

I have some topics which are broadcast by video_stream_opencv from RTSP streams to a set of image_raw topics, e.g. I get resulting topics as so (output from rostopic list -v):

/ch01/image_raw [sensor_msgs/Image] 1 publisher

I have a ROS package, in python, which has to at some point subscribe to these image_raw topics and save some data to a rosbag. The message import and subscriber is as so:

from sensor_msgs.msg import Image, CompressedImage
...
rospy.Subscriber(topic, Image, self.image_callback, callback_args=topic)

And the callback simply does:

    def image_callback(self, data, topic):
        if self.run:
            self.bag.write(topic, data)

The same strategy is used for a range of topics, it only doesn't work for the Image type. When my package is running, all of the other data types go into the rosbag nicely without issue. For these topics, I get this error:

[ERROR] [1628866609.663749]: bad callback: <bound method Main.image_callback of <__main__.Main instance at 0x7f6b6bbcfb40>>
Traceback (most recent call last):
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 748, in _invoke_callback
cb(msg, cb_args)
File "/home/root/catkin_ws/src/ralt_signalman/src/main.py", line 53, in image_callback
self.bag.write(topic, data)
File "/opt/ros/melodic/lib/python2.7/dist-packages/rosbag/bag.py", line 704, in write
self._stop_writing_chunk()
File "/opt/ros/melodic/lib/python2.7/dist-packages/rosbag/bag.py", line 1657, in _stop_writing_chunk
self._write_chunk_header(chunk_header)
File "/opt/ros/melodic/lib/python2.7/dist-packages/rosbag/bag.py", line 1724, in _write_chunk_header
'size':        _pack_uint32(chunk_header.uncompressed_size)
File "/opt/ros/melodic/lib/python2.7/dist-packages/rosbag/bag.py", line 1939, in _pack_uint32
def _pack_uint32(v): return struct.pack('<L', v)
error: integer out of range for 'L' format code

I assume the bad callback error is a result of the error that is shown below it. I have looked around and can only find one other instance of this problem, a similar situation, but saw no solution.

Has anyone had any experience with this issue, or has any ideas why this error would be happening? It seems like it should be straightforward to simply save the Image message to the rosbag, but maybe there is something else I need to do that I am missing.

For reference, I am using ROS in Docker containers with Ubuntu 18.04, ROS Melodic, and Python 2.7.18.

Thanks.

edit retag flag offensive close merge delete