-1

python3

def __init__(self):
        super().__init__('object_tracking')
        # Declare ROS parameters
        self.declare_parameters(namespace='',
                                parameters=[('qos_length',0),
                                            ('topic.untracked_obj',''),
                                            ('topic.rgb_image',''),
                                            ('topic.tracked_obj',''),
                                            ('obj_class.id',[]),
                                            ('obj_class.name',[]),
                                            ('display',True),
                                            ('frame_id.tracked_obj','')])
        self.nodeParams()
        qos_length = self.get_parameter('qos_length').get_parameter_value().integer_value
        qos_profile = QoSProfile(depth=qos_length,
                                 history=QoSHistoryPolicy.KEEP_LAST,
                                 reliability=QoSReliabilityPolicy.RELIABLE)
        # Load cv_bridge
        self.bridge = CvBridge()
        # Create instance of SORT
        self.mot_tracker = Sort()
        # Create Subscribers
        obj_topic = self.get_parameter('topic.untracked_obj').get_parameter_value().string_value
        self.obj_sub = mf.Subscriber(self,ObjectArray,obj_topic,qos_profile=qos_profile)
        rgb_topic = self.get_parameter('topic.rgb_image').get_parameter_value().string_value
        self.rgb_sub = mf.Subscriber(self,Image,rgb_topic,qos_profile=qos_profile)
        # Apply message filter
        self.timestamp_sync = mf.TimeSynchronizer([self.obj_sub,self.rgb_sub],queue_size=qos_length)
        self.timestamp_sync.registerCallback(self.objCallback)
        # Create Publishers
        obj_topic = self.get_parameter('topic.tracked_obj').get_parameter_value().string_value
        self.obj_pub = self.create_publisher(ObjectArray,obj_topic,qos_profile)

    def nodeParams(self):
        #print('1')
        self.display = self.get_parameter('display').get_parameter_value().bool_value
        class_id = self.get_parameter('obj_class.id').get_parameter_value().integer_array_value
        #print(class_id)
        class_name = self.get_parameter('obj_class.name').get_parameter_value().integer_array_value
        #print(class_name)
        self.class_dict = {}
        #for name in class_name:
        '''#for i,id_ in enumerate(class_id):
            #print('2')
            #self.class_dict = class_name [name]
            #print('3')'''
        for i,id_ in enumerate(class_id):
            self.class_dict[int(id_)] = class_name[i]

I'm not sure what's going on...I'd like to try object tracking in Carla 0.9.13 with ros2 foxy in Python 3.8. Could you please help me?

[object_tracking.py-3] self.nodeParams() [object_tracking.py-3] File "/home/smit/ros2_ws/install/carla_simulation/lib/carla_simulation/object_tracking.py", line 64, in nodeParams [object_tracking.py-3] self.class_dict[int(id_)] = class_name[i] [object_tracking.py-3] IndexError: array index out of range [ERROR] [object_tracking.py-3]: process has died [pid 623526, exit code 1, cmd '/home/smit/ros2_ws/install/carla_simulation/lib/carla_simulation/object_tracking.py --ros-args --params-file /home/smit/ros2_ws/install/carla_simulation/share/carla_simulation/config/params.yaml'].

1 Answers1

0

You are pobably using the returned hierarchy variable wrong. According to the specification:

In Python, hierarchy is nested inside a top level array. Use hierarchy[0][i] to access hierarchical elements of i-th contour.

https://docs.opencv.org/4.x/d3/dc0/group__imgproc__shape.html#gadf1ad6a0b82947fa1fe3c3d497f260e0

Andyza
  • 74
  • 3