separate pytwrpper from predictorWrappery
[trackerpp.git] / src / Tracker.cpp
index 99a4e28..098a24e 100644 (file)
@@ -2,31 +2,34 @@
 
 using namespace suanzi;
 using namespace cv;
+using namespace std;
 
 static const int MaxLost = 5;
 
-Tracker::Tracker(const cv::Mat& image,int id) : id(id)
+Tracker::Tracker(const cv::Mat& image, const Detection& detection, int id) 
+: id(id)
 {
     status = TrackerStatus::Fire;
     preStatus = TrackerStatus::Fire;
 
-    // TODO
-    // init KalmanFilter
-    this->kf.transitionMatrix = (Mat_<float>(4, 4) << 
+    // TODO: Kalman filter
+    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_<float>(2, 2) << 
+    KF.measurementMatrix = (Mat_<double>(2, 2) << 
                                                 1, 0, 0, 0,
                                                 0, 1, 0, 0);
 
-    this->kf.processNoiseCov = 1e-5 * Mat_<float>::eye(4, 4);
-    this->kf.measurementNoiseCov = 1e-1 * Mat_<float>::ones(2, 2);
-    this->kf.errorCovPost = 1. * Mat_<float>::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(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()
@@ -51,5 +54,23 @@ void Tracker::updateState(const Mat& image)
 
 void Tracker::addPatch(PatchPtr p)
 {
-    this->patches.push_back(p);
+    patches.insert(patches.begin(), p);
+    if (patches.size() > MaxPatch){
+        patches.erase(patches.end());
+    }
+}
+
+void Tracker::correct(const cv::Mat& image, const Detection& detection)
+{
+    // 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();
 }