Przeglądaj źródła

Tune the algorithm

customisations
alemart 5 miesięcy temu
rodzic
commit
372dd653e4

+ 4
- 3
src/trackers/image-tracker/image-tracker-utils.ts Wyświetl plik

@@ -305,14 +305,15 @@ export class ImageTrackerUtils
305 305
             }
306 306
 
307 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 309
             const gamma = alpha * Math.pow(2, -beta);
310 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 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 314
             const _t = 1 - t;
314 315
 
315
-            // a (1-t) + b t
316
+            // a (1-t) + b t == a + (b-a) t
316 317
             q[ j ] = ax * _t + bx * t;
317 318
             q[j+1] = ay * _t + by * t;
318 319
         }

+ 9
- 3
src/trackers/image-tracker/settings.ts Wyświetl plik

@@ -111,7 +111,7 @@ export const PRE_TRACK_FILTER_ALPHA = 0.8;
111 111
 export const PRE_TRACK_FILTER_BETA = 1;
112 112
 
113 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 116
 /** Minimum acceptable number of matched keypoints when in the tracking state */
117 117
 export const TRACK_MIN_MATCHES = 4;//10; //20;
@@ -153,7 +153,7 @@ export const TRACK_MATCH_RATIO = 0.7; // usually a value in [0.6, 0.8] - low val
153 153
 export const TRACK_LOST_TOLERANCE = 20; //15;
154 154
 
155 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 158
 /** Interpolation filter: correction strength for noisy corners */
159 159
 export const TRACK_FILTER_BETA = 1;
@@ -162,4 +162,10 @@ export const TRACK_FILTER_BETA = 1;
162 162
 export const TRACK_FILTER_TAU = 0;
163 163
 
164 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 Wyświetl plik

@@ -58,6 +58,7 @@ import {
58 58
     TRACK_HARRIS_QUALITY, TRACK_DETECTOR_CAPACITY, TRACK_MAX_KEYPOINTS,
59 59
     TRACK_RANSAC_REPROJECTIONERROR_NDC, TRACK_MATCH_RATIO,
60 60
     TRACK_FILTER_ALPHA, TRACK_FILTER_BETA, TRACK_FILTER_TAU, TRACK_FILTER_OMEGA,
61
+    TRACK_EXTRAPOLATION_ALPHA, TRACK_EXTRAPOLATION_BETA,
61 62
     NIGHTVISION_QUALITY, SUBPIXEL_METHOD,
62 63
 } from '../settings';
63 64
 import { Settings } from '../../../core/settings';
@@ -89,6 +90,9 @@ export class ImageTrackerTrackingState extends ImageTrackerState
89 90
     /** current homography (for computing the pose) */
90 91
     private _poseHomography: SpeedyMatrix;
91 92
 
93
+    /* previous homography */
94
+    private _prevHomography: SpeedyMatrix;
95
+
92 96
     /** initial keypoints (i.e., the keypoints we found when we first started tracking) */
93 97
     private _templateKeypoints: SpeedyKeypoint[];
94 98
 
@@ -129,6 +133,7 @@ export class ImageTrackerTrackingState extends ImageTrackerState
129 133
         this._referenceImage = null;
130 134
         this._warpHomography = Speedy.Matrix.Eye(3);
131 135
         this._poseHomography = Speedy.Matrix.Eye(3);
136
+        this._prevHomography = Speedy.Matrix.Eye(3);
132 137
         this._templateKeypoints = [];
133 138
         this._initialScreenSize = Speedy.Size(1, 1);
134 139
         this._lastOutput = {};
@@ -159,8 +164,9 @@ export class ImageTrackerTrackingState extends ImageTrackerState
159 164
 
160 165
         // set attributes
161 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 170
         this._templateKeypoints = templateKeypoints;
165 171
         this._initialScreenSize = Speedy.Size(initialScreenSize.width, initialScreenSize.height);
166 172
         this._lastOutput = {};
@@ -320,8 +326,18 @@ export class ImageTrackerTrackingState extends ImageTrackerState
320 326
         .then(warpMotion => {
321 327
 
322 328
             // update warp homography
329
+            this._prevHomography.setToSync(this._warpHomography);
323 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 343
             const lowPower = (Settings.powerPreference == 'low-power');

Ładowanie…
Anuluj
Zapisz