Ctracker.h
Go to the documentation of this file.
1 // Based on https://github.com/Smorodov/Multitarget-tracker/tree/master/Tracker, GPLv3
2 // Refer to README.md in this directory.
3 
4 #pragma once
5 #include "Kalman.h"
6 #include "HungarianAlg.h"
7 #include "defines.h"
8 #include <iostream>
9 #include <vector>
10 #include <memory>
11 #include <array>
12 
13 // --------------------------------------------------------------------------
14 class CTrack
15 {
16 public:
17  CTrack(const Point_t& p, const std::vector<cv::Point>& contour, track_t dt, size_t trackID)
18  : track_id(trackID),
19  skipped_frames(0),
20  prediction(p),
21  lastContour(contour),
22  KF(p, dt)
23  {
24  }
25 
27  {
28  Point_t diff = prediction - p;
29  return std::sqrt(diff.x * diff.x + diff.y * diff.y + diff.z * diff.z);
30  }
31 
32  void Update(const Point_t& p, const std::vector<cv::Point>& contour, bool dataCorrect, size_t max_trace_length)
33  {
34  KF.Prediction();
35  prediction = KF.Update(p, dataCorrect);
36 
37  if (dataCorrect)
38  {
39  lastContour = contour;
40  }
41 
42  if (trace.size() > max_trace_length)
43  {
44  trace.erase(trace.begin(), trace.end() - max_trace_length);
45  }
46 
47  trace.push_back(prediction);
48  }
49 
50  // Returns contour in [px], not in [m]!
51  std::vector<cv::Point> getLastContour() const
52  {
53  return lastContour;
54  }
55 
56  // Returns velocity in [px/s], not in [m/s]!
58  {
59  return KF.LastVelocity;
60  }
61 
62  std::vector<Point_t> trace;
63  size_t track_id;
65 
66 private:
68  std::vector<cv::Point> lastContour; // Contour liegt immer auf ganzen Pixeln -> Integer Punkt
70 };
71 
72 // --------------------------------------------------------------------------
73 class CTracker
74 {
75 public:
76  struct Params{
77  track_t dt; // time for one step of the filter
78  track_t dist_thresh;// distance threshold. Pairs of points with higher distance are not considered in the assignment problem
79  int max_allowed_skipped_frames; // Maximum number of frames the track is maintained without seeing the object in the measurement data
80  int max_trace_length; // Maximum trace length
81  };
82 
83  CTracker(const Params& parameters);
84  ~CTracker(void);
85 
86  std::vector<std::unique_ptr<CTrack>> tracks;
87  void Update(const std::vector<Point_t>& detectedCentroid, const std::vector<std::vector<cv::Point> > &contour);
88 
89  void updateParameters(const Params &parameters);
90 
91 private:
92  // Aggregated parameters for the tracker object
94  // ID for the upcoming CTrack object
95  size_t NextTrackID;
96 };
std::vector< std::unique_ptr< CTrack > > tracks
Definition: Ctracker.h:86
int max_trace_length
Definition: Ctracker.h:80
CTrack(const Point_t &p, const std::vector< cv::Point > &contour, track_t dt, size_t trackID)
Definition: Ctracker.h:17
std::vector< Point_t > trace
Definition: Ctracker.h:62
Point_t Update(Point_t p, bool DataCorrect)
Definition: Kalman.cpp:74
int max_allowed_skipped_frames
Definition: Ctracker.h:79
cv::Point3_< track_t > Point_t
Definition: defines.h:8
size_t skipped_frames
Definition: Ctracker.h:64
track_t dist_thresh
Definition: Ctracker.h:78
size_t NextTrackID
Definition: Ctracker.h:95
Point_t prediction
Definition: Ctracker.h:67
Params params
Definition: Ctracker.h:93
Point_t getEstimatedVelocity() const
Definition: Ctracker.h:57
std::vector< cv::Point > lastContour
Definition: Ctracker.h:68
track_t dt
Definition: Ctracker.h:77
std::vector< cv::Point > getLastContour() const
Definition: Ctracker.h:51
float track_t
Definition: defines.h:7
Point_t LastVelocity
Definition: Kalman.h:19
void Prediction()
Definition: Kalman.cpp:66
size_t track_id
Definition: Ctracker.h:63
TKalmanFilter KF
Definition: Ctracker.h:69
void Update(const Point_t &p, const std::vector< cv::Point > &contour, bool dataCorrect, size_t max_trace_length)
Definition: Ctracker.h:32
track_t CalcDist(const Point_t &p)
Definition: Ctracker.h:26


costmap_converter
Author(s): Christoph Rösmann , Franz Albers , Otniel Rinaldo
autogenerated on Fri Jun 7 2019 21:48:43