瀏覽代碼

Tune the algorithm to increase the stability of the tracking

customisations
alemart 5 月之前
父節點
當前提交
04fb86b3ea
共有 3 個文件被更改,包括 34 次插入16 次删除
  1. 1
    0
      src/geometry/pnp.ts
  2. 12
    3
      src/trackers/image-tracker/settings.ts
  3. 21
    13
      src/trackers/image-tracker/states/tracking.ts

+ 1
- 0
src/geometry/pnp.ts 查看文件

902
         // We're just using n = 4. We'll refine the homography later.
902
         // We're just using n = 4. We'll refine the homography later.
903
         const newPose = pose;
903
         const newPose = pose;
904
         const newError = error;
904
         const newError = error;
905
+        //const newError = n - count;
905
 
906
 
906
         // Not the best model? Discard it
907
         // Not the best model? Discard it
907
         if(newError > bestError)
908
         if(newError > bestError)

+ 12
- 3
src/trackers/image-tracker/settings.ts 查看文件

129
 export const TRACK_RECTIFIED_SCALE = 1 - 2 * TRACK_RECTIFIED_BORDER;
129
 export const TRACK_RECTIFIED_SCALE = 1 - 2 * TRACK_RECTIFIED_BORDER;
130
 
130
 
131
 /** Reprojection error, in NIS pixels, used when estimating a motion model (tracking state) */
131
 /** Reprojection error, in NIS pixels, used when estimating a motion model (tracking state) */
132
-export const TRACK_RANSAC_REPROJECTIONERROR_NIS = (NIS_SIZE * 0.0125) | 0;
132
+export const TRACK_RANSAC_REPROJECTIONERROR_NIS = (NIS_SIZE * 0.0125 * 0.5) | 0;
133
 
133
 
134
 /** Reprojection error, in NDC, used when estimating a motion model (tracking state) */
134
 /** Reprojection error, in NDC, used when estimating a motion model (tracking state) */
135
 export const TRACK_RANSAC_REPROJECTIONERROR_NDC = TRACK_RANSAC_REPROJECTIONERROR_NIS / (NIS_SIZE / 2);
135
 export const TRACK_RANSAC_REPROJECTIONERROR_NDC = TRACK_RANSAC_REPROJECTIONERROR_NIS / (NIS_SIZE / 2);
136
 
136
 
137
 /** We use a N x N grid to spatially distribute the keypoints in order to compute a better homography */
137
 /** We use a N x N grid to spatially distribute the keypoints in order to compute a better homography */
138
-export const TRACK_GRID_GRANULARITY = 10; //20; // the value of N
138
+export const TRACK_GRID_GRANULARITY = 15; //20; //10; // the value of N
139
 
139
 
140
 /** Used to identify the best maches */
140
 /** Used to identify the best maches */
141
 export const TRACK_MATCH_RATIO = 0.7; // usually a value in [0.6, 0.8] - low values => strict tracking
141
 export const TRACK_MATCH_RATIO = 0.7; // usually a value in [0.6, 0.8] - low values => strict tracking
142
 
142
 
143
 /** Number of consecutive frames in which we tolerate a  "target lost" situation */
143
 /** Number of consecutive frames in which we tolerate a  "target lost" situation */
144
-export const TRACK_LOST_TOLERANCE = 15;
144
+export const TRACK_LOST_TOLERANCE = 15;
145
+
146
+/** Interpolation filter: interpolation factor */
147
+export const TRACK_FILTER_ALPHA = 0.125;
148
+
149
+/** Interpolation filter: correction strength for noisy corners */
150
+export const TRACK_FILTER_BETA = 1;
151
+
152
+/** Interpolation filter: translation factor */
153
+export const TRACK_FILTER_TAU = 0.25;

+ 21
- 13
src/trackers/image-tracker/states/tracking.ts 查看文件

57
     SUBPIXEL_GAUSSIAN_KSIZE, SUBPIXEL_GAUSSIAN_SIGMA,
57
     SUBPIXEL_GAUSSIAN_KSIZE, SUBPIXEL_GAUSSIAN_SIGMA,
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,
60
     NIGHTVISION_QUALITY, SUBPIXEL_METHOD,
61
     NIGHTVISION_QUALITY, SUBPIXEL_METHOD,
61
 } from '../settings';
62
 } from '../settings';
62
 import { Settings } from '../../../core/settings';
63
 import { Settings } from '../../../core/settings';
298
             if(pairs.length < TRACK_MIN_MATCHES)
299
             if(pairs.length < TRACK_MIN_MATCHES)
299
                 throw new TrackingError('Not enough data points to continue the tracking');
300
                 throw new TrackingError('Not enough data points to continue the tracking');
300
 
301
 
301
-            // find motion models
302
+            // find motion model
302
             const points = ImageTrackerUtils.compilePairsOfKeypointsNDC(pairs);
303
             const points = ImageTrackerUtils.compilePairsOfKeypointsNDC(pairs);
303
-            return Speedy.Promise.all<SpeedyMatrixExpr>([
304
-                //this._findAffineMotionNDC(points),
305
-                //this._findPerspectiveMotionNDC(points),
306
-                this._find6DoFPerspectiveMotionNDC(points),
307
-                Speedy.Promise.resolve(NO_MOTION),
308
-            ]);
304
+            return this._find6DoFPerspectiveMotionNDC(points);
309
 
305
 
310
         })
306
         })
311
-        .then(([warpMotion, poseMotion]) => {
307
+        .then(warpMotion => {
312
 
308
 
313
             const lowPower = (Settings.powerPreference == 'low-power');
309
             const lowPower = (Settings.powerPreference == 'low-power');
314
             const delay = NUMBER_OF_PBOS * (!lowPower ? 2 : 1);
310
             const delay = NUMBER_OF_PBOS * (!lowPower ? 2 : 1);
317
             if(!USE_TURBO || this._counter % delay == 1) // skip the first frame (PBOs)
313
             if(!USE_TURBO || this._counter % delay == 1) // skip the first frame (PBOs)
318
                 this._warpHomography.setToSync(warpMotion.times(this._warpHomography));
314
                 this._warpHomography.setToSync(warpMotion.times(this._warpHomography));
319
 
315
 
316
+            // update counter
317
+            this._counter = (this._counter + 1) % delay;
318
+
319
+            // apply filter
320
+            return ImageTrackerUtils.interpolateHomographies(
321
+                this._poseHomography,
322
+                Speedy.Matrix(warpMotion.times(this._warpHomography)),
323
+                TRACK_FILTER_ALPHA,
324
+                TRACK_FILTER_BETA,
325
+                TRACK_FILTER_TAU
326
+            );
327
+
328
+        })
329
+        .then(filteredHomography => {
330
+
320
             // update pose homography
331
             // update pose homography
321
-            //poseMotion = warpMotion; // commented: reduce jitter, increase delay
322
-            this._poseHomography.setToSync(poseMotion.times(this._warpHomography));
332
+            this._poseHomography.setToSync(filteredHomography);
323
             if(Number.isNaN(this._poseHomography.at(0,0)))
333
             if(Number.isNaN(this._poseHomography.at(0,0)))
324
                 throw new NumericalError('Bad homography'); // normalize? 1 / h33
334
                 throw new NumericalError('Bad homography'); // normalize? 1 / h33
325
 
335
 
326
-            // update counter
327
-            this._counter = (this._counter + 1) % delay;
328
-
329
             /*
336
             /*
330
             // test
337
             // test
331
             console.log("POSE ", this._poseHomography.toString());
338
             console.log("POSE ", this._poseHomography.toString());
344
 
351
 
345
             // update camera model
352
             // update camera model
346
             return this._camera.update(homography);
353
             return this._camera.update(homography);
354
+
347
         })
355
         })
348
         .then(() => {
356
         .then(() => {
349
 
357
 

Loading…
取消
儲存