25 #include "TrackerBaseSimple.hh"
30 #define SMALL_DET 1e-8
32 template <
class StorageType>
46 if (_HalfWinSize != _LastHalfWinSize){
47 this->Resize_(_HalfWinSize);
49 BIASCDOUT(D_TRACKERB_KLT,
"trying to track p1: (" << p1[0] <<
", " << p1[1]
50 <<
") <--> p2: (" <<p2[0] <<
", " << p2[1]<<
")\n");
54 register KLT_TYPE dI, ex, ey, dx, dy, det;
56 const int hws=_HalfWinSize;
57 const int winsize=_WinSize;
58 const int maxiter=_MaxIterations;
59 const KLT_TYPE maxerr=_MaxError;
61 BIASCDOUT(D_TRACKERB_INIT,
"using hws: "<<hws<<
"\tmaxiter: "<<maxiter
62 <<
"\tmaxerr: "<<maxerr<<endl);
64 if (p1[0]<_minx1 || p1[0]>=_maxx1 ||
65 p1[1]<_miny1 || p1[1]>=_maxy1 ||
66 p2[0]<_minx2 || p2[0]>=_maxx2 ||
67 p2[1]<_miny2 || p2[1]>=_maxy2 ){
68 BIASCDOUT(D_TRACKERB_KLT,
"p1 ("<<p1[0]<<
", "<<p1[1]<<
") p2 ("<<p2[0]
69 <<
", "<<p2[1]<<
")\n");
70 BIASCDOUT(D_TRACKERB_KLT,
"tracking roi im1 : ( "<<_minx1<<
", "<<_miny1
71 <<
") <--> ( "<<_maxx1<<
", "<<_maxy1<<
")\n");
72 BIASCDOUT(D_TRACKERB_KLT,
"tracking roi im2 : ( "<<_minx2<<
", "<<_miny2
73 <<
") <--> ( "<<_maxx2<<
", "<<_maxy2<<
")\n");
74 BIASCDOUT(D_TRACKERB_KLT,
"points do not lie in ROI, returning -4\n");
77 BIASCDOUT(D_TRACKERB_KLT,
"tracking roi im1 : ( "<<_minx1<<
", "<<_miny1
78 <<
") <--> ( "<<_maxx1<<
", "<<_maxy1<<
")\n");
79 BIASCDOUT(D_TRACKERB_KLT,
"tracking roi im2 : ( "<<_minx2<<
", "<<_miny2
80 <<
") <--> ( "<<_maxx2<<
", "<<_maxy2<<
")\n");
87 BilinearRegion1_(p1[0],p1[1],hws);
88 BIASCDOUT(D_TRACKERB_BILINEAR,
"_bl1: "<<_bl1<<
"\n_gx1: "<<_gx1
89 <<
"\n_gy1: "<<_gy1<<endl);
92 cerr <<
"TrackerBase MyBilinearRegion1_ took "<<timer.
GetRealTime()
99 _gxx=_gxy=_gyy=ex=ey=0.0;
100 BilinearRegion2_(result[0],result[1],hws);
101 BIASCDOUT(D_TRACKERB_BILINEAR,
"_bl2: "<<_bl2<<
"\n_gx2: "<<_gx2
102 <<
"\n_gy2: "<<_gy2<<endl);
105 for (rh=0; rh<winsize; rh++){
106 for (ch=0; ch<winsize; ch++){
107 _gsx[rh][ch] = _gx1[rh][ch] + _gx2[rh][ch];
108 _gsy[rh][ch] = _gy1[rh][ch] + _gy2[rh][ch];
109 _gxx += _gsx[rh][ch]*_gsx[rh][ch];
110 _gyy += _gsy[rh][ch]*_gsy[rh][ch];
111 _gxy += _gsx[rh][ch]*_gsy[rh][ch];
112 dI = _bl1[rh][ch] - _bl2[rh][ch];
113 ex += _gsx[rh][ch]*dI;
114 ey += _gsy[rh][ch]*dI;
116 if (BIAS_ISNAN(_gxx) || BIAS_ISINF(_gxx) ||
117 BIAS_ISNAN(_gxy) || BIAS_ISINF(_gxy) ||
118 BIAS_ISNAN(_gyy) || BIAS_ISINF(_gyy) ) {
119 cout <<
"_gx1: "<<_gx1<<
"\n_gx2: "<<_gx2
120 <<
"\n_gy1: "<<_gy1<<
"\n_gy2: "<<_gy2
121 <<
"\n_bl1: "<<_bl1<<
"\n_bl2: "<<_bl2
122 <<
"\np1: "<<p1[0]<<
" "<<p1[1]<<endl
123 <<
"\np2: "<<p2[0]<<
" "<<p2[1]<<endl
124 <<
"\nroi1 ("<<_minx1<<
", "<<_miny1<<
") <--> ("
125 <<_maxx1<<
", "<<_maxy1<<
")"
126 <<
"\nroi2 ("<<_minx2<<
", "<<_miny2<<
") <--> ("
127 <<_maxx2<<
", "<<_maxy2<<
")\n";
129 BIASASSERT(!BIAS_ISNAN(_gxx) && !BIAS_ISINF(_gxx));
130 BIASASSERT(!BIAS_ISNAN(_gxy) && !BIAS_ISINF(_gxy));
131 BIASASSERT(!BIAS_ISNAN(_gyy) && !BIAS_ISINF(_gyy));
135 BIASCDOUT(D_TRACKERB_KLT,
"iter: "<<iter<<
" _gxx: "<<_gxx<<
" _gxy: "<<_gxy
136 <<
" _gyy: "<<_gyy<<
" ex: "<<ex<<
" ey: "<<ey<<endl);
137 det = _gxx*_gyy-_gxy*_gxy;
138 if (fabs(det)<SMALL_DET) {
139 BIASDOUT(D_TRACKERB_KLT,
140 "unable to invert G, det: "<<det);
145 dx = (_gyy*ex - _gxy*ey)*_idet;
146 dy = (_gxx*ey - _gxy*ex)*_idet;
148 BIASCDOUT(D_TRACKERB_KLT,
" det: "<<det<<
" _idet: "<<_idet
149 <<
" dx: "<<dx<<
" dy: "<<dy<<endl);
152 error = (fabs(dx)>fabs(dy))?fabs(dx):fabs(dy);
169 BIASCDOUT(D_TRACKERB_KLT,
" disp after "<<iter<<
" iteration: "
170 <<result[0]-p2[0]<<
", "<<result[1]-p2[1]<<
" error: "<< error
171 <<
" ("<<result[0]<<
", "<<result[1]<<
")\n");
175 fprintf(stdout,
"iter: %i\t_gxx: %f\t_gxy: %f\t_gyy: %f\tex: %f\tey: %f\n",
176 iter, _gxx, _gxy, _gyy, ex, ey);
177 fprintf(stdout,
" \tdx: %f\tdy: %f\tcoo: (%f, %f)\n",
178 dx, dy, result[0], result[1]);
183 if (result[0]<_minx2 || result[0]>=_maxx2 ||
184 result[1]<_miny2 || result[1]>=_maxy2){
185 BIASCDOUT(D_TRACKERB_KLT,
186 "feature slid out of image, returning -2");
190 }
while (error>maxerr && iter<maxiter);
192 if (res==0 && error>maxerr && iter==maxiter) {
194 BIASCDOUT(D_TRACKERB_KLT,
"error > "<<maxerr
195 <<
" and max iteration count reached: "<<iter<<
" returning -3");
197 BilinearRegion2_(result[0],result[1],hws);
202 cerr <<
"i "<<iter<<
" res "<<res<<
" ";
203 cerr <<
"TrackSimple_ took "<<timer.
GetRealTime()<<
" us = "
217 #ifdef BUILD_IMAGE_INT
220 #ifdef BUILD_IMAGE_CHAR
223 #ifdef BUILD_IMAGE_SHORT
226 #ifdef BUILD_IMAGE_USHORT
229 #ifdef BUILD_IMAGE_UINT
232 #ifdef BUILD_IMAGE_DOUBLE
virtual int Track_(Vector2< KLT_TYPE > &p1, Vector2< KLT_TYPE > &p2, Vector2< KLT_TYPE > &result, KLT_TYPE &error, int &iter, const Matrix2x2< KLT_TYPE > &AffinePred, Matrix2x2< KLT_TYPE > &AffineResult)
Interface of all tracking algorithms implemented in derived classes.
no spatial structure is present
double GetCycleCount() const
return number of cycles between all subsequent calls to Start() and Stop() since last call to Reset()...
double GetRealTime() const
return real time (=wall time clock) in usec JW For Win32: real-time is measured differently from user...
a point lies outside of valid region in images
class TimeMeasure contains functions for timing real time and cpu time.
maxiter is reached and error is above maxerror