Apollo 11.0
自动驾驶开放平台
hm_matcher.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
17
18#include <string>
19#include <utility>
20
21#include "modules/perception/radar_detection/proto/matcher_config.pb.h"
22
23#include "cyber/common/file.h"
24#include "cyber/common/log.h"
27
28namespace apollo {
29namespace perception {
30namespace radar {
31
32bool HMMatcher::Init(const MatcherInitOptions &options) {
33 std::string config_file =
34 GetConfigFile(options.config_path, options.config_file);
35 MatcherConfig config_params;
36 ACHECK(cyber::common::GetProtoFromFile(config_file, &config_params))
37 << "Failed to parse MatcherConfig config file.";
38 double max_match_distance = config_params.max_match_distance();
39 double bound_match_distance = config_params.bound_match_distance();
40 BaseMatcher::SetMaxMatchDistance(max_match_distance);
41 BaseMatcher::SetBoundMatchDistance(bound_match_distance);
42 return true;
43}
44
45// @brief match radar objects to tracks
46// @params[IN] radar_tracks: global tracks
47// @params[IN] radar_frame: current radar frame
48// @params[IN] options: matcher options for future use
49// @params[OUT] assignments: matched pair of tracks and measurements
50// @params[OUT] unassigned_tracks: unmatched tracks
51// @params[OUT] unassigned_objects: unmatched objects
52// @return nothing
53bool HMMatcher::Match(const std::vector<RadarTrackPtr> &radar_tracks,
54 const base::Frame &radar_frame,
55 const TrackObjectMatcherOptions &options,
56 std::vector<TrackObjectPair> *assignments,
57 std::vector<size_t> *unassigned_tracks,
58 std::vector<size_t> *unassigned_objects) {
59 IDMatch(radar_tracks, radar_frame, assignments, unassigned_tracks,
60 unassigned_objects);
61 TrackObjectPropertyMatch(radar_tracks, radar_frame, assignments,
62 unassigned_tracks, unassigned_objects);
63 return true;
64}
65
67 double track_timestamp,
68 const base::ObjectPtr &radar_object,
69 double radar_timestamp) {
70 double dist = 0.5 * DistanceBetweenObs(track_object, track_timestamp,
71 radar_object, radar_timestamp) +
72 0.5 * DistanceBetweenObs(radar_object, radar_timestamp,
73 track_object, track_timestamp);
74
76}
77
78void HMMatcher::TrackObjectPropertyMatch(
79 const std::vector<RadarTrackPtr> &radar_tracks,
80 const base::Frame &radar_frame, std::vector<TrackObjectPair> *assignments,
81 std::vector<size_t> *unassigned_tracks,
82 std::vector<size_t> *unassigned_objects) {
83 if (unassigned_tracks->empty() || unassigned_objects->empty()) {
84 return;
85 }
86 std::vector<std::vector<double>> association_mat(unassigned_tracks->size());
87 for (size_t i = 0; i < association_mat.size(); ++i) {
88 association_mat[i].resize(unassigned_objects->size(), 0);
89 }
90 ComputeAssociationMat(radar_tracks, radar_frame, *unassigned_tracks,
91 *unassigned_objects, &association_mat);
92
93 // from perception-common
94 algorithm::SecureMat<double> *global_costs =
95 hungarian_matcher_.mutable_global_costs();
96 global_costs->Resize(unassigned_tracks->size(), unassigned_objects->size());
97 for (size_t i = 0; i < unassigned_tracks->size(); ++i) {
98 for (size_t j = 0; j < unassigned_objects->size(); ++j) {
99 (*global_costs)(i, j) = association_mat[i][j];
100 }
101 }
102 std::vector<TrackObjectPair> property_assignments;
103 std::vector<size_t> property_unassigned_tracks;
104 std::vector<size_t> property_unassigned_objects;
105 hungarian_matcher_.Match(
108 &property_assignments, &property_unassigned_tracks,
109 &property_unassigned_objects);
110
111 for (size_t i = 0; i < property_assignments.size(); ++i) {
112 size_t gt_idx = unassigned_tracks->at(property_assignments[i].first);
113 size_t go_idx = unassigned_objects->at(property_assignments[i].second);
114 assignments->push_back(std::pair<size_t, size_t>(gt_idx, go_idx));
115 }
116 std::vector<size_t> temp_unassigned_tracks;
117 std::vector<size_t> temp_unassigned_objects;
118 for (size_t i = 0; i < property_unassigned_tracks.size(); ++i) {
119 size_t gt_idx = unassigned_tracks->at(property_unassigned_tracks[i]);
120 temp_unassigned_tracks.push_back(gt_idx);
121 }
122 for (size_t i = 0; i < property_unassigned_objects.size(); ++i) {
123 size_t go_idx = unassigned_objects->at(property_unassigned_objects[i]);
124 temp_unassigned_objects.push_back(go_idx);
125 }
126 *unassigned_tracks = temp_unassigned_tracks;
127 *unassigned_objects = temp_unassigned_objects;
128}
129
130void HMMatcher::ComputeAssociationMat(
131 const std::vector<RadarTrackPtr> &radar_tracks,
132 const base::Frame &radar_frame,
133 const std::vector<size_t> &unassigned_tracks,
134 const std::vector<size_t> &unassigned_objects,
135 std::vector<std::vector<double>> *association_mat) {
136 double frame_timestamp = radar_frame.timestamp;
137 for (size_t i = 0; i < unassigned_tracks.size(); ++i) {
138 for (size_t j = 0; j < unassigned_objects.size(); ++j) {
139 const base::ObjectPtr &track_object =
140 radar_tracks[unassigned_tracks[i]]->GetObs();
141 const base::ObjectPtr &frame_object =
142 radar_frame.objects[unassigned_objects[j]];
143 double track_timestamp =
144 radar_tracks[unassigned_tracks[i]]->GetTimestamp();
145 double distance_forward = DistanceBetweenObs(
146 track_object, track_timestamp, frame_object, frame_timestamp);
147 double distance_backward = DistanceBetweenObs(
148 frame_object, frame_timestamp, track_object, track_timestamp);
149 association_mat->at(i).at(j) =
150 0.5 * distance_forward + 0.5 * distance_backward;
151 }
152 }
153}
154
155double HMMatcher::DistanceBetweenObs(const base::ObjectPtr &obs1,
156 double timestamp1,
157 const base::ObjectPtr &obs2,
158 double timestamp2) {
159 double time_diff = timestamp2 - timestamp1;
160 return (obs2->center - obs1->center -
161 obs1->velocity.cast<double>() * time_diff)
162 .head(2)
163 .norm();
164}
165
167
168} // namespace radar
169} // namespace perception
170} // namespace apollo
#define PERCEPTION_REGISTER_MATCHER(name)
void Match(T cost_thresh, OptimizeFlag opt_flag, std::vector< std::pair< size_t, size_t > > *assignments, std::vector< size_t > *unassigned_rows, std::vector< size_t > *unassigned_cols)
void Resize(const size_t resize_height, const size_t resize_width)
virtual void IDMatch(const std::vector< RadarTrackPtr > &radar_tracks, const base::Frame &radar_frame, std::vector< TrackObjectPair > *assignments, std::vector< size_t > *unassigned_tracks, std::vector< size_t > *unassigned_objects)
Target association by id.
static void SetBoundMatchDistance(double dist)
Set the Bound Match Distance
static double GetBoundMatchDistance()
Get the Bound Match Distance
static double GetMaxMatchDistance()
Get the Max Match Distance
static void SetMaxMatchDistance(double dist)
Set the Max Match Distance
bool Init(const MatcherInitOptions &options) override
Init HMMatcher config
Definition hm_matcher.cc:32
bool Match(const std::vector< RadarTrackPtr > &radar_tracks, const base::Frame &radar_frame, const TrackObjectMatcherOptions &options, std::vector< TrackObjectPair > *assignments, std::vector< size_t > *unassigned_tracks, std::vector< size_t > *unassigned_objects) override
match radar objects to tracks
Definition hm_matcher.cc:53
bool RefinedTrack(const base::ObjectPtr &track_object, double track_timestamp, const base::ObjectPtr &radar_object, double radar_timestamp) override
After the IDMatch, then track targets based on their features.
Definition hm_matcher.cc:66
#define ACHECK(cond)
Definition log.h:80
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
std::shared_ptr< Object > ObjectPtr
Definition object.h:127
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
Definition util.cc:80
class register implement
Definition arena_queue.h:37