eric-wieser / ros_numpy

Tools for converting ROS messages to and from numpy arrays
MIT License
305 stars 159 forks source link

TypeError: numpy_to_image() takes exactly 2 arguments (1 given) #17

Open mymrblack opened 4 years ago

mymrblack commented 4 years ago

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 4 years ago

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