Apollo 10.0
自动驾驶开放平台
mrf_track_object_matcher.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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 *****************************************************************************/
16
18
19#include <numeric>
20
21#include "cyber/common/file.h"
22#include "modules/perception/radar4d_detection/lib/tracker/multi_radar_fusion/proto/mrf_config.pb.h"
23
24namespace apollo {
25namespace perception {
26namespace radar4d {
27
29 const MrfTrackObjectMatcherInitOptions &options) {
30 std::string config_file = "mrf_track_object_matcher.pb.txt";
31 if (!options.config_file.empty()) {
32 config_file = options.config_file;
33 }
34 config_file = GetConfigFile(options.config_path, config_file);
36 ACHECK(cyber::common::GetProtoFromFile(config_file, &config));
37
38 foreground_matcher_ = BaseBipartiteGraphMatcherRegisterer::GetInstanceByName(
40 ACHECK(foreground_matcher_ != nullptr);
41 AINFO << "MrfTrackObjectMatcher, fg: " << foreground_matcher_->Name();
42 background_matcher_ = BaseBipartiteGraphMatcherRegisterer::GetInstanceByName(
44 ACHECK(background_matcher_ != nullptr);
45 AINFO << "MrfTrackObjectMatcher, bg: " << background_matcher_->Name();
48
50 MrfTrackObjectDistanceInitOptions distance_init_options;
51 distance_init_options.config_path = options.config_path;
52 ACHECK(track_object_distance_->Init(distance_init_options));
53
54 bound_value_ = config.bound_value();
56 return true;
57}
58
60 const MrfTrackObjectMatcherOptions &options,
61 const std::vector<TrackedObjectPtr> &objects,
62 const std::vector<MrfTrackDataPtr> &tracks,
63 std::vector<std::pair<size_t, size_t>> *assignments,
64 std::vector<size_t> *unassigned_tracks,
65 std::vector<size_t> *unassigned_objects) {
66 assignments->clear();
67 unassigned_objects->clear();
68 unassigned_tracks->clear();
69 if (objects.empty() || tracks.empty()) {
70 unassigned_objects->resize(objects.size());
71 unassigned_tracks->resize(tracks.size());
72 std::iota(unassigned_objects->begin(), unassigned_objects->end(), 0);
73 std::iota(unassigned_tracks->begin(), unassigned_tracks->end(), 0);
74 return;
75 }
76
77 BipartiteGraphMatcherOptions matcher_options;
78 matcher_options.cost_thresh = max_match_distance_;
79 matcher_options.bound_value = bound_value_;
80
82 objects[0]->is_background ? background_matcher_ : foreground_matcher_;
83
84 algorithm::SecureMat<float> *association_mat = matcher->cost_matrix();
85
86 association_mat->Resize(tracks.size(), objects.size());
87 ComputeAssociateMatrix(tracks, objects, association_mat);
88 matcher->Match(matcher_options, assignments, unassigned_tracks,
89 unassigned_objects);
90 for (size_t i = 0; i < assignments->size(); ++i) {
91 objects[assignments->at(i).second]->association_score =
92 (*association_mat)(assignments->at(i).first,
93 assignments->at(i).second) /
95 }
96}
97
99 const std::vector<MrfTrackDataPtr> &tracks,
100 const std::vector<TrackedObjectPtr> &new_objects,
101 algorithm::SecureMat<float> *association_mat) {
102 for (size_t i = 0; i < tracks.size(); ++i) {
103 for (size_t j = 0; j < new_objects.size(); ++j) {
104 (*association_mat)(i, j) =
105 track_object_distance_->ComputeDistance(new_objects[j], tracks[i]);
106 }
107 }
108}
109
110} // namespace radar4d
111} // namespace perception
112} // namespace apollo
void Resize(const size_t resize_height, const size_t resize_width)
void Reserve(const size_t reserve_height, const size_t reserve_width)
virtual void Match(const BipartiteGraphMatcherOptions &options, std::vector< NodeNodePair > *assignments, std::vector< size_t > *unassigned_rows, std::vector< size_t > *unassigned_cols)=0
Match bipartite graph
virtual std::string Name() const =0
Get class name
virtual algorithm::SecureMat< float > * cost_matrix()
Get cost matrix
void Match(const MrfTrackObjectMatcherOptions &options, const std::vector< TrackedObjectPtr > &objects, const std::vector< MrfTrackDataPtr > &tracks, std::vector< std::pair< size_t, size_t > > *assignments, std::vector< size_t > *unassigned_tracks, std::vector< size_t > *unassigned_objects)
Match detected objects to tracks
std::unique_ptr< MrfTrackObjectDistance > track_object_distance_
bool Init(const MrfTrackObjectMatcherInitOptions &options=MrfTrackObjectMatcherInitOptions())
Initalize mrf track object matcher
void ComputeAssociateMatrix(const std::vector< MrfTrackDataPtr > &tracks, const std::vector< TrackedObjectPtr > &new_objects, algorithm::SecureMat< float > *association_mat)
Compute association matrix
#define ACHECK(cond)
Definition log.h:80
#define AINFO
Definition log.h:42
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::string GetConfigFile(const std::string &config_path, const std::string &config_file)
Definition util.cc:80
class register implement
Definition arena_queue.h:37