Apollo 10.0
自动驾驶开放平台
apollo::perception::camera::Target结构体 参考

#include <target.h>

apollo::perception::camera::Target 的协作图:

Public 成员函数

 Target (const TargetParam &param)
 
void Init (const TargetParam &param)
 init Target
 
void Add (TrackObjectPtr object)
 add object to tracked_objects
 
void RemoveOld (int frame_id)
 remove objects older than frame_id
 
void Clear ()
 clear tracked_objects
 
void Predict (CameraTrackingFrame *frame)
 using kalman filter to predict the tracked_objects
 
void Update (CameraTrackingFrame *frame)
 using kalman filter to correct the tracked_objects todo(zero): update world in bev
 
void Update2D (CameraTrackingFrame *frame)
 update 2d
 
void Update3D (CameraTrackingFrame *frame)
 update 3d
 
void UpdateType (CameraTrackingFrame *frame)
 update type
 
int Size () const
 return the size of tracked_objects
 
TrackObjectPtr get_object (int index) const
 Get the object accoding to index
 
TrackObjectPtr operator[] (int index) const
 
bool isTracked () const
 return whether the target is tracked
 
bool isLost () const
 return whether the target is lost
 

Public 属性

int lost_age = 0
 
int id = 0
 
double start_ts = 0.0
 
FirstOrderRCLowPassFilter direction
 
TrackObjectPtr latest_object = nullptr
 
base::ObjectSubType type = base::ObjectSubType::MAX_OBJECT_TYPE
 
KalmanFilterConstVelocity world_center
 
MeanFilter world_center_for_unmovable
 
KalmanFilterConstState< 2 > world_center_const
 
MeanFilter displacement_theta
 
MaxNMeanFilter world_lwh
 
MeanFilter world_lwh_for_unmovable
 
MeanFilter world_velocity
 
std::vector< float > type_probs
 
TargetParam target_param_
 
FirstOrderRCLowPassFilter image_wh
 
KalmanFilterConstVelocity image_center
 
TrackObjectPtrs tracked_objects
 

Protected 属性

ObjectTemplateManagerobject_template_manager_ = nullptr
 

详细描述

在文件 target.h35 行定义.

构造及析构函数说明

◆ Target()

apollo::perception::camera::Target::Target ( const TargetParam param)
explicit

在文件 target.cc103 行定义.

103{ Init(param); }
void Init(const TargetParam &param)
init Target
Definition target.cc:65

成员函数说明

◆ Add()

void apollo::perception::camera::Target::Add ( TrackObjectPtr  object)

add object to tracked_objects

参数
object

在文件 target.cc43 行定义.

43 {
44 if (tracked_objects.empty()) {
45 start_ts = object->timestamp;
46 id = Target::global_track_id++;
47 type = object->object->sub_type;
48 }
49 object->object->track_id = id;
50 object->object->tracking_time = object->timestamp - start_ts;
51 object->object->latest_tracked_time = object->timestamp;
52 latest_object = object;
53 lost_age = 0;
54 tracked_objects.push_back(object);
55}
base::ObjectSubType type
Definition target.h:137
TrackObjectPtrs tracked_objects
Definition target.h:156

◆ Clear()

void apollo::perception::camera::Target::Clear ( )

clear tracked_objects

在文件 target.cc33 行定义.

33{ tracked_objects.clear(); }

◆ get_object()

TrackObjectPtr apollo::perception::camera::Target::get_object ( int  index) const

Get the object accoding to index

参数
index
返回
TrackObjectPtr

在文件 target.cc36 行定义.

36 {
37 CHECK_GT(static_cast<int>(tracked_objects.size()), 0);
38 CHECK_LT(index, static_cast<int>(tracked_objects.size()));
39 CHECK_GE(index, -static_cast<int>(tracked_objects.size()));
40 return tracked_objects[(index + tracked_objects.size()) %
41 tracked_objects.size()];
42}

◆ Init()

void apollo::perception::camera::Target::Init ( const TargetParam param)

init Target

参数
param

在文件 target.cc65 行定义.

65 {
66 target_param_ = param;
67 id = -1;
68 lost_age = 0;
69
70 world_lwh.SetWindow(param.world_lhw_history());
71 world_lwh_for_unmovable.SetWindow(param.world_lhw_history());
72 image_wh.SetAlpha(param.image_wh_update_rate());
73 // TODO(gaohan) should update variance when predict and update
82
83 type_probs.assign(static_cast<int>(base::ObjectSubType::MAX_OBJECT_TYPE),
84 0.0f);
85 world_center_for_unmovable.SetWindow(param.world_lhw_history());
86 world_velocity.SetWindow(param.mean_filter_window());
87
88 // record history state after kalman filter
89 history_world_states_.set_capacity(param.world_state_history());
90
91 // record orientation of displacement
92 displacement_theta.SetWindow(param.mean_filter_window());
93 direction.SetAlpha(param.direction_filter_ratio());
94 // Init constant position Kalman Filter
95 world_center_const.covariance_.setIdentity();
100 // Init object template
101 object_template_manager_ = ObjectTemplateManager::Instance();
102}
optional KalmanParam world_center
Definition omt.proto:28
optional KalmanParam image_center
Definition omt.proto:29
KalmanFilterConstVelocity image_center
Definition target.h:154
ObjectTemplateManager * object_template_manager_
Definition target.h:167
KalmanFilterConstVelocity world_center
Definition target.h:138
KalmanFilterConstState< 2 > world_center_const
Definition target.h:142
std::vector< float > type_probs
Definition target.h:150
FirstOrderRCLowPassFilter image_wh
Definition target.h:153
FirstOrderRCLowPassFilter direction
Definition target.h:135

◆ isLost()

bool apollo::perception::camera::Target::isLost ( ) const

return whether the target is lost

返回
true
false

在文件 target.cc516 行定义.

516{ return lost_age > 0; }

◆ isTracked()

bool apollo::perception::camera::Target::isTracked ( ) const

return whether the target is tracked

返回
true
false

在文件 target.cc513 行定义.

513 {
514 return Size() >= target_param_.tracked_life();
515}
int Size() const
return the size of tracked_objects
Definition target.cc:31

◆ operator[]()

TrackObjectPtr apollo::perception::camera::Target::operator[] ( int  index) const

在文件 target.cc35 行定义.

35{ return get_object(index); }
TrackObjectPtr get_object(int index) const
Get the object accoding to index
Definition target.cc:36

◆ Predict()

void apollo::perception::camera::Target::Predict ( CameraTrackingFrame frame)

using kalman filter to predict the tracked_objects

参数
frame

在文件 target.cc105 行定义.

105 {
106 auto delta_t =
107 static_cast<float>(frame->timestamp - latest_object->timestamp);
108 if (delta_t < 0) {
109 return;
110 }
111 image_center.Predict(delta_t);
112 float acc_variance = target_param_.world_center().process_variance();
113 float delta_t_2 = delta_t * delta_t;
114 float pos_variance = 0.25f * acc_variance * delta_t_2 * delta_t_2;
115 float vel_variance = acc_variance * delta_t_2;
116 world_center.process_noise_(0, 0) = pos_variance;
117 world_center.process_noise_(1, 1) = pos_variance;
118 world_center.process_noise_(2, 2) = vel_variance;
119 world_center.process_noise_(3, 3) = vel_variance;
120 world_center.Predict(delta_t);
121
122 // const position kalman predict
124 world_center_const.process_noise_(0, 0) = vel_variance * delta_t_2;
128}

◆ RemoveOld()

void apollo::perception::camera::Target::RemoveOld ( int  frame_id)

remove objects older than frame_id

参数
frame_id

在文件 target.cc56 行定义.

56 {
57 size_t index = 0;
58 while (index < tracked_objects.size() &&
59 tracked_objects[index]->indicator.frame_id < frame_id) {
60 ++index;
61 }
62 tracked_objects.erase(tracked_objects.begin(),
63 tracked_objects.begin() + index);
64}

◆ Size()

int apollo::perception::camera::Target::Size ( ) const

return the size of tracked_objects

返回
int

在文件 target.cc31 行定义.

31{ return static_cast<int>(tracked_objects.size()); }

◆ Update()

void apollo::perception::camera::Target::Update ( CameraTrackingFrame frame)

using kalman filter to correct the tracked_objects todo(zero): update world in bev

参数
frame

在文件 target.cc309 行定义.

309 {
310 auto object = latest_object->object;
311 if (!isLost()) {
312 // todo(zero): need to fix alpha
313 float alpha = 0.01f;
314
315 Eigen::Vector4d size_measurement;
316 size_measurement << alpha, object->size(0), object->size(1),
317 object->size(2);
318 world_lwh.AddMeasure(size_measurement);
319 world_lwh_for_unmovable.AddMeasure(size_measurement);
320 // update 3d object size
321 if (object->type == base::ObjectType::UNKNOWN_UNMOVABLE) {
322 object->size =
323 world_lwh_for_unmovable.get_state().block<3, 1>(1, 0).cast<float>();
324 } else {
325 object->size = world_lwh.get_state().block<3, 1>(1, 0).cast<float>();
326 }
327 ADEBUG << " size is " << world_lwh.get_state().transpose();
328 }
329
330 Update3D(frame);
331}
void AddMeasure(const Eigen::VectorXd &z)
void AddMeasure(const Eigen::VectorXd &z)
const Eigen::VectorXd & get_state() const
#define ADEBUG
Definition log.h:41
bool isLost() const
return whether the target is lost
Definition target.cc:516
void Update3D(CameraTrackingFrame *frame)
update 3d
Definition target.cc:161

◆ Update2D()

void apollo::perception::camera::Target::Update2D ( CameraTrackingFrame frame)

update 2d

参数
frame

在文件 target.cc130 行定义.

130 {
131 // measurements
132 auto obj = latest_object->object;
133 float width = static_cast<float>(frame->data_provider->src_width());
134 float height = static_cast<float>(frame->data_provider->src_height());
135 base::RectF rect(latest_object->projected_box);
136 base::Point2DF center = rect.Center();
137
138 if (!isLost()) {
139 Eigen::Vector2d measurement;
140 measurement << rect.width, rect.height;
141 image_wh.AddMeasure(measurement);
142 measurement << center.x, center.y;
143 image_center.Correct(measurement);
144
145 // update 2d bbox size
146 Eigen::Vector4d state;
147 state = image_center.get_state();
148 center.x = static_cast<float>(state(0));
149 center.y = static_cast<float>(state(1));
150 ADEBUG << "2d move:" << id << " " << state(2) << " " << state(3);
151
152 auto shape = image_wh.get_state();
153 rect.width = static_cast<float>(shape(0));
154 rect.height = static_cast<float>(shape(1));
155 rect.SetCenter(center);
156 RefineBox(rect, width, height, &rect);
157 latest_object->projected_box = rect;
158 }
159}
uint32_t height
Height of point cloud
uint32_t width
Width of point cloud
Rect< float > RectF
Definition box.h:160
Point2D< float > Point2DF
Definition point.h:87
void RefineBox(const base::Rect< T > &box_in, const T width, const T height, base::Rect< T > *box_out)
Definition util.h:92

◆ Update3D()

void apollo::perception::camera::Target::Update3D ( CameraTrackingFrame frame)

update 3d

参数
frame

在文件 target.cc161 行定义.

161 {
162 auto object = latest_object->object;
163 if (!isLost()) {
164 // camera coordinate
165 Eigen::Vector2d z;
166 z << std::sin(object->theta), std::cos(object->theta);
168 z = direction.get_state();
169 float theta = static_cast<float>(std::atan2(z[0], z[1]));
170 AINFO << "dir " << id << " " << object->theta << " " << theta;
171 object->theta = theta;
172 object->direction[0] = static_cast<float>(cos(object->theta));
173 object->direction[1] = static_cast<float>(sin(object->theta));
174 object->direction[2] = 0;
175
176 z << object->center(0), object->center(1);
177 if (object->type == base::ObjectType::UNKNOWN_UNMOVABLE) {
179 } else {
180 // Eigen::Vector4d x = world_center.get_state();
181 float obj_2_car_x = object->camera_supplement.local_center[0];
182 float obj_2_car_z = object->camera_supplement.local_center[2];
183 float obj_distance_to_main_car =
184 obj_2_car_x * obj_2_car_x + obj_2_car_z * obj_2_car_z;
185 float dis_err = target_param_.world_center().measure_variance() *
186 obj_distance_to_main_car;
187 world_center.measure_noise_.setIdentity();
188 world_center.measure_noise_ *= dis_err;
190 ADEBUG << "Velocity: " << id << " " << z.transpose() << " "
191 << world_center.get_state().transpose();
192
193 // const position kalman correct
196 KalmanFilterConstState<2>::VectorNd pos_measure;
197 pos_measure << object->center(0), object->center(1);
199 }
200 }
201
202 if (object->type == base::ObjectType::UNKNOWN_UNMOVABLE) {
203 const Eigen::VectorXd &x = world_center_for_unmovable.get_state();
204 const Eigen::MatrixXd &var = world_center_for_unmovable.get_variance();
205 object->center(0) = x(0);
206 object->center(1) = x(1);
207 object->center_uncertainty(0) = static_cast<float>(var(0));
208 object->center_uncertainty(1) = static_cast<float>(var(1));
209 object->velocity(0) = 0;
210 object->velocity(1) = 0;
211 object->velocity(2) = 0;
212 } else {
213 Eigen::Vector4d x = world_center.get_state();
214 // TODO(gaohan02): refactor
215 if (tracked_objects.size() > 10) {
216 auto pose1 = get_object(-2)->object->center;
217 auto pose2 = get_object(-10)->object->center;
218 double ts1 = get_object(-2)->timestamp;
219 double ts2 = get_object(-10)->timestamp;
220 Eigen::Vector3d vel = (pose1 - pose2) / (ts1 - ts2);
221 double speed1 = std::sqrt(vel(0) * vel(0) + vel(1) * vel(1));
222 double speed2 = std::sqrt(x(2) * x(2) + x(3) * x(3));
223 double ratio = (Equal(speed1, 0)) ? 0 : speed2 / speed1;
224 ADEBUG << "Target: " << id << " " << vel.transpose() << " , "
225 << x.block<2, 1>(2, 0).transpose();
228 ADEBUG << "Velocity too large";
229 } else if (ratio > target_param_.large_velocity_ratio()) {
230 vel(0) = (x(2) + vel(0)) / 2;
231 vel(1) = (x(3) + vel(1)) / 2;
233 ADEBUG << "Velocity large";
234 } else {
235 ADEBUG << "Velocity normal";
236 }
237 }
238
240 double speed = std::sqrt(x(2) * x(2) + x(3) * x(3));
241 const std::map<base::ObjectSubType, float> &kTypeSpeedLimit =
243 if (speed > kTypeSpeedLimit.at(object->sub_type)) {
244 double ratio = kTypeSpeedLimit.at(object->sub_type) / speed;
245 Eigen::Vector2d vel;
246 vel << x(2) * ratio, x(3) * ratio;
249 }
250 object->center(0) = x(0);
251 object->center(1) = x(1);
252 object->center_uncertainty.setConstant(0);
253 object->center_uncertainty(0, 0) =
254 static_cast<float>(world_center.variance_(0, 0));
255 object->center_uncertainty(1, 1) =
256 static_cast<float>(world_center.variance_(1, 1));
257 object->velocity(0) = static_cast<float>(x(2));
258 object->velocity(1) = static_cast<float>(x(3));
259 object->velocity(2) = 0;
260 world_velocity.AddMeasure(object->velocity.cast<double>());
261 object->velocity_uncertainty = world_velocity.get_variance().cast<float>();
262 if (speed > target_param_.velocity_threshold()) {
263 object->direction(0) = static_cast<float>(x(2) / speed);
264 object->direction(1) = static_cast<float>(x(3) / speed);
265 object->direction(2) = 0;
266 object->theta = static_cast<float>(std::atan2(x(3), x(2)));
267 }
268 }
269
270 if (object->type != base::ObjectType::UNKNOWN_UNMOVABLE &&
272 // check displacement orientation
273 bool stable_moving = false;
274 double avg_vel_norm = world_velocity.get_state().norm();
275 if (avg_vel_norm > target_param_.stable_moving_speed()) {
276 stable_moving = true;
277 } else if (tracked_objects.size() > 1) {
278 auto prev_pos = get_object(-2)->object->center;
279 auto displacement = object->center - prev_pos;
280 Eigen::VectorXd measured_theta(1);
281 measured_theta << std::atan2(displacement[1], displacement[0]);
282 displacement_theta.AddMeasure(measured_theta);
283 // if an object is moving, its displacement orientation should be
284 // consistent
285 stable_moving = displacement_theta.get_variance()(0, 0) <
287 }
288
289 // check const position kalman residuals
290 const auto &residual = world_center_const.residual_;
291 if (!stable_moving &&
292 residual(0) * residual(0) <
294 residual(1) * residual(1) <
296 object->velocity(0) = 0;
297 object->velocity(1) = 0;
298 }
299
300 // check history states
301 history_world_states_.push_back(object);
302 ClappingTrackVelocity(object);
303 }
304
305 // debug velocity
306 ADEBUG << "obj_speed--id: " << id << " " << object->velocity.head(2).norm();
307}
void Correct(const VectorNd &measurement)
const Eigen::MatrixXd & get_variance() const
const std::map< base::ObjectSubType, float > & TypeSpeedLimit()
#define AINFO
Definition log.h:42
float cos(Angle16 a)
Definition angle.cc:42
float sin(Angle16 a)
Definition angle.cc:25
bool Equal(double x, double target, double eps)
Definition util.cc:24

◆ UpdateType()

void apollo::perception::camera::Target::UpdateType ( CameraTrackingFrame frame)

update type

参数
frame

在文件 target.cc333 行定义.

333 {
334 auto object = latest_object->object;
335 if (!isLost()) {
336 base::RectF rect(object->camera_supplement.box);
337 // 1. 6mm: reliable z is 40. intrinsic is approximate 2000
338 // 2. 12mm: reliable z is 80. intrinsic is approximate 4000
339 // hf = H * f/z = H * 50
340 const TemplateMap &kMidTemplateHWL =
342 float alpha = gaussian(
343 rect.height /
344 (50 * (kMidTemplateHWL.at(object->sub_type).at(0) + 0.01f)),
346 alpha = std::max(0.01f, alpha);
347
348 type_probs[static_cast<int>(object->sub_type)] += alpha;
349 auto max_prob = std::max_element(type_probs.begin(), type_probs.end());
350 auto index = static_cast<int>(std::distance(type_probs.begin(), max_prob));
351 type = static_cast<base::ObjectSubType>(index);
352 ADEBUG << "Target " << id << " change type from "
353 << static_cast<int>(object->sub_type) << " to "
354 << static_cast<int>(type);
355 object->sub_type = type;
356
357 Eigen::Vector4d size_measurement;
358 size_measurement << alpha, object->size(0), object->size(1),
359 object->size(2);
360 world_lwh.AddMeasure(size_measurement);
361 world_lwh_for_unmovable.AddMeasure(size_measurement);
362 // update 3d object size
363 if (object->type == base::ObjectType::UNKNOWN_UNMOVABLE) {
364 object->size =
365 world_lwh_for_unmovable.get_state().block<3, 1>(1, 0).cast<float>();
366 } else {
367 object->size = world_lwh.get_state().block<3, 1>(1, 0).cast<float>();
368 }
369 ADEBUG << " size is " << world_lwh.get_state().transpose();
370 }
371}
Dtype gaussian(Dtype x, Dtype mu, Dtype sigma)
std::map< base::ObjectSubType, std::vector< float > > TemplateMap

类成员变量说明

◆ direction

FirstOrderRCLowPassFilter apollo::perception::camera::Target::direction

在文件 target.h135 行定义.

◆ displacement_theta

MeanFilter apollo::perception::camera::Target::displacement_theta

在文件 target.h145 行定义.

◆ id

int apollo::perception::camera::Target::id = 0

在文件 target.h133 行定义.

◆ image_center

KalmanFilterConstVelocity apollo::perception::camera::Target::image_center

在文件 target.h154 行定义.

◆ image_wh

FirstOrderRCLowPassFilter apollo::perception::camera::Target::image_wh

在文件 target.h153 行定义.

◆ latest_object

TrackObjectPtr apollo::perception::camera::Target::latest_object = nullptr

在文件 target.h136 行定义.

◆ lost_age

int apollo::perception::camera::Target::lost_age = 0

在文件 target.h132 行定义.

◆ object_template_manager_

ObjectTemplateManager* apollo::perception::camera::Target::object_template_manager_ = nullptr
protected

在文件 target.h167 行定义.

◆ start_ts

double apollo::perception::camera::Target::start_ts = 0.0

在文件 target.h134 行定义.

◆ target_param_

TargetParam apollo::perception::camera::Target::target_param_

在文件 target.h151 行定义.

◆ tracked_objects

TrackObjectPtrs apollo::perception::camera::Target::tracked_objects

在文件 target.h156 行定义.

◆ type

base::ObjectSubType apollo::perception::camera::Target::type = base::ObjectSubType::MAX_OBJECT_TYPE

在文件 target.h137 行定义.

◆ type_probs

std::vector<float> apollo::perception::camera::Target::type_probs

在文件 target.h150 行定义.

◆ world_center

KalmanFilterConstVelocity apollo::perception::camera::Target::world_center

在文件 target.h138 行定义.

◆ world_center_const

KalmanFilterConstState<2> apollo::perception::camera::Target::world_center_const

在文件 target.h142 行定义.

◆ world_center_for_unmovable

MeanFilter apollo::perception::camera::Target::world_center_for_unmovable

在文件 target.h139 行定义.

◆ world_lwh

MaxNMeanFilter apollo::perception::camera::Target::world_lwh

在文件 target.h147 行定义.

◆ world_lwh_for_unmovable

MeanFilter apollo::perception::camera::Target::world_lwh_for_unmovable

在文件 target.h148 行定义.

◆ world_velocity

MeanFilter apollo::perception::camera::Target::world_velocity

在文件 target.h149 行定义.


该结构体的文档由以下文件生成: