'String' object has no attribute 'splitlines'
I'm trying to parse the output of ros_caffe and republish this in a format ready for speaking. Simon Birrell's node filter_caffe does this but I'm getting the error in the headline. https://github.com/SimonBirrell/filte...
import sys
print
print sys.path
print
import rospy
from filter_caffe import filter_caffe_message
from std_msgs.msg import String
Pub = 0
def received_caffe_message(data):
global Pub
filtered_message = filter_caffe_message(data)
if filtered_message:
Pub.publish(filtered_message)
rospy.loginfo(filtered_message)
else:
rospy.loginfo("No good hit.")
I think it's related to this portion of the code:
def filter_caffe_message(caffe_message):
lines = caffe_message.splitlines()
if (len(lines) == 0):
return None
first_line = lines[0]
tokens = first_line.split(" ")
if (len(tokens)<2):
return None
raw_probability = tokens[1].split("[")
if (len(raw_probability)<2):
return None
probability = float(raw_probability[1])
if (probability>PROBABILITY_THRESHOLD):
object_list = first_line.split(" - ")[1][10:]
first_object = object_list.split(",")[0]
return first_object
return None
This is the exact error I'm getting:
[ERROR] [WallTime: 1491028835.534480] bad callback: <function received_caffe_message at 0xb672e6b0>
Traceback (most recent call last):
File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/topics.py", line 720, in _invoke_callback
cb(msg)
File "/home/ubuntu/catkin_ws/src/filter_caffe/nodes/filter_caffe2.py", line 24, in received_caffe_message
filtered_message = filter_caffe_message(data)
File "<string>", line 28, in filter_caffe_message
AttributeError: 'String' object has no attribute 'splitlines'
I understand that splitlines() only works with string objects but I thought that caffe_message was a string?
Thanks!
Will