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
      * In its simplest form, it's similar to linear interpolation: src (1-alpha) + dest alpha
231
      * In its simplest form, it's similar to linear interpolation: src (1-alpha) + dest alpha
232
      * @param src homography
232
      * @param src homography
233
      * @param dest homography
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
      * @param beta correction strength for noisy corners (optional)
235
      * @param beta correction strength for noisy corners (optional)
236
      * @param tau translation factor (optional)
236
      * @param tau translation factor (optional)
237
      * @param omega rotational factor (optional)
237
      * @param omega rotational factor (optional)
267
         let tx = 0, ty = 0, sin = 0, cos = 1;
267
         let tx = 0, ty = 0, sin = 0, cos = 1;
268
         const max = Math.max(d[0], d[1], d[2], d[3]); // max = Math.max(...d)
268
         const max = Math.max(d[0], d[1], d[2], d[3]); // max = Math.max(...d)
269
         const min = Math.min(d[0], d[1], d[2], d[3]);
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
         for(let i = 0, j = 0; i < 4; i++, j += 2) {
276
         for(let i = 0, j = 0; i < 4; i++, j += 2) {
271
             const x = p[j], y = p[j+1];
277
             const x = p[j], y = p[j+1];
272
 
278
 
282
             const bx = hbx/hbz, by = hby/hbz;
288
             const bx = hbx/hbz, by = hby/hbz;
283
 
289
 
284
             // correct noisy corners, if any
290
             // correct noisy corners, if any
285
-            if(d[i] == min && min <= 0.5 * max) {
291
+            if(d[i] == min) {
286
                 // we take the min for the translation
292
                 // we take the min for the translation
287
                 // because there may be noisy corners
293
                 // because there may be noisy corners
288
                 tx = bx - ax;
294
                 tx = bx - ax;

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

138
 export const TRACK_RECTIFIED_SCALE = 1 - 2 * TRACK_RECTIFIED_BORDER;
138
 export const TRACK_RECTIFIED_SCALE = 1 - 2 * TRACK_RECTIFIED_BORDER;
139
 
139
 
140
 /** Reprojection error, in NIS pixels, used when estimating a motion model (tracking state) */
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
 /** Reprojection error, in NDC, used when estimating a motion model (tracking state) */
143
 /** Reprojection error, in NDC, used when estimating a motion model (tracking state) */
144
 export const TRACK_RANSAC_REPROJECTIONERROR_NDC = TRACK_RANSAC_REPROJECTIONERROR_NIS / (NIS_SIZE / 2);
144
 export const TRACK_RANSAC_REPROJECTIONERROR_NDC = TRACK_RANSAC_REPROJECTIONERROR_NIS / (NIS_SIZE / 2);
147
 export const TRACK_GRID_GRANULARITY = 15; //20; //10; // the value of N
147
 export const TRACK_GRID_GRANULARITY = 15; //20; //10; // the value of N
148
 
148
 
149
 /** Used to identify the best maches */
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
 /** Number of consecutive frames in which we tolerate a  "target lost" situation */
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
 /** Interpolation filter: interpolation factor */
155
 /** Interpolation filter: interpolation factor */
156
-export const TRACK_FILTER_ALPHA = 0.2;
156
+export const TRACK_FILTER_ALPHA = 0.3;
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;
160
 
160
 
161
 /** Interpolation filter: translation factor */
161
 /** Interpolation filter: translation factor */
162
-export const TRACK_FILTER_TAU = 0.2;
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.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
         })
306
         })
307
         .then(warpMotion => {
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
             const lowPower = (Settings.powerPreference == 'low-power');
327
             const lowPower = (Settings.powerPreference == 'low-power');
310
             const delay = NUMBER_OF_PBOS * (!lowPower ? 2 : 1);
328
             const delay = NUMBER_OF_PBOS * (!lowPower ? 2 : 1);
311
 
329
 
319
             // apply filter
337
             // apply filter
320
             return ImageTrackerUtils.interpolateHomographies(
338
             return ImageTrackerUtils.interpolateHomographies(
321
                 this._poseHomography,
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
         .then(filteredHomography => {
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
             // test
352
             // test
339
             console.log("WARP ", this._warpHomography.toString());
353
             console.log("WARP ", this._warpHomography.toString());
341
             console.log("FILT ", filteredHomography.toString());
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
             // We transform the keypoints of the reference image to NDC as a
363
             // We transform the keypoints of the reference image to NDC as a
345
             // convenience. However, doing so distorts the aspect ratio. Here
364
             // convenience. However, doing so distorts the aspect ratio. Here
346
             // we undo the distortion.
365
             // we undo the distortion.

Loading…
Cancel
Save