Browse Source

Tune the algorithm

customisations
alemart 5 months ago
parent
commit
372dd653e4

+ 4
- 3
src/trackers/image-tracker/image-tracker-utils.ts View File

305
             }
305
             }
306
 
306
 
307
             // compute the interpolation factor t = t(alpha, beta)
307
             // compute the interpolation factor t = t(alpha, beta)
308
-            // t is (clamped) alpha if beta is zero
308
+            // t is alpha if beta is zero
309
             const gamma = alpha * Math.pow(2, -beta);
309
             const gamma = alpha * Math.pow(2, -beta);
310
             const f = 1 - Math.sqrt(d[i] / max); // f is zero when d[i] is max (hence, it minimizes t and contributes to src)
310
             const f = 1 - Math.sqrt(d[i] / max); // f is zero when d[i] is max (hence, it minimizes t and contributes to src)
311
             const g = (alpha - gamma) * f + gamma; // gamma when f is zero; alpha when f is one
311
             const g = (alpha - gamma) * f + gamma; // gamma when f is zero; alpha when f is one
312
-            const t = Math.max(0, Math.min(g, 1)); // clamp
312
+            //const t = Math.max(0, Math.min(g, 1)); // clamp
313
+            const t = g; // allow extrapolation; don't clamp
313
             const _t = 1 - t;
314
             const _t = 1 - t;
314
 
315
 
315
-            // a (1-t) + b t
316
+            // a (1-t) + b t == a + (b-a) t
316
             q[ j ] = ax * _t + bx * t;
317
             q[ j ] = ax * _t + bx * t;
317
             q[j+1] = ay * _t + by * t;
318
             q[j+1] = ay * _t + by * t;
318
         }
319
         }

+ 9
- 3
src/trackers/image-tracker/settings.ts View File

111
 export const PRE_TRACK_FILTER_BETA = 1;
111
 export const PRE_TRACK_FILTER_BETA = 1;
112
 
112
 
113
 /** Maximum number of iterations in Pre-tracking B */
113
 /** Maximum number of iterations in Pre-tracking B */
114
-export const PRE_TRACK_MAX_ITERATIONS = 6; // the less the interpolation factor, the more iterations are needed
114
+export const PRE_TRACK_MAX_ITERATIONS = 8; //6; // the less the interpolation factor, the more iterations are needed
115
 
115
 
116
 /** Minimum acceptable number of matched keypoints when in the tracking state */
116
 /** Minimum acceptable number of matched keypoints when in the tracking state */
117
 export const TRACK_MIN_MATCHES = 4;//10; //20;
117
 export const TRACK_MIN_MATCHES = 4;//10; //20;
153
 export const TRACK_LOST_TOLERANCE = 20; //15;
153
 export const TRACK_LOST_TOLERANCE = 20; //15;
154
 
154
 
155
 /** Interpolation filter: interpolation factor */
155
 /** Interpolation filter: interpolation factor */
156
-export const TRACK_FILTER_ALPHA = 0.3;
156
+export const TRACK_FILTER_ALPHA = 0.3; //0.4;
157
 
157
 
158
 /** Interpolation filter: correction strength for noisy corners */
158
 /** Interpolation filter: correction strength for noisy corners */
159
 export const TRACK_FILTER_BETA = 1;
159
 export const TRACK_FILTER_BETA = 1;
162
 export const TRACK_FILTER_TAU = 0;
162
 export const TRACK_FILTER_TAU = 0;
163
 
163
 
164
 /** Interpolation filter: rotational factor */
164
 /** Interpolation filter: rotational factor */
165
-export const TRACK_FILTER_OMEGA = 0; // keep it zero or close to zero
165
+export const TRACK_FILTER_OMEGA = 0; // keep it zero or close to zero
166
+
167
+/** Extrapolation filter: extrapolation factor */
168
+export const TRACK_EXTRAPOLATION_ALPHA = 6;
169
+
170
+/** Extrapolation filter: correction strength for noisy corners */
171
+export const TRACK_EXTRAPOLATION_BETA = 1.33;

+ 19
- 3
src/trackers/image-tracker/states/tracking.ts View File

58
     TRACK_HARRIS_QUALITY, TRACK_DETECTOR_CAPACITY, TRACK_MAX_KEYPOINTS,
58
     TRACK_HARRIS_QUALITY, TRACK_DETECTOR_CAPACITY, TRACK_MAX_KEYPOINTS,
59
     TRACK_RANSAC_REPROJECTIONERROR_NDC, TRACK_MATCH_RATIO,
59
     TRACK_RANSAC_REPROJECTIONERROR_NDC, TRACK_MATCH_RATIO,
60
     TRACK_FILTER_ALPHA, TRACK_FILTER_BETA, TRACK_FILTER_TAU, TRACK_FILTER_OMEGA,
60
     TRACK_FILTER_ALPHA, TRACK_FILTER_BETA, TRACK_FILTER_TAU, TRACK_FILTER_OMEGA,
61
+    TRACK_EXTRAPOLATION_ALPHA, TRACK_EXTRAPOLATION_BETA,
61
     NIGHTVISION_QUALITY, SUBPIXEL_METHOD,
62
     NIGHTVISION_QUALITY, SUBPIXEL_METHOD,
62
 } from '../settings';
63
 } from '../settings';
63
 import { Settings } from '../../../core/settings';
64
 import { Settings } from '../../../core/settings';
89
     /** current homography (for computing the pose) */
90
     /** current homography (for computing the pose) */
90
     private _poseHomography: SpeedyMatrix;
91
     private _poseHomography: SpeedyMatrix;
91
 
92
 
93
+    /* previous homography */
94
+    private _prevHomography: SpeedyMatrix;
95
+
92
     /** initial keypoints (i.e., the keypoints we found when we first started tracking) */
96
     /** initial keypoints (i.e., the keypoints we found when we first started tracking) */
93
     private _templateKeypoints: SpeedyKeypoint[];
97
     private _templateKeypoints: SpeedyKeypoint[];
94
 
98
 
129
         this._referenceImage = null;
133
         this._referenceImage = null;
130
         this._warpHomography = Speedy.Matrix.Eye(3);
134
         this._warpHomography = Speedy.Matrix.Eye(3);
131
         this._poseHomography = Speedy.Matrix.Eye(3);
135
         this._poseHomography = Speedy.Matrix.Eye(3);
136
+        this._prevHomography = Speedy.Matrix.Eye(3);
132
         this._templateKeypoints = [];
137
         this._templateKeypoints = [];
133
         this._initialScreenSize = Speedy.Size(1, 1);
138
         this._initialScreenSize = Speedy.Size(1, 1);
134
         this._lastOutput = {};
139
         this._lastOutput = {};
159
 
164
 
160
         // set attributes
165
         // set attributes
161
         this._referenceImage = referenceImage;
166
         this._referenceImage = referenceImage;
162
-        this._warpHomography = Speedy.Matrix(homography);
163
-        this._poseHomography = Speedy.Matrix(homography);
167
+        this._warpHomography.setToSync(homography);
168
+        this._poseHomography.setToSync(homography);
169
+        this._prevHomography.setToSync(homography);
164
         this._templateKeypoints = templateKeypoints;
170
         this._templateKeypoints = templateKeypoints;
165
         this._initialScreenSize = Speedy.Size(initialScreenSize.width, initialScreenSize.height);
171
         this._initialScreenSize = Speedy.Size(initialScreenSize.width, initialScreenSize.height);
166
         this._lastOutput = {};
172
         this._lastOutput = {};
320
         .then(warpMotion => {
326
         .then(warpMotion => {
321
 
327
 
322
             // update warp homography
328
             // update warp homography
329
+            this._prevHomography.setToSync(this._warpHomography);
323
             this._warpHomography.setToSync(warpMotion.times(this._warpHomography));
330
             this._warpHomography.setToSync(warpMotion.times(this._warpHomography));
324
-            return this._warpHomography;
331
+            //return this._warpHomography;
332
+
333
+            // extrapolate to compensante a bit the delay introduced by the
334
+            // previous filter
335
+            return ImageTrackerUtils.interpolateHomographies(
336
+                this._prevHomography,
337
+                this._warpHomography,
338
+                TRACK_EXTRAPOLATION_ALPHA,
339
+                TRACK_EXTRAPOLATION_BETA
340
+            );
325
 
341
 
326
             /*
342
             /*
327
             const lowPower = (Settings.powerPreference == 'low-power');
343
             const lowPower = (Settings.powerPreference == 'low-power');

Loading…
Cancel
Save