Go to the documentation of this file.00001
00002
00003
00004 #pragma once
00005 #include "Kalman.h"
00006 #include "HungarianAlg.h"
00007 #include "defines.h"
00008 #include <iostream>
00009 #include <vector>
00010 #include <memory>
00011 #include <array>
00012
00013
00014 class CTrack
00015 {
00016 public:
00017 CTrack(const Point_t& p, const std::vector<cv::Point>& contour, track_t dt, size_t trackID)
00018 : track_id(trackID),
00019 skipped_frames(0),
00020 prediction(p),
00021 lastContour(contour),
00022 KF(p, dt)
00023 {
00024 }
00025
00026 track_t CalcDist(const Point_t& p)
00027 {
00028 Point_t diff = prediction - p;
00029 return std::sqrt(diff.x * diff.x + diff.y * diff.y + diff.z * diff.z);
00030 }
00031
00032 void Update(const Point_t& p, const std::vector<cv::Point>& contour, bool dataCorrect, size_t max_trace_length)
00033 {
00034 KF.Prediction();
00035 prediction = KF.Update(p, dataCorrect);
00036
00037 if (dataCorrect)
00038 {
00039 lastContour = contour;
00040 }
00041
00042 if (trace.size() > max_trace_length)
00043 {
00044 trace.erase(trace.begin(), trace.end() - max_trace_length);
00045 }
00046
00047 trace.push_back(prediction);
00048 }
00049
00050
00051 std::vector<cv::Point> getLastContour() const
00052 {
00053 return lastContour;
00054 }
00055
00056
00057 Point_t getEstimatedVelocity() const
00058 {
00059 return KF.LastVelocity;
00060 }
00061
00062 std::vector<Point_t> trace;
00063 size_t track_id;
00064 size_t skipped_frames;
00065
00066 private:
00067 Point_t prediction;
00068 std::vector<cv::Point> lastContour;
00069 TKalmanFilter KF;
00070 };
00071
00072
00073 class CTracker
00074 {
00075 public:
00076 struct Params{
00077 track_t dt;
00078 track_t dist_thresh;
00079 int max_allowed_skipped_frames;
00080 int max_trace_length;
00081 };
00082
00083 CTracker(const Params& parameters);
00084 ~CTracker(void);
00085
00086 std::vector<std::unique_ptr<CTrack>> tracks;
00087 void Update(const std::vector<Point_t>& detectedCentroid, const std::vector<std::vector<cv::Point> > &contour);
00088
00089 void updateParameters(const Params ¶meters);
00090
00091 private:
00092
00093 Params params;
00094
00095 size_t NextTrackID;
00096 };