Browse Source

Extend the filter

customisations
alemart 5 months ago
parent
commit
19fe1733cc

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

234
      * @param alpha interpolation factor in [0,1]
234
      * @param alpha interpolation factor in [0,1]
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
      * @returns interpolated homography
238
      * @returns interpolated homography
238
      */
239
      */
239
-    static interpolateHomographies(src: SpeedyMatrix, dest: SpeedyMatrix, alpha: number, beta: number = 0, tau: number = 0): SpeedyPromise<SpeedyMatrix>
240
+    static interpolateHomographies(src: SpeedyMatrix, dest: SpeedyMatrix, alpha: number, beta: number = 0, tau: number = 0, omega: number = 0): SpeedyPromise<SpeedyMatrix>
240
     {
241
     {
241
         const d = new Array<number>(4), q = new Array<number>(8), p = [
242
         const d = new Array<number>(4), q = new Array<number>(8), p = [
242
             // NDC
243
             // NDC
263
             d[i] = dx*dx + dy*dy;
264
             d[i] = dx*dx + dy*dy;
264
         }
265
         }
265
 
266
 
266
-        let tx = 0, ty = 0;
267
+        let tx = 0, ty = 0, sin = 0, cos = 1;
267
         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)
268
         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]);
269
         for(let i = 0, j = 0; i < 4; i++, j += 2) {
270
         for(let i = 0, j = 0; i < 4; i++, j += 2) {
277
             const hby = hb[1] * x + hb[4] * y + hb[7];
278
             const hby = hb[1] * x + hb[4] * y + hb[7];
278
             const hbz = hb[2] * x + hb[5] * y + hb[8];
279
             const hbz = hb[2] * x + hb[5] * y + hb[8];
279
 
280
 
280
-            if(d[i] == min) {
281
+            const ax = hax/haz, ay = hay/haz;
282
+            const bx = hbx/hbz, by = hby/hbz;
283
+
284
+            // correct noisy corners, if any
285
+            if(d[i] == min && min <= 0.5 * max) {
281
                 // we take the min for the translation
286
                 // we take the min for the translation
282
                 // because there may be noisy corners
287
                 // because there may be noisy corners
283
-                tx = hbx/hbz - hax/haz;
284
-                ty = hby/hbz - hay/haz;
288
+                tx = bx - ax;
289
+                ty = by - ay;
290
+
291
+                const dot = ax * bx + ay * by;
292
+                const signedArea = ax * by - ay * bx;
293
+                const la2 = ax * ax + ay * ay;
294
+                const lb2 = bx * bx + by * by;
295
+                const lalb = Math.sqrt(la2 * lb2);
296
+
297
+                sin = signedArea / lalb;
298
+                cos = dot / lalb;
285
             }
299
             }
286
 
300
 
287
             // compute the interpolation factor t = t(alpha, beta)
301
             // compute the interpolation factor t = t(alpha, beta)
288
             // t is (clamped) alpha if beta is zero
302
             // t is (clamped) alpha if beta is zero
289
             const gamma = alpha * Math.pow(2, -beta);
303
             const gamma = alpha * Math.pow(2, -beta);
290
             const f = 1 - Math.sqrt(d[i] / max); // f is zero when d[i] is max (hence, it minimizes t and contributes to src)
304
             const f = 1 - Math.sqrt(d[i] / max); // f is zero when d[i] is max (hence, it minimizes t and contributes to src)
291
-            const g = (alpha - gamma) * f + gamma;
305
+            const g = (alpha - gamma) * f + gamma; // gamma when f is zero; alpha when f is one
292
             const t = Math.max(0, Math.min(g, 1)); // clamp
306
             const t = Math.max(0, Math.min(g, 1)); // clamp
293
             const _t = 1 - t;
307
             const _t = 1 - t;
294
 
308
 
295
             // a (1-t) + b t
309
             // a (1-t) + b t
296
-            q[ j ] = (hax/haz) * _t + (hbx/hbz) * t;
297
-            q[j+1] = (hay/haz) * _t + (hby/hbz) * t;
310
+            q[ j ] = ax * _t + bx * t;
311
+            q[j+1] = ay * _t + by * t;
312
+        }
313
+
314
+        const _omega = 1 - omega;
315
+        for(let j = 0; j < 8; j += 2) {
316
+            const x = q[j], y = q[j+1];
317
+            q[ j ] = x * _omega + (x * cos - y * sin) * omega;
318
+            q[j+1] = y * _omega + (x * sin + y * cos) * omega;
298
         }
319
         }
299
 
320
 
300
         for(let j = 0; j < 8; j += 2) {
321
         for(let j = 0; j < 8; j += 2) {

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

150
 export const TRACK_FILTER_BETA = 1;
150
 export const TRACK_FILTER_BETA = 1;
151
 
151
 
152
 /** Interpolation filter: translation factor */
152
 /** Interpolation filter: translation factor */
153
-export const TRACK_FILTER_TAU = 0.2;
153
+export const TRACK_FILTER_TAU = 0.2;
154
+
155
+/** Interpolation filter: rotational factor */
156
+export const TRACK_FILTER_OMEGA = 0.05; // keep it close to zero

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

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
+    TRACK_FILTER_ALPHA, TRACK_FILTER_BETA, TRACK_FILTER_TAU, TRACK_FILTER_OMEGA,
61
     NIGHTVISION_QUALITY, SUBPIXEL_METHOD,
61
     NIGHTVISION_QUALITY, SUBPIXEL_METHOD,
62
 } from '../settings';
62
 } from '../settings';
63
 import { Settings } from '../../../core/settings';
63
 import { Settings } from '../../../core/settings';
322
                 Speedy.Matrix(warpMotion.times(this._warpHomography)),
322
                 Speedy.Matrix(warpMotion.times(this._warpHomography)),
323
                 TRACK_FILTER_ALPHA,
323
                 TRACK_FILTER_ALPHA,
324
                 TRACK_FILTER_BETA,
324
                 TRACK_FILTER_BETA,
325
-                TRACK_FILTER_TAU
325
+                TRACK_FILTER_TAU,
326
+                TRACK_FILTER_OMEGA
326
             );
327
             );
327
 
328
 
328
         })
329
         })
335
 
336
 
336
             /*
337
             /*
337
             // test
338
             // test
338
-            console.log("POSE ", this._poseHomography.toString());
339
             console.log("WARP ", this._warpHomography.toString());
339
             console.log("WARP ", this._warpHomography.toString());
340
-            console.log("AMOT ", Speedy.Matrix(warpMotion).toString());
341
-            console.log("PMOT ", Speedy.Matrix(poseMotion).toString());
340
+            console.log("POSE ", this._poseHomography.toString());
341
+            console.log("FILT ", filteredHomography.toString());
342
             */
342
             */
343
 
343
 
344
             // We transform the keypoints of the reference image to NDC as a
344
             // We transform the keypoints of the reference image to NDC as a

Loading…
Cancel
Save