Apollo 11.0
自动驾驶开放平台
mlf_track_object_distance.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 *****************************************************************************/
16
18
19#include "cyber/common/file.h"
21#include "modules/perception/lidar_tracking/tracker/multi_lidar_fusion/proto/multi_lidar_fusion_config.pb.h"
22
23namespace apollo {
24namespace perception {
25namespace lidar {
26
27// location dist weight, irection dist weight, bbox size dist weight,
28// point num dist weight, histogram dist weight, centroid shift dist weight
29// bbox iou dist weight
30const std::vector<float> MlfTrackObjectDistance::kForegroundDefaultWeight = {
31 0.7f, 0.2f, 0.3f, 0.1f, 0.2f, 0.f, 0.f};
32// location dist weight, irection dist weight, bbox size dist weight,
33// point num dist weight, histogram dist weight, centroid shift dist weight
34// bbox iou dist weight
35const std::vector<float> MlfTrackObjectDistance::kBackgroundDefaultWeight = {
36 0.f, 0.f, 0.f, 0.4f, 0.f, 0.6f, 0.0f};
37
39 const MlfTrackObjectDistanceInitOptions& options) {
40 std::string config_file = "mlf_track_object_distance.conf";
41 if (!options.config_file.empty()) {
42 config_file = options.config_file;
43 }
44 config_file = GetConfigFile(options.config_path, config_file);
45 MlfDistanceConfig config;
46 ACHECK(cyber::common::GetProtoFromFile(config_file, &config));
47
52 for (int i = 0; i < config.foreground_weights_size(); ++i) {
53 const auto& fgws = config.foreground_weights(i);
54 const std::string& name = fgws.sensor_name_pair();
55 std::vector<float> weights(7, 0.f);
56 weights[0] = fgws.location_dist_weight();
57 weights[1] = fgws.direction_dist_weight();
58 weights[2] = fgws.bbox_size_dist_weight();
59 weights[3] = fgws.point_num_dist_weight();
60 weights[4] = fgws.histogram_dist_weight();
61 weights[5] = fgws.centroid_shift_dist_weight();
62 weights[6] = fgws.bbox_iou_dist_weight();
63 weights[7] = fgws.semantic_map_dist_weight();
64 foreground_weight_table_.emplace(name, weights);
65 }
66 for (int i = 0; i < config.background_weights_size(); ++i) {
67 const auto& bgws = config.background_weights(i);
68 const std::string& name = bgws.sensor_name_pair();
69 std::vector<float> weights(7, 0.f);
70 weights[0] = bgws.location_dist_weight();
71 weights[1] = bgws.direction_dist_weight();
72 weights[2] = bgws.bbox_size_dist_weight();
73 weights[3] = bgws.point_num_dist_weight();
74 weights[4] = bgws.histogram_dist_weight();
75 weights[5] = bgws.centroid_shift_dist_weight();
76 weights[6] = bgws.bbox_iou_dist_weight();
77 background_weight_table_.emplace(name, weights);
78 }
79
80 return true;
81}
82
84 const TrackedObjectConstPtr& object,
85 const MlfTrackDataConstPtr& track) const {
86 bool is_background = object->is_background;
87 const TrackedObjectConstPtr latest_object = track->GetLatestObject().second;
88 std::string key = latest_object->sensor_info.name + object->sensor_info.name;
89 const std::vector<float>* weights = nullptr;
90 if (is_background) {
91 auto iter = background_weight_table_.find(key);
92 if (iter == background_weight_table_.end()) {
93 weights = &kBackgroundDefaultWeight;
94 } else {
95 weights = &iter->second;
96 }
97 } else {
98 auto iter = foreground_weight_table_.find(key);
99 if (iter == foreground_weight_table_.end()) {
100 weights = &kForegroundDefaultWeight;
101 } else {
102 weights = &iter->second;
103 }
104 }
105 if (weights == nullptr || weights->size() < 7) {
106 AERROR << "Invalid weights";
107 return 1e+10f;
108 }
109 float distance = 0.f;
110 float delta = 1e-10f;
111
112 double current_time = object->object_ptr->latest_tracked_time;
113 track->PredictState(current_time);
114
115 double time_diff =
116 track->age_ ? current_time - track->latest_visible_time_ : 0;
117
118 // gate
119 float euclidean_distance =
120 EuclideanDistance(latest_object, track->predict_.state, object, time_diff);
121 if (euclidean_distance > euclidean_distance_threshold_) {
123 }
124
125 if (weights->at(0) > delta) {
126 distance +=
127 weights->at(0) * LocationDistance(latest_object, track->predict_.state,
128 object, time_diff);
129 }
130 if (weights->at(1) > delta) {
131 distance +=
132 weights->at(1) * DirectionDistance(latest_object, track->predict_.state,
133 object, time_diff);
134 }
135 if (weights->at(2) > delta) {
136 distance +=
137 weights->at(2) * BboxSizeDistance(latest_object, track->predict_.state,
138 object, time_diff);
139 }
140 if (weights->at(3) > delta) {
141 distance +=
142 weights->at(3) * PointNumDistance(latest_object, track->predict_.state,
143 object, time_diff);
144 }
145 if (weights->at(4) > delta) {
146 distance +=
147 weights->at(4) * HistogramDistance(latest_object, track->predict_.state,
148 object, time_diff);
149 }
150 if (weights->at(5) > delta) {
151 distance += weights->at(5) * CentroidShiftDistance(latest_object,
152 track->predict_.state,
153 object, time_diff);
154 }
155 if (weights->at(6) > delta) {
156 distance += weights->at(6) *
157 BboxIouDistance(latest_object, track->predict_.state, object,
159 }
160
161 return distance;
162}
163
164} // namespace lidar
165} // namespace perception
166} // namespace apollo
std::map< std::string, std::vector< float > > background_weight_table_
float ComputeDistance(const TrackedObjectConstPtr &object, const MlfTrackDataConstPtr &track) const
Compute object track distance
std::map< std::string, std::vector< float > > foreground_weight_table_
bool Init(const MlfTrackObjectDistanceInitOptions &options=MlfTrackObjectDistanceInitOptions())
Init mlf track object distance
#define ACHECK(cond)
Definition log.h:80
#define AERROR
Definition log.h:44
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< const MlfTrackData > MlfTrackDataConstPtr
std::shared_ptr< const TrackedObject > TrackedObjectConstPtr
float CentroidShiftDistance(const TrackedObjectConstPtr &last_object, const Eigen::VectorXf &track_predict, const TrackedObjectConstPtr &new_object, const double time_diff)
Compute centroid shift distance for object and background match
float HistogramDistance(const TrackedObjectConstPtr &last_object, const Eigen::VectorXf &track_predict, const TrackedObjectConstPtr &new_object, const double time_diff)
Compute histogram distance for given track & object
float BboxIouDistance(const TrackedObjectConstPtr &last_object, const Eigen::VectorXf &track_predict, const TrackedObjectConstPtr &new_object, const double time_diff, double match_threshold)
Compute bbox iou distance for object and background match
float LocationDistance(const TrackedObjectConstPtr &last_object, const Eigen::VectorXf &track_predict, const TrackedObjectConstPtr &new_object, const double time_diff)
Compute location distance for given track & object
float BboxSizeDistance(const TrackedObjectConstPtr &last_object, const Eigen::VectorXf &track_predict, const TrackedObjectConstPtr &new_object, const double time_diff)
Compute bbox size distance for given track & object
float EuclideanDistance(const TrackedObjectConstPtr &last_object, const Eigen::VectorXf &track_predict, const TrackedObjectConstPtr &new_object, const double time_diff)
: compute euclidean distance for given track & object
float PointNumDistance(const TrackedObjectConstPtr &last_object, const Eigen::VectorXf &track_predict, const TrackedObjectConstPtr &new_object, const double time_diff)
Compute point num distance for given track & object
float DirectionDistance(const TrackedObjectConstPtr &last_object, const Eigen::VectorXf &track_predict, const TrackedObjectConstPtr &new_object, const double time_diff)
Compute direction distance for given track & object
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