TypeError: numpy_to_image() takes exactly 2 arguments (1 given)
mymrblack opened this issue · 1 comments
mymrblack commented
Hi, I am using ros kenetic in Linux 16.04 LTS, and trying to convert numpy array to ros image message. I used the code like:
img_msg_to_be_publish = ros_numpy.msgify(Image, img_array)
But I get the error:
[ERROR] [1575536397.176668]: bad callback: <bound method Subscriber.callback of <message_filters.Subscriber object at 0x7f03cbe1cbd0>>
Traceback (most recent call last):
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 75, in callback
self.signalMessage(msg)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 57, in signalMessage
cb(*(msg + args))
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 224, in add
self.signalMessage(*msgs)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 57, in signalMessage
cb(*(msg + args))
File "/home/robot/catkin_ws/src/pose_tracking/scripts/pose_tracker.py", line 87, in callback
img_msg_to_be_publish = ros_numpy.msgify(Image, processed_img)
File "/home/robot/catkin_ws/src/ros_numpy/src/ros_numpy/registry.py", line 51, in msgify
return conv(numpy_obj, *args, **kwargs)
TypeError: numpy_to_image() takes exactly 2 arguments (1 given)
Do I use it in a wrong way? Thank you in advance
dronedojo commented
Hi mymrblack,
I was able to fix this by supplying the 'encoding' argument. My incoming Image message used the encoding of 'rgb8', so successfully running your function would look like (assuming encoding of 'rgb8'):
img_msg_to_be_publish = ros.numpy.msgify(Image, img_array, encoding='rbg8')