MTF
GridTrackerCV.h
1 #ifndef MTF_GRID_TRACKER_CV_H
2 #define MTF_GRID_TRACKER_CV_H
3 
4 #include "GridBase.h"
5 #include <vector>
6 
7 #define GTCV_GRID_SIZE_X 10
8 #define GTCV_GRID_SIZE_Y 10
9 #define GTCV_SEARCH_WINDOW_X 10
10 #define GTCV_SEARCH_WINDOW_Y 10
11 #define GTCV_RESET_AT_EACH_FRAME 1
12 #define GTCV_PATCH_CENTROID_INSIDE 0
13 #define GTCV_FB_ERR_THRESH 0
14 #define GTCV_PYRAMID_LEVELS 0
15 #define GTCV_USE_MIN_EIG_VALS 0
16 #define GTCV_MIN_EIG_THRESH 1e-4
17 #define GTCV_MAX_ITERS 30
18 #define GTCV_INPUT_TYPE CV_32FC1
19 #define GTCV_EPSILON 0.01
20 #define GTCV_SHOW_PTS 0
21 #define GTCV_DEBUG_MODE 0
22 
23 _MTF_BEGIN_NAMESPACE
24 
26 
27  int grid_size_x, grid_size_y;
28  int search_window_x, search_window_y;
29  bool reset_at_each_frame;
30  bool patch_centroid_inside;
31 
32  double fb_err_thresh;
33 
34  int pyramid_levels;
35  bool use_min_eig_vals;
36  double min_eig_thresh;
37 
38  int max_iters;
39  double epsilon;
40 
41  int input_type;
42 
43  bool show_pts;// show the locations of individual patch trackers
44 
45  bool debug_mode;
46 
49  int _grid_size_x, int _grid_size_y,
50  int _search_window_x, int _search_window_y,
51  bool reset_at_each_frame, bool _patch_centroid_inside,
52  double _fb_err_thresh,
53  int _pyramid_levels, bool _use_min_eig_vals,
54  double _min_eig_thresh, int _max_iters,
55  double _epsilon, int _input_type, bool _show_pts,
56  bool _debug_mode);
57  GridTrackerCVParams(const GridTrackerCVParams *params = nullptr);
58 
59  int getResX() const{ return resx; }
60  int getResY() const{ return resy; }
61 
62 private:
63  int resx, resy;
64  void updateRes();
65 };
66 
67 template<class SSM>
68 class GridTrackerCV : public GridBase{
69 
70 public:
72  typedef typename SSM::ParamType SSMParams;
73  typedef typename SSM::EstimatorParams EstimatorParams;
74 
75  GridTrackerCV(const ParamType *grid_params, const EstimatorParams *_est_params,
76  const SSMParams *ssm_params);
77 
78  void initialize(const cv::Mat &corners) override;
79  void update() override;
80  void setImage(const cv::Mat &img) override;
81  void setRegion(const cv::Mat& corners) override;
82  const uchar* getPixMask() override{ return pix_mask.data(); }
83  int getResX() override{ return params.grid_size_x; }
84  int getResY() override{ return params.grid_size_y; }
85  const cv::Mat& getRegion() override{ return cv_corners_mat; }
86  int inputType() const override{ return params.input_type; }
87  SSM& getSSM() { return ssm; }
88 
89  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
90 
91 private:
92 
93  SSM ssm;
94  ParamType params;
95  EstimatorParams est_params;
96 
97  cv::Mat curr_img_in, curr_img, prev_img;
98  cv::Mat curr_pts_mat, prev_pts_mat;
99 
100  std::vector<cv::Point2f> curr_pts, prev_pts;
101  int n_pts;
102  cv::Size search_window;
103  cv::TermCriteria lk_term_criteria;
104 
105  cv::Mat warp_mat;
106  cv::Mat patch_corners;
107  std::vector<uchar> lk_status, pix_mask;
108  std::vector<float> lk_error;
109  int lk_flags;
110 
111  VectorXd ssm_update;
112 
113  cv::Mat curr_img_disp;
114 
115  Matrix2Xd centroid_offset;
116 
117  char* patch_win_name;
118 
119  MatrixXi _linear_idx;//used for indexing the sub region locations
120  int pause_seq;
121 
122  bool enable_fb_err_est;
123  std::vector<cv::Point2f> fb_prev_pts;
124  VectorXb fb_err_mask;
125  bool rgb_input, uchar_input;
126 
127  ~GridTrackerCV(){}
128  void resetPts();
129  void backwardEstimation();
130  void showPts();
131 };
132 
133 _MTF_END_NAMESPACE
134 
135 #endif
136 
Definition: StateSpaceModel.h:35
Definition: GridTrackerCV.h:68
Definition: GridBase.h:8
GridTrackerCVParams(int _grid_size_x, int _grid_size_y, int _search_window_x, int _search_window_y, bool reset_at_each_frame, bool _patch_centroid_inside, double _fb_err_thresh, int _pyramid_levels, bool _use_min_eig_vals, double _min_eig_thresh, int _max_iters, double _epsilon, int _input_type, bool _show_pts, bool _debug_mode)
decides whether logging data will be printed for debugging purposes;
Definition: GridTrackerCV.h:25
double epsilon
maximum iterations of the GridTrackerCV algorithm to run for each frame
Definition: GridTrackerCV.h:39