Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TrackerBaseAffine.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 #ifndef __TrackerBaseAffine_hh__
25 #define __TrackerBaseAffine_hh__
26 
27 #include <Matcher2D/TrackerBaseInterface.hh>
28 
29 namespace BIAS {
30 
31  /** @class TrackerBaseAffine
32  @ingroup g_tracker
33  @brief
34  @author woelk/kollmann 06/2006 */
35  template <class StorageType>
36  class BIASMatcher2D_EXPORT TrackerBaseAffine
37  : public TrackerBaseInterface<StorageType>
38  {
39  public:
40  TrackerBaseAffine(bool only4params = false, bool useHomography = false);
41 
42  /** Estimate all 6 parameters or only 4? */
43  inline void SetOnly4(bool Only4) { _SimilarityTransformOnly = Only4; }
44  inline void SetMaxAffineChange(const KLT_TYPE maxerr) {
45  _MaxAffineChange=maxerr;
46  }
47 
48  /** enable brightness variance and offset invariant computation */
49  virtual void SetAffineBrightnessInvariance(bool bi) {
50  _AffineBrightnessInvariance = bi;
51  }
52 
53  inline bool IsSimilarityTransformOnly() {
54  return _SimilarityTransformOnly ;
55  }
56 
57  protected:
58  /// iteration stops if position refinement is less than *_Maxerror
59  KLT_TYPE _MaxAffineChange;
60 
61  /// Estimate all 6 parameters or only 4?
63 
65 
66  /// workaround: save values from Track_ so we dont lose them
68  KLT_TYPE residuumMAD_;
69  KLT_TYPE residuumMSD_;
70 
71  /** @brief fill in computed residui from Track_ */
72  virtual void EvaluateResult_(KLT_TYPE& mad,KLT_TYPE& msd,
73  Matrix<KLT_TYPE>& cov);
74 
75 
76  virtual int Track_(Vector2<KLT_TYPE>& p1, Vector2<KLT_TYPE>& p2,
77  Vector2<KLT_TYPE>& result, KLT_TYPE& error,
78  int &iter,
79  const Matrix2x2<KLT_TYPE>& AffinePred,
80  Matrix2x2<KLT_TYPE>& AffineResult);
81 
82  /** @brief track using affine warp
83  @param p1 point in image 1
84  @param p2 prediction for point in image 2
85  @param p2A prediction for affine warp
86  @param result result after tracking
87  @param resultA affine warp after tracking
88  @param error maxnorm of last iteration step
89  @param iter number of iterations done
90  @param Cov resulting covariance
91  @param sad sum of absolute differences
92  @param ssd sum of squared differences
93  @param SimilarityTransformOnly only estimate A, not dx,dy
94  @param ComputeCovariance, if true Cov is computed using svd
95 
96  This implementation is based on Thorsten Thormaelen's version,
97  see cpp file.
98 
99  @author koeser 06/2005
100  */
101  int TrackAffine_(KLT_TYPE p1[2], KLT_TYPE p2[2],
102  const Matrix2x2<KLT_TYPE>& p2A,
103  KLT_TYPE result[2], Matrix2x2<KLT_TYPE>& resultA,
104  KLT_TYPE& error, int &iter, Matrix<KLT_TYPE>& Cov,
105  KLT_TYPE& mad, KLT_TYPE& msd,
106  bool SimilarityTransformOnly = false,
107  bool ComputeCovariance = true);
108 
109  // ------------ affine worker functions ----------------------------
110  void GetGradientWinAffine_(const KLT_TYPE& x, const KLT_TYPE& y,
111  const KLT_TYPE& Axx, const KLT_TYPE& Ayx,
112  const KLT_TYPE& Axy, const KLT_TYPE& Ayy,
113  const KLT_TYPE& h31, const KLT_TYPE& h32,
114  const int halfwidth, const int halfheight,
115  KLT_TYPE* out_gradx,
116  KLT_TYPE* out_grady);
117 
118  void ComputeIntensityDifferenceAffine_(const KLT_TYPE& x2,
119  const KLT_TYPE& y2,
120  const KLT_TYPE& Axx,
121  const KLT_TYPE& Ayx,
122  const KLT_TYPE& Axy,
123  const KLT_TYPE& Ayy,
124  const KLT_TYPE& h31,
125  const KLT_TYPE& h32,
126  const int halfwidth,
127  const int halfheight,
128  KLT_TYPE* imgdiff);
129 
171  };
172 }
173 
174 #endif // __TrackerBaseAffine_hh__
void SetMaxAffineChange(const KLT_TYPE maxerr)
Base class for the different tracking algorithms, defining the interfaces for the tracking functions...
long int ComputeCovariance(long int NumErrors, long int NumParams, double *Jac, int *Permutation, double &SumOfSquaredErrors, Matrix< double > &Cov)
Compute covariance matrix from Levenberg-Marquardt resulting Jacobian matrix J(x) and permutation mat...
Definition: Minpack.cpp:289
bool _SimilarityTransformOnly
Estimate all 6 parameters or only 4?
virtual void SetAffineBrightnessInvariance(bool bi)
enable brightness variance and offset invariant computation
Matrix< KLT_TYPE > Cov_
workaround: save values from Track_ so we dont lose them
void SetOnly4(bool Only4)
Estimate all 6 parameters or only 4?
KLT_TYPE _MaxAffineChange
iteration stops if position refinement is less than *_Maxerror