Tools for converting ROS messages to and from numpy arrays. Contains two functions:
arr = numpify(msg, …) - try to get a numpy object from a message msg
= msgify(MessageType, arr, …) - try and convert a numpy object to a message
安装方式:
git clone https://github.com/eric-wieser/ros_numpy.git cd ros_numpy/ python setup.py install python3 setup.py install
使用:
from sensor_msgs.msg import Image import ros_numpy import PIL image = ros_numpy.numpify(image) image = PIL.Image.fromarray(image)
其中image是class 'sensor_msgs.msg._Image.Image’类型,使用ros_numpy下的函数将其转换为np.array,就可以利用PIL.Image.fromarray进行图像处理。
PIL和numpy array的转化
import PIL image = Image.open(“###.jpg”) # image is a PIL image array = numpy.array(image) # array is a numpy array image2 = Image.fromarray(array) # image2 is a PIL image
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)