30int Target::global_track_id = 0;
46 id = Target::global_track_id++;
47 type =
object->object->sub_type;
49 object->object->track_id =
id;
50 object->object->tracking_time =
object->timestamp -
start_ts;
51 object->object->latest_tracked_time =
object->timestamp;
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;
133 float width =
static_cast<float>(frame->
data_provider->src_width());
134 float height =
static_cast<float>(frame->
data_provider->src_height());
139 Eigen::Vector2d measurement;
140 measurement << rect.width, rect.height;
142 measurement << center.
x, center.
y;
146 Eigen::Vector4d 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);
153 rect.width =
static_cast<float>(shape(0));
154 rect.height =
static_cast<float>(shape(1));
155 rect.SetCenter(center);
166 z << std::sin(object->theta), std::cos(object->theta);
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;
176 z <<
object->center(0),
object->center(1);
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;
186 obj_distance_to_main_car;
190 ADEBUG <<
"Velocity: " <<
id <<
" " << z.transpose() <<
" "
197 pos_measure <<
object->center(0),
object->center(1);
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;
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";
230 vel(0) = (x(2) + vel(0)) / 2;
231 vel(1) = (x(3) + vel(1)) / 2;
233 ADEBUG <<
"Velocity large";
235 ADEBUG <<
"Velocity normal";
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;
246 vel << x(2) * ratio, x(3) * ratio;
250 object->center(0) = x(0);
251 object->center(1) = x(1);
252 object->center_uncertainty.setConstant(0);
253 object->center_uncertainty(0, 0) =
255 object->center_uncertainty(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;
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)));
273 bool stable_moving =
false;
276 stable_moving =
true;
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]);
291 if (!stable_moving &&
292 residual(0) * residual(0) <
294 residual(1) * residual(1) <
296 object->velocity(0) = 0;
297 object->velocity(1) = 0;
301 history_world_states_.push_back(
object);
302 ClappingTrackVelocity(
object);
306 ADEBUG <<
"obj_speed--id: " <<
id <<
" " <<
object->velocity.head(2).norm();
315 Eigen::Vector4d size_measurement;
316 size_measurement << alpha,
object->size(0),
object->size(1),
344 (50 * (kMidTemplateHWL.at(object->sub_type).at(0) + 0.01f)),
346 alpha = std::max(0.01f, alpha);
348 type_probs[
static_cast<int>(
object->sub_type)] += alpha;
350 auto index =
static_cast<int>(std::distance(
type_probs.begin(), max_prob));
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;
357 Eigen::Vector4d size_measurement;
358 size_measurement << alpha,
object->size(0),
object->size(1),
376 Eigen::Vector3f obj_dir = obj->direction;
377 Eigen::Vector3f obj_vel = obj->velocity;
378 double vel_heading_angle_change_1 =
381 double vel_heading_angle_change_2 =
383 double vel_heading_angle_change =
384 std::min(std::fabs(vel_heading_angle_change_1),
385 std::fabs(vel_heading_angle_change_2));
386 ADEBUG <<
"obj_id: " << obj->track_id
387 <<
" vel_heading_angle, 1: " << vel_heading_angle_change_1
388 <<
" 2: " << vel_heading_angle_change_2
389 <<
" final: " << vel_heading_angle_change;
390 if (vel_heading_angle_change >
392 ADEBUG <<
"omt set zero velocity because vel_heading_angle_change >"
393 " abnormal_velocity_heading_angle_threshold : "
395 obj->velocity = Eigen::Vector3f::Zero();
402 ADEBUG <<
"omt set zero velocity because of small speed.";
403 obj->velocity = Eigen::Vector3f::Zero();
413bool Target::CheckStatic() {
414 if (
static_cast<int>(history_world_states_.size()) <
420 bool small_speed =
false;
421 const int min_vel_size =
422 std::min(
static_cast<int>(history_world_states_.size()),
425 std::shared_ptr<base::Object> tmp_obj_vel_avg =
nullptr;
426 tmp_obj_vel_avg.reset(
new base::Object);
427 tmp_obj_vel_avg->velocity = Eigen::Vector3f(0, 0, 0);
429 std::accumulate(history_world_states_.begin() +
430 history_world_states_.size() - min_vel_size,
431 history_world_states_.end(), tmp_obj_vel_avg,
432 [](
const std::shared_ptr<base::Object> obj1,
433 const std::shared_ptr<base::Object> obj2) {
434 std::shared_ptr<base::Object> ret_obj = nullptr;
435 ret_obj.reset(new base::Object);
436 ret_obj->velocity = obj1->velocity + obj2->velocity;
439 tmp_obj_vel_avg->velocity /=
static_cast<float>(min_vel_size);
440 double speed_avg = tmp_obj_vel_avg->velocity.head(2).norm();
441 const auto &obj_type = history_world_states_.back()->type;
453 bool not_move =
false;
454 if (
static_cast<int>(history_world_states_.size()) >=
457 double move_distance = 0.0;
458 Eigen::Vector3d start_position(0.0, 0.0, 0.0);
459 Eigen::Vector3d end_position(0.0, 0.0, 0.0);
460 const int start_idx =
461 static_cast<int>(history_world_states_.size()) -
463 const int end_idx =
static_cast<int>(history_world_states_.size()) - 1;
468 static_cast<int>(history_world_states_.size()) &&
471 start_position += history_world_states_[start_idx + i]->center;
472 end_position += history_world_states_[end_idx - i]->center;
474 double time_diff = history_world_states_[end_idx]->latest_tracked_time -
475 history_world_states_[start_idx]->latest_tracked_time;
477 if (std::fabs(time_diff) > 1e-3) {
480 move_distance = (end_position - start_position).head(2).norm();
482 double avg_speed = move_distance / time_diff;
496 std::vector<double> theta_vec(min_vel_size);
497 std::transform(history_world_states_.begin() + history_world_states_.size() -
499 history_world_states_.end(), theta_vec.begin(),
500 [](
const std::shared_ptr<base::Object> obj) ->
double {
501 return std::atan2(obj->velocity[1], obj->velocity[0]);
506 double stddev = std::sqrt(var);
void SetAlpha(float alpha)
Eigen::VectorXd get_state() const
void AddMeasure(const Eigen::VectorXd &z)
bool Predict(float delta_t)
Eigen::Matrix< double, N, 1 > VectorNd
void Correct(const VectorNd &measurement)
void Correct(const Eigen::VectorXd &z)
Eigen::Vector4d get_state() const
Eigen::Matrix2d measure_noise_
Eigen::Matrix4d variance_
void MagicVelocity(const Eigen::VectorXd &vel)
Eigen::Matrix4d process_noise_
void Predict(float delta_t)
Eigen::VectorXd get_state() const
void AddMeasure(const Eigen::VectorXd &z)
void SetWindow(int window)
void AddMeasure(const Eigen::VectorXd &z)
void SetWindow(int window)
const Eigen::MatrixXd & get_variance() const
const Eigen::VectorXd & get_state() const
const std::map< base::ObjectSubType, float > & TypeSpeedLimit()
const TemplateMap & MidTemplateHWL()
T CalculateTheta2DXY(const Eigen::Matrix< T, 3, 1 > &v1, const Eigen::Matrix< T, 3, 1 > &v2)
std::shared_ptr< Object > ObjectPtr
bool Equal(double x, double target, double eps)
void CalculateMeanAndVariance(const std::vector< T > &data, T *mean, T *variance)
Dtype gaussian(Dtype x, Dtype mu, Dtype sigma)
std::shared_ptr< TrackObject > TrackObjectPtr
void RefineBox(const base::Rect< T > &box_in, const T width, const T height, base::Rect< T > *box_out)
std::map< base::ObjectSubType, std::vector< float > > TemplateMap
std::shared_ptr< camera::DataProvider > data_provider
optional float process_variance
optional float measure_variance
optional float init_variance
optional KalmanParam world_center
optional float velocity_theta_var
optional float type_filter_var
optional float image_wh_update_rate
optional float displacement_theta_var
optional float abnormal_velocity_heading_angle_threshold
optional float min_moving_avg_speed_ped
optional int32 min_cached_position_size
optional int32 world_lhw_history
optional float static_speed_threshold
optional int32 min_cached_velocity_size
optional int32 calc_avg_position_window_size
optional float large_velocity_ratio
optional float stable_moving_speed
optional float direction_filter_ratio
optional float velocity_threshold
optional int32 tracked_life
optional int32 mean_filter_window
optional int32 world_state_history
optional KalmanParam image_center
optional float min_moving_avg_speed
optional float too_large_velocity_ratio
optional int32 min_cached_world_state_history_size
optional float static_speed_threshold_ped
optional bool clapping_velocity
TrackObjectPtr operator[](int index) const
MeanFilter displacement_theta
void Clear()
clear tracked_objects
int Size() const
return the size of tracked_objects
void Predict(CameraTrackingFrame *frame)
using kalman filter to predict the tracked_objects
MeanFilter world_center_for_unmovable
MeanFilter world_velocity
bool isLost() const
return whether the target is lost
void Add(TrackObjectPtr object)
add object to tracked_objects
void Update3D(CameraTrackingFrame *frame)
update 3d
bool isTracked() const
return whether the target is tracked
void Update2D(CameraTrackingFrame *frame)
update 2d
void Update(CameraTrackingFrame *frame)
using kalman filter to correct the tracked_objects todo(zero): update world in bev
TrackObjectPtr latest_object
KalmanFilterConstVelocity image_center
ObjectTemplateManager * object_template_manager_
MeanFilter world_lwh_for_unmovable
KalmanFilterConstVelocity world_center
KalmanFilterConstState< 2 > world_center_const
void RemoveOld(int frame_id)
remove objects older than frame_id
TrackObjectPtr get_object(int index) const
Get the object accoding to index
Target(const TargetParam ¶m)
std::vector< float > type_probs
FirstOrderRCLowPassFilter image_wh
FirstOrderRCLowPassFilter direction
TrackObjectPtrs tracked_objects
void UpdateType(CameraTrackingFrame *frame)
update type
TargetParam target_param_
void Init(const TargetParam ¶m)
init Target