Getting error while publishing sensor_msgs/Image.msg type on topic and recording in bag file.
Hi, I am trying to record bag file through the command
rosbag record -O /home/maq/MAQ/my_seq3.bag /camera/rgb/image_color amera/rgb/camera_info /camera/depth/image
from terminal. I am running my nodes and publish on the above mentioned topics, for which the code is,
rgb_image = rgb_image.astype('uint8')
rgb = CvBridge().cv2_to_imgmsg(rgb_image, encoding="rgb8")
depth = CvBridge().cv2_to_imgmsg(depth_gt, encoding="32FC1")
depth_msg = make_depth_msg(depth, rgb_time_sec, rgb_time_nsec, test_image)
rgb_msg = make_rgb_msg(rgb, rgb_time_sec, rgb_time_nsec, test_image)
pub_depth = rospy.Publisher('/camera/depth/image', Image, queue_size=1000)
pub_camera_info = rospy.Publisher('/camera/rgb/camera_info', CameraInfo, queue_size=1000)
pub_rgb = rospy.Publisher('/camera/rgb/image_color', Image, queue_size=1000)
pub_depth.publish(depth_msg)
pub_camera_info.publish(camera_info_msg)
pub_rgb.publish(rgb_msg)
Once I run this python file in pycharm it is publishing on all the topics without any error, but once I try to record them in bag file through the above mentioned command from terminal I get the following error.
Traceback (most recent call last):
File "/home/maq/PycharmProjects/Deeper-Depth-Prediction_2/pytorch/result_collection_sequence.py", line 46, in <module>
pub_depth.publish(depth_msg)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 886, in publish
raise ROSSerializationException(str(e))
rospy.exceptions.ROSSerializationException: field data must be a list or tuple type
Can anyone help me please. Regards.
EDIT 1:
Sorry i should have added definitions of
makedepthmsg(..)
and
makergbmsg(..)
earlier:
def make_rgb_msg(rgb, rgb_time_sec, rgb_time_nsec, test_image):
rgb_msg = Image()
rgb_msg.header.seq = test_image
rgb_msg.header.frame_id = "/openni_rgb_optical_frame"
rgb_msg.header.stamp.secs = rgb_time_sec
rgb_msg.header.stamp.nsecs = rgb_time_nsec
rgb_msg.step = 1920
rgb_msg.is_bigendian = 0
rgb_msg.encoding = 'rgb8'
rgb_msg.data = rgb
return rgb_msg
def make_depth_msg(depth, rgb_time_sec, rgb_time_nsec, test_image):
depth_msg = Image()
depth_msg.header.seq = test_image
depth_msg.header.frame_id = "/openni_rgb_optical_frame"
depth_msg.header.stamp.secs = rgb_time_sec
depth_msg.header.stamp.nsecs = rgb_time_nsec-20000000
depth_msg.step = 2560
depth_msg.is_bigendian = 0
depth_msg.encoding = '32FC1'
depth_msg.data = depth
return depth_msg
And gvdhoorn is right with rostopic echo /camera/depth/image
same problems occurs.
Now added .step
, .is_bigendian
and .encoding
as well in each definition. But problem is same.
Asked by Ghost on 2019-04-04 04:02:09 UTC
Comments
I have the impression the issue is in your script, not in
rosbag
. The title of your question seems to suggest there is a problem with recording (ie: withrosbag
).It's likely that using
rostopic echo ..
will result in the same problem.I suspect
make_depth_msg(..)
and/ormake_rgb_msg(..)
.Asked by gvdhoorn on 2019-04-04 05:00:23 UTC
Thanks for early reply. I have edited my question with their definitions.
Asked by Ghost on 2019-04-04 05:17:38 UTC
Could be this line in
make_depth_msg(..)
:If you don't set
depth_msg.data
, does the problem still occur?And just to check:
test_image
is an integer, correct?Asked by gvdhoorn on 2019-04-04 05:33:46 UTC
Yes it is this line
depth_msg.data = depth
andrgb_msg.data = rgb
this line in definitions. But by these i want to savedepth
andmsg
data insensor_msgs/Image.msg
format and then publish it. What is wrong in the way i am doing. And yestest_image
is an integer.Thanks again
Asked by Ghost on 2019-04-04 05:40:46 UTC
I don't know if you have already solved it, but for others, I solved this issue by converting the image into list() format before assigning to
data
field:rgb_msg.data = rgb.ravel().tolist()
anddepth_msg.data = depth.ravel().tolist()
.Asked by francesco94 on 2020-05-25 08:34:18 UTC