Apollo 10.0
自动驾驶开放平台
mrf_motion_measurement.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
17#include <algorithm>
18#include <string>
19#include <vector>
20
23
24namespace apollo {
25namespace perception {
26namespace radar4d {
27
29 const MrfTrackDataConstPtr& track_data, TrackedObjectPtr new_object) {
30 // prefer to choose objects from the same sensor
31 std::string sensor_name = new_object->sensor_info.name;
32 TrackedObjectConstPtr latest_object =
33 track_data->GetLatestSensorObject(sensor_name).second;
34 if (latest_object == nullptr) {
35 latest_object = track_data->GetLatestObject().second;
36 }
37 if (latest_object.get() == nullptr) {
38 AERROR << "latest_object is not available";
39 return;
40 }
41 // should we estimate the measurement if the time diff is too small?
42 double latest_time = latest_object->object_ptr->latest_tracked_time;
43 double current_time = new_object->object_ptr->latest_tracked_time;
44 double time_diff = current_time - latest_time;
45 if (fabs(time_diff) < EPSILON_TIME) {
46 time_diff = DEFAULT_FPS;
47 }
48 MeasureAnchorPointVelocity(new_object, latest_object, time_diff);
49 MeasureBboxCenterVelocity(new_object, latest_object, time_diff);
50 MeasureBboxCornerVelocity(new_object, latest_object, time_diff);
51 MeasurementSelection(track_data, latest_object, new_object);
52 MeasurementQualityEstimation(latest_object, new_object);
53}
54
56 const MrfTrackDataConstPtr& track_data,
57 const TrackedObjectConstPtr& latest_object, TrackedObjectPtr new_object) {
58 // Select measured velocity among candidates according motion consistency
59 int64_t corner_index = 0;
60 float corner_velocity_gain = 0.0f;
61 std::vector<float> corner_velocity_gain_norms(4);
62 for (int i = 0; i < 4; ++i) {
63 corner_velocity_gain_norms[i] =
64 static_cast<float>((new_object->measured_corners_velocity[i] -
65 latest_object->belief_velocity)
66 .norm());
67 }
68 std::vector<float>::iterator corener_min_gain =
69 std::min_element(std::begin(corner_velocity_gain_norms),
70 std::end(corner_velocity_gain_norms));
71 corner_velocity_gain = *corener_min_gain;
72 corner_index = corener_min_gain - corner_velocity_gain_norms.begin();
73
74 std::vector<float> velocity_gain_norms(3);
75 velocity_gain_norms[0] = corner_velocity_gain;
76 velocity_gain_norms[1] =
77 static_cast<float>((new_object->measured_barycenter_velocity -
78 latest_object->belief_velocity)
79 .norm());
80 velocity_gain_norms[2] = static_cast<float>(
81 (new_object->measured_center_velocity - latest_object->belief_velocity)
82 .norm());
83 std::vector<float>::iterator min_gain = std::min_element(
84 std::begin(velocity_gain_norms), std::end(velocity_gain_norms));
85 int64_t min_gain_pos = min_gain - velocity_gain_norms.begin();
86 if (min_gain_pos == 0) {
87 new_object->selected_measured_velocity =
88 new_object->measured_corners_velocity[corner_index];
89 }
90 if (min_gain_pos == 1) {
91 new_object->selected_measured_velocity =
92 new_object->measured_barycenter_velocity;
93 }
94 if (min_gain_pos == 2) {
95 new_object->selected_measured_velocity =
96 new_object->measured_center_velocity;
97 }
98}
99
101 const TrackedObjectConstPtr& latest_object, TrackedObjectPtr new_object) {
102 // 1. point size diff (only for same sensor)
103 int pre_num = static_cast<int>(
104 latest_object->object_ptr->radar4d_supplement.cloud_world.size());
105 int cur_num = static_cast<int>(
106 new_object->object_ptr->radar4d_supplement.cloud_world.size());
107 double quality_based_on_point_diff_ratio =
108 (latest_object->sensor_info.name == new_object->sensor_info.name)
109 ? (1.0 - fabs(pre_num - cur_num) / std::max(pre_num, cur_num))
110 : 1.0;
111 // 2. association quality
112 double quality_based_on_association_score =
113 pow(1.0 - new_object->association_score, 2.0);
114 new_object->update_quality = std::min(quality_based_on_association_score,
115 quality_based_on_point_diff_ratio);
116}
117
118} // namespace radar4d
119} // namespace perception
120} // namespace apollo
void MeasurementSelection(const MrfTrackDataConstPtr &track_data, const TrackedObjectConstPtr &latest_object, TrackedObjectPtr new_object)
Select measurement based on track history
void ComputeMotionMeasurment(const MrfTrackDataConstPtr &track_data, TrackedObjectPtr new_object)
Wrapper of motion measurement functions
void MeasurementQualityEstimation(const TrackedObjectConstPtr &latest_object, TrackedObjectPtr new_object)
Estimate measurement quality
#define AERROR
Definition log.h:44
std::shared_ptr< const TrackedObject > TrackedObjectConstPtr
std::shared_ptr< TrackedObject > TrackedObjectPtr
void MeasureAnchorPointVelocity(TrackedObjectPtr new_object, const TrackedObjectConstPtr &old_object, const double &time_diff)
Measure anchor point velocity
std::shared_ptr< const MrfTrackData > MrfTrackDataConstPtr
void MeasureBboxCornerVelocity(TrackedObjectPtr new_object, const TrackedObjectConstPtr &old_object, const double &time_diff)
Measure bbox corner velocity
void MeasureBboxCenterVelocity(TrackedObjectPtr new_object, const TrackedObjectConstPtr &old_object, const double &time_diff)
Measure bbox center velocity
class register implement
Definition arena_queue.h:37