Autoware.Auto
data_association.hpp
Go to the documentation of this file.
1 // Copyright 2021 Apex.AI, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #ifndef TRACKING__DATA_ASSOCIATION_HPP_
15 #define TRACKING__DATA_ASSOCIATION_HPP_
16 
18 
19 #include <autoware_auto_msgs/msg/tracked_dynamic_object_array.hpp>
20 #include <autoware_auto_msgs/msg/detected_dynamic_object_array.hpp>
23 
24 #include <experimental/optional>
25 #include <limits>
26 #include <map>
27 #include <vector>
28 
29 namespace autoware
30 {
31 namespace perception
32 {
33 namespace tracking
34 {
35 
37 
39 class TRACKING_PUBLIC DataAssociationConfig
40 {
41 public:
47  DataAssociationConfig(const float max_distance, const float max_area_ratio);
48 
49  inline float get_max_distance_squared() const {return m_max_distance_squared;}
50 
51  inline float get_max_area_ratio() const {return m_max_area_ratio;}
52 
53  inline float get_max_area_ratio_inv() const {return m_max_area_ratio_inv;}
54 
55 private:
56  float m_max_distance;
57  float m_max_distance_squared;
58  float m_max_area_ratio;
59  float m_max_area_ratio_inv;
60 };
61 
63 struct TRACKING_PUBLIC AssociatorResult
64 {
65  static constexpr std::size_t UNASSIGNED = std::numeric_limits<std::size_t>::max();
69  std::vector<std::size_t> track_assignments;
71  std::vector<std::size_t> unassigned_detection_indices;
73  std::vector<std::size_t> unassigned_track_indices;
74 };
75 
76 
79 class TRACKING_PUBLIC Associator
80 {
81 public:
84  explicit Associator(const DataAssociationConfig & association_cfg);
85 
90  AssociatorResult assign(
91  const autoware_auto_msgs::msg::DetectedDynamicObjectArray & detections, const
92  autoware_auto_msgs::msg::TrackedDynamicObjectArray & tracks);
93 
94 private:
96  void reset();
97 
99  void compute_weights(
100  const autoware_auto_msgs::msg::DetectedDynamicObjectArray & detections,
101  const autoware_auto_msgs::msg::TrackedDynamicObjectArray & tracks);
102 
104  bool consider_associating(
105  const autoware_auto_msgs::msg::DetectedDynamicObject & detection, const
106  autoware_auto_msgs::msg::TrackedDynamicObject & track) const;
107 
109  void set_weight(const float weight, const size_t det_idx, const size_t track_idx);
110 
112  AssociatorResult extract_result() const;
113 
114  DataAssociationConfig m_association_cfg;
116  // Hungarian assigner expects a fat matrix (not tall). Bool tracks if tracks are rows or cols
117  bool m_are_tracks_rows;
118  size_t m_num_tracks;
119  size_t m_num_detections;
120 };
121 
122 
123 } // namespace tracking
124 } // namespace perception
125 } // namespace autoware
126 
127 #endif // TRACKING__DATA_ASSOCIATION_HPP_
autoware::perception::tracking::assigner_idx_t
autoware::fusion::hungarian_assigner::index_t assigner_idx_t
Definition: data_association.hpp:36
visibility_control.hpp
autoware::fusion::hungarian_assigner::index_t
Eigen::Index index_t
indexing matches what matrices use
Definition: hungarian_assigner.hpp:49
autoware::perception::tracking::DataAssociationConfig::get_max_distance_squared
float get_max_distance_squared() const
Definition: data_association.hpp:49
tracker_types.hpp
autoware::perception::tracking::AssociatorResult::unassigned_track_indices
std::vector< std::size_t > unassigned_track_indices
Indices of tracks that are not associated to any detections.
Definition: data_association.hpp:73
autoware
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
autoware::perception::tracking::AssociatorResult
Struct to store results after the assignment is done.
Definition: data_association.hpp:63
autoware::perception::tracking::Associator
Class to perform data association between existing tracks and new detections using mahalanobis distan...
Definition: data_association.hpp:79
hungarian_assigner.hpp
Header for hungarian algorithm for optimal linear assignment.
autoware::perception::tracking::DataAssociationConfig::get_max_area_ratio_inv
float get_max_area_ratio_inv() const
Definition: data_association.hpp:53
autoware::perception::tracking::AssociatorResult::track_assignments
std::vector< std::size_t > track_assignments
This vector stores the detection index associated with each track idx. So, it should have Associator:...
Definition: data_association.hpp:69
autoware::perception::tracking::DataAssociationConfig::get_max_area_ratio
float get_max_area_ratio() const
Definition: data_association.hpp:51
autoware::perception::tracking::AssociatorResult::unassigned_detection_indices
std::vector< std::size_t > unassigned_detection_indices
Indices of detections that are not associated to any tracks.
Definition: data_association.hpp:71
autoware::perception::tracking::DataAssociationConfig
Class to create configuration parameters for data association.
Definition: data_association.hpp:39
autoware::fusion::hungarian_assigner::hungarian_assigner_c< MAX_NUM_TRACKS >