X-Git-Url: http://47.100.26.94:8080/?a=blobdiff_plain;f=src%2FTracker.cpp;h=098a24ec4e4b1f0310c3249f521bb3e3a6bc2eec;hb=81741fb5b3fe86bf29a130f367ea102e3aa99b0b;hp=2d353a75af7c0c58dc2735eb5e49063981879127;hpb=5675c1a74ffcb95725eb11463e51cfebbc88a15e;p=trackerpp.git diff --git a/src/Tracker.cpp b/src/Tracker.cpp index 2d353a7..098a24e 100644 --- a/src/Tracker.cpp +++ b/src/Tracker.cpp @@ -2,25 +2,39 @@ using namespace suanzi; using namespace cv; +using namespace std; static const int MaxLost = 5; -Tracker::Tracker(int id) : id(id) +Tracker::Tracker(const cv::Mat& image, const Detection& detection, int id) +: id(id) { status = TrackerStatus::Fire; preStatus = TrackerStatus::Fire; -} -Tracker::~Tracker() -{ + // TODO: Kalman filter + KF.transitionMatrix = (Mat_(4, 4) << + 1, 0, 1, 0, + 0, 1, 0, 1, + 0, 0, 1, 0, + 0, 0, 0, 1); + + KF.measurementMatrix = (Mat_(2, 2) << + 1, 0, 0, 0, + 0, 1, 0, 0); + + KF.processNoiseCov = 1e-5 * Mat_::eye(4, 4); + KF.measurementNoiseCov = 1e-1 * Mat_::ones(2, 2); + KF.errorCovPost = 1. * Mat_::ones(4, 4); + //this->kf.statePre = 0.1 * Matx_::randn(4, 1); + //??? TODO + randn(KF.statePre, Scalar::all(0), Scalar::all(0.1)); + KF.statePost = (Mat_(4, 1) << detection.center_x, detection.center_y, 0, 0); } -void Tracker::addPatch(Patch* p) +Tracker::~Tracker() { - patches.push_back(p); - if (patches.size() > Metrics::MaxPatch){ - patches.erase(patches.end()); - } + patches.clear(); } void Tracker::updateState(const Mat& image) @@ -37,3 +51,26 @@ void Tracker::updateState(const Mat& image) status = TrackerStatus::Lost; } } + +void Tracker::addPatch(PatchPtr 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(); +}