AttributeError: 'list' object has no attribute '...'
Hello, I created a subscriber node to get data from a topic. Topic broadcasts humans on the camera in a list called human_list. I want to read this data with below code. However when I rosrun it I get an error stating this
[ERROR] [1522830692.692015]: bad callback: <function callback at 0x7f7c0598aaa0>
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 "/home/robolab3/catkin_ws/src/hand_raise_detector/scripts/armraiselistener.py", line 8, in callback
x = human.body_key_points_with_prob.x
AttributeError: 'list' object has no attribute 'x'
rosmsg show openpose_ros_msgs/OpenPoseHumanList
is as follows:
msgs/OpenPoseHumanList
std_msgs/Header header
uint32 seq
time stamp
string frame_id
std_msgs/Header rgb_image_header
uint32 seq
time stamp
string frame_id
int32 num_humans
openpose_ros_msgs/OpenPoseHuman[] human_list
int32 num_body_key_points_with_non_zero_prob
openpose_ros_msgs/PointWithProb[18] body_key_points_with_prob
float64 x
float64 y
float64 prob
My code to subscribe this topic is as follows. I appreciate your help to identify what about my code is wrong.
import rospy
from openpose_ros_msgs.msg import OpenPoseHumanList
def callback(msg):
for human in msg.human_list:
x = human.body_key_points_with_prob.x
y = human.body_key_points_with_prob.y
prob = human.body_key_points_with_prob.prob
rospy.loginfo('x: {}, y: {}, prob: {}'.format(x, y, prob))
def armraiselistener():
rospy.init_node('armraiselistener', anonymous=True)
rospy.Subscriber("/openpose_ros/human_list", OpenPoseHumanList, callback)
rospy.spin()
if __name__== '__main__':
armraiselistener()