Browse Source

Increase the stability of the tracking

customisations
alemart 5 months ago
parent
commit
8d74f24c37

+ 8
- 2
src/trackers/image-tracker/image-tracker-utils.ts View File

@@ -231,7 +231,7 @@ export class ImageTrackerUtils
231 231
      * In its simplest form, it's similar to linear interpolation: src (1-alpha) + dest alpha
232 232
      * @param src homography
233 233
      * @param dest homography
234
-     * @param alpha interpolation factor in [0,1]
234
+     * @param alpha interpolation factor in [0,1] (1 means no interpolation)
235 235
      * @param beta correction strength for noisy corners (optional)
236 236
      * @param tau translation factor (optional)
237 237
      * @param omega rotational factor (optional)
@@ -267,6 +267,12 @@ export class ImageTrackerUtils
267 267
         let tx = 0, ty = 0, sin = 0, cos = 1;
268 268
         const max = Math.max(d[0], d[1], d[2], d[3]); // max = Math.max(...d)
269 269
         const min = Math.min(d[0], d[1], d[2], d[3]);
270
+        //const quality = min / max;
271
+
272
+        // no change?
273
+        if(max < 1e-5)
274
+            return Speedy.Promise.resolve(Speedy.Matrix(dest));
275
+
270 276
         for(let i = 0, j = 0; i < 4; i++, j += 2) {
271 277
             const x = p[j], y = p[j+1];
272 278
 
@@ -282,7 +288,7 @@ export class ImageTrackerUtils
282 288
             const bx = hbx/hbz, by = hby/hbz;
283 289
 
284 290
             // correct noisy corners, if any
285
-            if(d[i] == min && min <= 0.5 * max) {
291
+            if(d[i] == min) {
286 292
                 // we take the min for the translation
287 293
                 // because there may be noisy corners
288 294
                 tx = bx - ax;

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

@@ -138,7 +138,7 @@ export const TRACK_CLIPPING_BORDER = TRACK_RECTIFIED_BORDER * 1.20; //1.25; //1.
138 138
 export const TRACK_RECTIFIED_SCALE = 1 - 2 * TRACK_RECTIFIED_BORDER;
139 139
 
140 140
 /** Reprojection error, in NIS pixels, used when estimating a motion model (tracking state) */
141
-export const TRACK_RANSAC_REPROJECTIONERROR_NIS = (NIS_SIZE * 0.0125 * 0.5) | 0;
141
+export const TRACK_RANSAC_REPROJECTIONERROR_NIS = (NIS_SIZE * 0.0125) | 0;
142 142
 
143 143
 /** Reprojection error, in NDC, used when estimating a motion model (tracking state) */
144 144
 export const TRACK_RANSAC_REPROJECTIONERROR_NDC = TRACK_RANSAC_REPROJECTIONERROR_NIS / (NIS_SIZE / 2);
@@ -147,19 +147,19 @@ export const TRACK_RANSAC_REPROJECTIONERROR_NDC = TRACK_RANSAC_REPROJECTIONERROR
147 147
 export const TRACK_GRID_GRANULARITY = 15; //20; //10; // the value of N
148 148
 
149 149
 /** Used to identify the best maches */
150
-export const TRACK_MATCH_RATIO = 0.65; // usually a value in [0.6, 0.8] - low values => strict tracking
150
+export const TRACK_MATCH_RATIO = 0.7; // usually a value in [0.6, 0.8] - low values => strict tracking
151 151
 
152 152
 /** Number of consecutive frames in which we tolerate a  "target lost" situation */
153
-export const TRACK_LOST_TOLERANCE = 15;
153
+export const TRACK_LOST_TOLERANCE = 20; //15;
154 154
 
155 155
 /** Interpolation filter: interpolation factor */
156
-export const TRACK_FILTER_ALPHA = 0.2;
156
+export const TRACK_FILTER_ALPHA = 0.3;
157 157
 
158 158
 /** Interpolation filter: correction strength for noisy corners */
159 159
 export const TRACK_FILTER_BETA = 1;
160 160
 
161 161
 /** Interpolation filter: translation factor */
162
-export const TRACK_FILTER_TAU = 0.2;
162
+export const TRACK_FILTER_TAU = 0;
163 163
 
164 164
 /** Interpolation filter: rotational factor */
165
-export const TRACK_FILTER_OMEGA = 0.05; // keep it zero or close to zero
165
+export const TRACK_FILTER_OMEGA = 0; // keep it zero or close to zero

+ 29
- 10
src/trackers/image-tracker/states/tracking.ts View File

@@ -306,6 +306,24 @@ export class ImageTrackerTrackingState extends ImageTrackerState
306 306
         })
307 307
         .then(warpMotion => {
308 308
 
309
+            // apply filter
310
+            return ImageTrackerUtils.interpolateHomographies(
311
+                NO_MOTION,
312
+                Speedy.Matrix(warpMotion),
313
+                TRACK_FILTER_ALPHA,
314
+                TRACK_FILTER_BETA,
315
+                TRACK_FILTER_TAU,
316
+                TRACK_FILTER_OMEGA
317
+            );
318
+
319
+        })
320
+        .then(warpMotion => {
321
+
322
+            // update warp homography
323
+            this._warpHomography.setToSync(warpMotion.times(this._warpHomography));
324
+            return this._warpHomography;
325
+
326
+            /*
309 327
             const lowPower = (Settings.powerPreference == 'low-power');
310 328
             const delay = NUMBER_OF_PBOS * (!lowPower ? 2 : 1);
311 329
 
@@ -319,21 +337,17 @@ export class ImageTrackerTrackingState extends ImageTrackerState
319 337
             // apply filter
320 338
             return ImageTrackerUtils.interpolateHomographies(
321 339
                 this._poseHomography,
322
-                Speedy.Matrix(warpMotion.times(this._warpHomography)),
323
-                TRACK_FILTER_ALPHA,
324
-                TRACK_FILTER_BETA,
325
-                TRACK_FILTER_TAU,
326
-                TRACK_FILTER_OMEGA
340
+                this._warpHomography,
341
+                0.4,//TRACK_FILTER_ALPHA,
342
+                1,//TRACK_FILTER_BETA,
343
+                0.4,//TRACK_FILTER_TAU,
344
+                0.05,//TRACK_FILTER_OMEGA
327 345
             );
346
+            */
328 347
 
329 348
         })
330 349
         .then(filteredHomography => {
331 350
 
332
-            // update pose homography
333
-            this._poseHomography.setToSync(filteredHomography);
334
-            if(Number.isNaN(this._poseHomography.at(0,0)))
335
-                throw new NumericalError('Bad homography'); // normalize? 1 / h33
336
-
337 351
             /*
338 352
             // test
339 353
             console.log("WARP ", this._warpHomography.toString());
@@ -341,6 +355,11 @@ export class ImageTrackerTrackingState extends ImageTrackerState
341 355
             console.log("FILT ", filteredHomography.toString());
342 356
             */
343 357
 
358
+            // update pose homography
359
+            this._poseHomography.setToSync(filteredHomography);
360
+            if(Number.isNaN(this._poseHomography.at(0,0)))
361
+                throw new NumericalError('Bad homography'); // normalize? 1 / h33
362
+
344 363
             // We transform the keypoints of the reference image to NDC as a
345 364
             // convenience. However, doing so distorts the aspect ratio. Here
346 365
             // we undo the distortion.

Loading…
Cancel
Save