MTF
FESMBase.h
1 #ifndef MTF_FESMBASE_H
2 #define MTF_FESMBASE_H
3 
4 #include "SearchMethod.h"
5 
6 #define FESM_MAX_ITERS 10
7 #define FESM_UPD_THRESH 0.01
8 #define FESM_SEC_ORD_HESS false
9 #define FESM_ENABLE_SPI false
10 #define FESM_SPI_THRESH 10
11 #define FESM_DEBUG_MODE false
12 
13 _MTF_BEGIN_NAMESPACE
14 
15 struct FESMParams{
16 
17  enum class JacType{ Original, DiffOfJacs };
18  enum class HessType {
19  Original, SumOfStd, SumOfSelf,
20  InitialSelf, CurrentSelf, Std
21  };
22 
23  int max_iters;
24  double upd_thresh;
26 
27  bool enable_spi;
28  double spi_thresh;
29  bool debug_mode;
30 
32  // value constructor
33  FESMParams(int _max_iters, double _upd_thresh,
34  bool _sec_ord_hess,
35  bool _enable_spi, double _spi_thresh,
36  bool _debug_mode){
37  max_iters = _max_iters;
38  upd_thresh = _upd_thresh;
39  sec_ord_hess = _sec_ord_hess;
40  enable_spi = _enable_spi;
41  spi_thresh = _spi_thresh;
42  debug_mode = _debug_mode;
43  }
44  // default and copy constructor
45  FESMParams(FESMParams *params = nullptr) :
46  max_iters(FESM_MAX_ITERS),
47  upd_thresh(FESM_UPD_THRESH),
48  sec_ord_hess(FESM_SEC_ORD_HESS),
49  enable_spi(FESM_ENABLE_SPI),
50  spi_thresh(FESM_SPI_THRESH),
51  debug_mode(FESM_DEBUG_MODE){
52  if(params){
53  max_iters = params->max_iters;
54  upd_thresh = params->upd_thresh;
55  sec_ord_hess = params->sec_ord_hess;
56  enable_spi = params->enable_spi;
57  spi_thresh = params->spi_thresh;
58  debug_mode = params->debug_mode;
59  }
60  }
61 };
62 
63 template<class AM, class SSM>
64 class FESMBase : public SearchMethod < AM, SSM > {
65 public:
66  typedef FESMParams ParamType;
67  using SearchMethod<AM, SSM> ::am;
68  using SearchMethod<AM, SSM> ::ssm;
69  using typename SearchMethod<AM, SSM> ::AMParams;
70  using typename SearchMethod<AM, SSM> ::SSMParams;
71  using SearchMethod<AM, SSM> ::cv_corners_mat;
72  using SearchMethod<AM, SSM> ::name;
73  using SearchMethod<AM, SSM> ::initialize;
74  using SearchMethod<AM, SSM> ::update;
75 
76  FESMBase(const ParamType *nesm_params = nullptr,
77  const AMParams *am_params = nullptr,
78  const SSMParams *ssm_params = nullptr);
79 
80  void initialize(const cv::Mat &corners) override;
81  void update() override;
82 
83  virtual void initializeHessian(){}
84  virtual void updateJacobian();
85  virtual void updateHessian();
86 
87  // functions re implemented by AFESMBase to get the additive variant
88  void initializePixJacobian();
89  void updatePixJacobian();
90  void initializePixHessian();
91  void updatePixHessian();
92  void updateSSM();
93 
94 protected:
95  ParamType params;
96 
97  int frame_id;
98  VectorXc pix_mask2;
99  VectorXb pix_mask;
100  VectorXd rel_pix_diff;
101  cv::Mat pix_mask_img;
102  double max_pix_diff;
103  char* spi_win_name;
104 
105  Matrix24d prev_corners;
106 
109  MatrixXd init_pix_jacobian, curr_pix_jacobian, mean_pix_jacobian;
110  MatrixXd init_pix_hessian, curr_pix_hessian, mean_pix_hessian;
111 
112  VectorXd ssm_update;
113 
115  RowVectorXd jacobian;
117  MatrixXd hessian, init_self_hessian;
118 
119  init_profiling();
120  char *time_fname;
121  char *log_fname;
122 
123  string hess_order;
124 
125  void initializeSPIMask();
126  void updateSPIMask();
127  void showSPIMask();
128 };
129 _MTF_END_NAMESPACE
130 
131 #endif
132 
double upd_thresh
maximum iterations of the FESMBase algorithm to run for each frame
Definition: FESMBase.h:24
RowVectorXd jacobian
1 x S Jacobian of the AM error norm w.r.t. SSM state vector
Definition: FESMBase.h:115
Definition: StateSpaceModel.h:35
Definition: AMParams.h:12
bool sec_ord_hess
maximum L1 norm of the state update vector at which to stop the iterations
Definition: FESMBase.h:25
FESMParams(int _max_iters, double _upd_thresh, bool _sec_ord_hess, bool _enable_spi, double _spi_thresh, bool _debug_mode)
decides whether logging data will be printed for debugging purposes;
Definition: FESMBase.h:33
Definition: SearchMethod.h:10
MatrixXd init_pix_jacobian
N x S jacobians of the pixel values w.r.t the SSM state vector where N = resx * resy is the no...
Definition: FESMBase.h:109
MatrixXd hessian
S x S Hessian of the AM error norm w.r.t. SSM state vector.
Definition: FESMBase.h:117
Definition: FESMBase.h:64
Definition: FESMBase.h:15