MTF
HACLK.h
1 #ifndef MTF_HACLK_H
2 #define MTF_HACLK_H
3 
4 #include "SearchMethod.h"
5 #include <vector>
6 
7 #define HACLK_MAX_ITERS 10
8 #define HACLK_EPSILON 0.01
9 #define HACLK_REC_INIT_ERR_GRAD false
10 #define HACLK_DEBUG_MODE false
11 #define HACLK_HESS_TYPE 0
12 
13 _MTF_BEGIN_NAMESPACE
14 
15 struct HACLKParams{
16  int max_iters;
17  double epsilon;
19  bool debug_mode;
21  int hess_type;
23  std::vector<cv::Mat> converged_corners;
24 
25  HACLKParams(int _max_iters, double _epsilon,
26  bool _rec_init_err_grad, bool _debug_mode,
27  int _hess_type, const std::vector<cv::Mat> &_converged_corners){
28  this->max_iters = _max_iters;
29  this->epsilon = _epsilon;
30  this->rec_init_err_grad = _rec_init_err_grad;
31  this->debug_mode = _debug_mode;
32  this->hess_type = _hess_type;
33  this->converged_corners = _converged_corners;
34  }
35  HACLKParams(HACLKParams *params = nullptr) :
36  max_iters(HACLK_MAX_ITERS),
37  epsilon(HACLK_EPSILON),
38  rec_init_err_grad(HACLK_REC_INIT_ERR_GRAD),
39  debug_mode(HACLK_DEBUG_MODE),
40  hess_type(HACLK_HESS_TYPE){
41  if(params){
42  max_iters = params->max_iters;
43  epsilon = params->epsilon;
44  rec_init_err_grad = params->rec_init_err_grad;
45  debug_mode = params->debug_mode;
46  hess_type = params->hess_type;
47  converged_corners = params->converged_corners;
48  }
49  }
50 };
51 // Hessian After Convergence Lucas Kanade Search Method
52 template<class AM, class SSM>
53 class HACLK : public SearchMethod < AM, SSM > {
54 public:
55 
56  enum { GaussNewton, Newton, InitialNewton, CurrentNewton, ConvergedNewton};
57 
58  typedef HACLKParams ParamType;
59 
60  using SearchMethod<AM, SSM> ::am;
61  using SearchMethod<AM, SSM> ::ssm;
62  using typename SearchMethod<AM, SSM> ::AMParams;
63  using typename SearchMethod<AM, SSM> ::SSMParams;
64  using SearchMethod<AM, SSM> ::cv_corners_mat;
65  using SearchMethod<AM, SSM> ::name;
66  using SearchMethod<AM, SSM> ::initialize;
67  using SearchMethod<AM, SSM> ::update;
68 
69  HACLK(const ParamType *haclk_params = nullptr,
70  const AMParams *am_params = nullptr, const SSMParams *ssm_params = nullptr);
71 
72  void initialize(const cv::Mat &corners) override;
73  void update() override;
74 
75 private:
76  ParamType params;
77 
78  bool use_newton_method;
79  // Let S = size of SSM state vector and N = resx * resy = no. of pixels in the object patch
80 
82  MatrixXd init_pix_jacobian, curr_pix_jacobian;
84  MatrixXd init_pix_hessian, curr_pix_hessian;
85 
87  RowVectorXd similarity_jacobian;
89  MatrixXd hessian;
90 
91  Matrix24d curr_conv_corners;
92  Matrix24d prev_corners;
93  VectorXd ssm_update;
94  Matrix3d warp_update;
95 
96  //VectorXd prev_pix_vals;
97  //PixGradT prev_pix_grad;
98  //MatrixXd prev_pix_jacobian;
99 
100  int n_frames;
101  int frame_id;
102  VectorXd inv_state;
103  ClockType start_time, end_time;
104  std::vector<double> proc_times;
105  std::vector<char*> proc_labels;
106  char *log_fname;
107  char *time_fname;
108  inline void updateSSM(VectorXd &state_update){
109  ssm.compositionalUpdate(state_update);
110  }
111  inline void resetSSM(VectorXd &state_update){
112  ssm.invertState(inv_state, state_update);
113  ssm.compositionalUpdate(inv_state);
114  }
115 };
116 _MTF_END_NAMESPACE
117 
118 #endif
119 
Definition: HACLK.h:15
Definition: StateSpaceModel.h:35
bool rec_init_err_grad
maximum L1 norm of the state update vector at which to stop the iterations
Definition: HACLK.h:18
Definition: AMParams.h:12
Definition: SearchMethod.h:10
int hess_type
decides whether logging data will be printed for debugging purposes;
Definition: HACLK.h:22
bool debug_mode
decides if the gradient of the error vector w.r.t.
Definition: HACLK.h:20
double epsilon
maximum iterations of the HACLK algorithm to run for each frame
Definition: HACLK.h:17
Definition: HACLK.h:53