MTF
LineTracker.h
1 #ifndef MTF_LINE_TRACKER_H
2 #define MTF_LINE_TRACKER_H
3 
4 #include "CompositeBase.h"
5 #include "mtf/Macros/common.h"
6 
7 #define LINE_GRID_SIZE_X 5
8 #define LINE_GRID_SIZE_Y 5
9 #define LINE_PATCH_SIZE 25
10 #define LINE_USE_CONSTANT_SLOPE false
11 #define LINE_USE_LS false
12 #define LINE_INTER_ALPHA_THRESH 0.1
13 #define LINE_INTRA_ALPHA_THRESH 0.05
14 #define LINE_RESET_POS false
15 #define LINE_RESET_TEMPLATE false
16 #define LINE_DEBUG_MODE false
17 
18 #define INF_VAL 1e5
19 #define TINY_VAL 1e-5
20 #define SMALL_VAL 2
21 
22 #define PI_RAD 3.14159265358979323846
23 
24 _MTF_BEGIN_NAMESPACE
25 
26 struct lineParams {
27  double m;
28  double c;
29  double c_diff;
30  double theta;
31  int is_vert;
32  lineParams(double _m = 0, double _c = 0, double _c_diff=0,
33  int _is_vert = 0) {
34  m = _m;
35  c = _c;
36  c_diff = _c_diff;
37  is_vert = _is_vert;
38  }
39 };
40 
41 struct gridPoint {
42  double x;
43  double y;
44  double tracker_x;
45  double tracker_y;
46  double xx;
47  double xy;
48 
49  double wt;
50  double wt_y;
51  double wt_x;
52  double alpha_wt[2];
53  double alpha[2];
54 
55  double inter_alpha_diff[2];
56  double intra_alpha_diff[2];
57 
58  int is_successful[2];
59 
60 };
61 
62 struct gridLine {
63  int no_of_pts;
64  lineParams *params;
65  gridPoint **pts;
66 
67  gridPoint *start_pt;
68  gridPoint *end_pt;
69 
70  int type;
71 
72  int inited;
73  int is_successful;
74 
75  gridLine();
76  ~gridLine() {
77  if(inited) {
78  delete(params);
79  delete(pts);
80  }
81  }
82 
83  void init(int no_of_pts, int type);
84  void assignAddrs(gridPoint *start_addr = nullptr, int offset_diff = 1);
85  void updateParams();
86 };
88  int grid_size_x, grid_size_y;
89  int patch_size;
90  int use_constant_slope;
91  int use_ls;
92  double inter_alpha_thresh;
93  double intra_alpha_thresh;
94  int reset_pos;
95  int reset_template;
96  int debug_mode;
97  LineTrackerParams(int grid_size_x, int grid_size_y,
98  int patch_size, bool use_constant_slope, bool use_ls,
99  double inter_alpha_thresh, double intra_alpha_thresh,
100  bool reset_pos, bool reset_template, bool debug_mode);
101  LineTrackerParams(const LineTrackerParams *params = nullptr);
102 };
103 
104 class LineTracker : public CompositeBase {
105 
106 public:
107 
109 
110  LineTracker(const vector<TrackerBase*> trackers,
111  const ParamType *line_params = nullptr);
112  ~LineTracker(){}
113  void initialize(const cv::Mat& cv_corners) override;
114  void update() override;
115 
116 private:
117  ParamType params;
118 
119  int corner_tracker_ids[4];
120  int frame_id;
121 
122  cv::Point2d *tracker_pos;
123  cv::Point2d wt_mean_pt;
124 
125  gridPoint *curr_grid_pts;
126  gridPoint *prev_grid_pts;
127 
128  gridLine *curr_vert_lines;
129  gridLine *curr_horz_lines;
130  gridLine *prev_vert_lines;
131  gridLine *prev_horz_lines;
132 
133  lineParams *mean_horz_params;
134  lineParams *mean_vert_params;
135 
136  int is_initialized;
137 
138  void initGridPositions(const cv::Mat& cv_corners);
139  void updateAlpha(gridLine* curr_lines, gridLine* prev_lines,
140  int no_of_lines, int line_type);
141  int updateLineParamsLS(gridLine* curr_lines, gridLine* prev_lines, lineParams *mean_params,
142  int no_of_lines, int line_type);
143  int updateLineParamsWeightedLS(gridLine* curr_lines, gridLine* prev_lines, lineParams *mean_params,
144  int no_of_lines, int line_type);
145  void resetLineParamsToPrev(gridLine* curr_lines,
146  gridLine* prev_lines, int no_of_lines);
147  void resetLineParamsToMean(gridLine* curr_lines, gridLine* prev_lines, lineParams* mean_params,
148  int no_of_lines, int reset_c = 0);
149  void updateGridWithLineIntersections();
150 
151  void updateDistanceWeights();
152  void resetTrackerStates();
153  void updateCVCorners();
154 };
155 _MTF_END_NAMESPACE
156 #endif
Definition: CompositeBase.h:10
Definition: LineTracker.h:62
Definition: LineTracker.h:87
Definition: LineTracker.h:41
Definition: LineTracker.h:26
Definition: LineTracker.h:104