因此,我尝试使用 Python 在 ROS 中创建一个发布图像的程序,但我导入了两个都称为“图像”的东西。当我运行程序时,我收到此错误消息。
File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/topics.py", line 812, in __init__
super(Publisher, self).__init__(name, data_class, Registration.PUB)
File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/topics.py", line 138, in __init__
raise ValueError("data_class [%s] is not a class"%data_class)
ValueError: data_class [<module 'PIL.Image' from '/usr/lib/python2.7/dist-packages/PIL/Image.pyc'>] is not a class
当我取出导入 PIL Image 和 ImageFilter 的行、初始化 image1 的行和发布 image1 的行时,程序运行良好,因为(我认为)两个导入的 Image 对象之间没有混淆。有没有办法告诉程序区分两个图像?
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import Image
from PIL import Image, ImageFilter
def camera():
pub = rospy.Publisher('rgb', Image, queue_size=10)
image1 = Image.open('dog.png')
pub.publish(image1)
if __name__ == '__main__':
try:
camera()
except rospy.ROSInterruptException:
pass