void updateState(const cv::Mat& image);
void addPatch(PatchPtr p);
void correct(const cv::Mat& image, const Detection& d);
- TrackerStatus status;
+ void predict();
std::vector<PatchPtr> patches;
Detection detection;
+ TrackerStatus status = TrackerStatus::Fire;
private:
- TrackerStatus preStatus;
+ TrackerStatus preStatus = TrackerStatus::Fire;
int id;
- int age;
- int last_active;
- cv::KalmanFilter kf = {4,2};
+ int age = 1;
+ int last_active = 1;
+ cv::KalmanFilter KF = {4,2};
};
-
-
}
#endif /* _TRACKER_H_ */
static const double MaxCost = 100000;
static const int MaxPatch = 5;
+static const double ProbThreshold = 0.05;
MultiTracker::MultiTracker(EngineWPtr e)
: engine(e)
ss = similarity(i, patch);
features.insert(features.end(), ss.begin(), ss.end());
}
- double prob = predictor->predict(4, features);
- return prob;
+ double prob = predictor->predict(MaxPatch - 1, features); // TODO ???
+ if (prob > ProbThreshold)
+ return -log(prob);
+ else
+ return MaxCost;
}
static float calc_iou_ratio(const Detection& d1, const Detection& d2)
void MultiTracker::update(unsigned int total, const Detection* detections, const Mat& image)
{
+ // predict trackers, update trackers using kalman filter
+ for (auto t : trackers){
+ t->predict();
+ }
+
+ // match the trackers with the detections
int row = trackers.size();
int col = total;
Eigen::MatrixXi cost_matrix = Eigen::MatrixXi::Zero(row, col);
static const int MaxLost = 5;
-Tracker::Tracker(const cv::Mat& image, const Detection& detection, int id) : id(id)
+Tracker::Tracker(const cv::Mat& image, const Detection& detection, int id)
+: id(id)
{
status = TrackerStatus::Fire;
preStatus = TrackerStatus::Fire;
// TODO: Kalman filter
- this->kf.transitionMatrix = (Mat_<double>(4, 4) <<
+ KF.transitionMatrix = (Mat_<double>(4, 4) <<
1, 0, 1, 0,
0, 1, 0, 1,
0, 0, 1, 0,
0, 0, 0, 1);
- this->kf.measurementMatrix = (Mat_<double>(2, 2) <<
+ KF.measurementMatrix = (Mat_<double>(2, 2) <<
1, 0, 0, 0,
0, 1, 0, 0);
- this->kf.processNoiseCov = 1e-5 * Mat_<double>::eye(4, 4);
- this->kf.measurementNoiseCov = 1e-1 * Mat_<double>::ones(2, 2);
- this->kf.errorCovPost = 1. * Mat_<double>::ones(4, 4);
+ KF.processNoiseCov = 1e-5 * Mat_<double>::eye(4, 4);
+ KF.measurementNoiseCov = 1e-1 * Mat_<double>::ones(2, 2);
+ KF.errorCovPost = 1. * Mat_<double>::ones(4, 4);
//this->kf.statePre = 0.1 * Matx_<int, 4, 1>::randn(4, 1);
//??? TODO
- randn(this->kf.statePre, Scalar::all(0), Scalar::all(0.1));
- this->kf.statePost = (Mat_<double>(4, 1) << detection.center_x, detection.center_y, 0, 0);
+ randn(KF.statePre, Scalar::all(0), Scalar::all(0.1));
+ KF.statePost = (Mat_<double>(4, 1) << detection.center_x, detection.center_y, 0, 0);
}
Tracker::~Tracker()
void Tracker::correct(const cv::Mat& image, const Detection& detection)
{
- //kf.correct();
+ // detection.center_x, detection.center_y,
+ // KF.correct(detect.center_x, detect.center_y);
preStatus = status;
status = TrackerStatus::Active;
last_active = age;
}
+void Tracker::predict()
+{
+ age++;
+ //detection = KF.predict();
+}