deepsort 算法代码阅读
//计算cost_matrix
tracker::iou_cost(
std::vector<Track> &tracks,
const DETECTIONS &dets,
const std::vector<int>& track_indices,
const std::vector<int>& detection_indices)
{
//!!!python diff: track_indices && detection_indices will never be None.
// if(track_indices.empty() == true) {
// for(size_t i = 0; i < tracks.size(); i++) {
// track_indices.push_back(i);
// }
// }
// if(detection_indices.empty() == true) {
// for(size_t i = 0; i < dets.size(); i++) {
// detection_indices.push_back(i);
// }
// }
int rows = track_indices.size();
int cols = detection_indices.size();
DYNAMICM cost_matrix = Eigen::MatrixXf::Zero(rows, cols);
for(int i = 0; i < rows; i++) {
int track_idx = track_indices[i];
if(tracks[track_idx].time_since_update > 1) {
cost_matrix.row(i) = Eigen::RowVectorXf::Constant(cols, INFTY_COST);
continue;
}
DETECTBOX bbox = tracks[track_idx].to_tlwh();
int csize = detection_indices.size();
DETECTBOXSS candidates(csize, 4);
for(int k = 0; k < csize; k++) candidates.row(k) = dets[detection_indices[k]].tlwh;
Eigen::RowVectorXf rowV = (1. - iou(bbox, candidates).array()).matrix().transpose();
cost_matrix.row(i) = rowV;
}
return cost_matrix;
}
linear_assignment::gate_cost_matrix(
KalmanFilters *kf,
DYNAMICM &cost_matrix,
std::vector<Track> &tracks,
const DETECTIONS &detections,
const std::vector<int> &track_indices,
const std::vector<int> &detection_indices,
float gated_cost, bool only_position)
{
int gating_dim = (only_position == true?2:4);
double gating_threshold = KalmanFilters::chi2inv95[gating_dim];
std::vector<DETECTBOX> measurements;
for(int i:detection_indices) <