Browse Source

Image Tracker: introduce spaces NIS, NDC

customisations
alemart 10 months ago
parent
commit
b0690ad5b7

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

58
 A few definitions:
58
 A few definitions:
59
 
59
 
60
 1. Viewport size:
60
 1. Viewport size:
61
-    size of the drawing buffer of the background canvas = size of the input
62
-    media, in pixels
61
+   size of the drawing buffer of the background canvas, which is the same as
62
+   the size in pixels of the input media (typically a video).
63
 
63
 
64
 2. AR screen size:
64
 2. AR screen size:
65
-    size for image processing operations, determined by the resolution of the
66
-    tracker and by the aspect ratio of the input media
65
+   size in pixels used for image processing operations. It's determined by the
66
+   resolution of the tracker and by the aspect ratio of the input media.
67
+
68
+3. Raster space:
69
+   an image space whose top-left coordinate is (0,0) and whose bottom-right
70
+   coordinate is (w-1,h-1), where (w,h) is its size. The y-axis grows downwards.
71
+
72
+4. AR Screen Space (ASS):
73
+   a raster space whose size is the AR screen size.
74
+
75
+5. Normalized Image Space (NIS):
76
+   a raster space whose size is N x N, where N = NIS_SIZE.
77
+
78
+6. Normalized Device Coordinates (NDC):
79
+   the normalized 2D space [-1,1]x[-1,1]. The origin is at the center. Also,
80
+   the y-axis grows upwards.
67
 
81
 
68
 */
82
 */
69
 
83
 
102
     /** optional keypoints */
116
     /** optional keypoints */
103
     readonly keypoints?: SpeedyKeypoint[];
117
     readonly keypoints?: SpeedyKeypoint[];
104
 
118
 
119
+    /** optional keypoints */
120
+    readonly keypointsNIS?: SpeedyKeypoint[];
121
+
105
     /** optional polyline for testing */
122
     /** optional polyline for testing */
106
     readonly polyline?: SpeedyPoint2[];
123
     readonly polyline?: SpeedyPoint2[];
107
 
124
 
125
+    /** optional polyline for testing */
126
+    readonly polylineNDC?: SpeedyPoint2[];
127
+
108
     /** optional 3x4 camera matrix in AR screen space */
128
     /** optional 3x4 camera matrix in AR screen space */
109
     readonly cameraMatrix?: SpeedyMatrix;
129
     readonly cameraMatrix?: SpeedyMatrix;
110
 
130
 
311
         // compute the screen size for image processing purposes
331
         // compute the screen size for image processing purposes
312
         // note: this may change over time...!
332
         // note: this may change over time...!
313
         const media = this._source!._internalMedia;
333
         const media = this._source!._internalMedia;
314
-        const aspectRatio = media.width / media.height;
315
-        const screenSize = Utils.resolution(this._resolution, aspectRatio);
334
+        const screenSize = this._computeScreenSize();
316
 
335
 
317
         // run the active state
336
         // run the active state
318
         const activeState = this._state[this._activeStateName];
337
         const activeState = this._state[this._activeStateName];
330
     }
349
     }
331
 
350
 
332
     /**
351
     /**
352
+     * Compute the current size of the AR screen space
353
+     * Note that this may change over time
354
+     * @returns size
355
+     * @internal
356
+     */
357
+    _computeScreenSize(): SpeedySize
358
+    {
359
+        const media = this._source!._internalMedia;
360
+        const aspectRatio = media.width / media.height;
361
+        const screenSize = Utils.resolution(this._resolution, aspectRatio);
362
+
363
+        return screenSize;
364
+    }
365
+
366
+    /**
333
      * Get reference image
367
      * Get reference image
334
      * @param keypointIndex -1 if not found
368
      * @param keypointIndex -1 if not found
335
      * @returns reference image
369
      * @returns reference image

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

29
 /** Percentage relative to the screen size adjusted to the aspect ratio of the reference image */
29
 /** Percentage relative to the screen size adjusted to the aspect ratio of the reference image */
30
 export const TRAIN_IMAGE_SCALE = 0.8; // ORB is not scale invariant
30
 export const TRAIN_IMAGE_SCALE = 0.8; // ORB is not scale invariant
31
 
31
 
32
+/** Width and height of the Normalized Image Space (NIS) */
33
+export const NIS_SIZE = 1024; // keypoint positions are stored as fixed point
34
+
32
 /** Normalized width & height of an image target, in pixels */
35
 /** Normalized width & height of an image target, in pixels */
33
-export const TRAIN_TARGET_NORMALIZED_SIZE = 1024; // keypoint positions are stored as fixed point
36
+export const TRAIN_TARGET_NORMALIZED_SIZE = NIS_SIZE; // keypoint positions are stored as fixed point
34
 
37
 
35
 /** Used to identify the best maches */
38
 /** Used to identify the best maches */
36
 export const SCAN_MATCH_RATIO = 0.7; // usually a value in [0.6, 0.8]
39
 export const SCAN_MATCH_RATIO = 0.7; // usually a value in [0.6, 0.8]
54
 export const SCAN_CONSECUTIVE_FRAMES = 30;//15;//45;
57
 export const SCAN_CONSECUTIVE_FRAMES = 30;//15;//45;
55
 
58
 
56
 /** Reprojection error, in pixels, used when estimating a motion model (scanning state) */
59
 /** Reprojection error, in pixels, used when estimating a motion model (scanning state) */
57
-export const SCAN_RANSAC_REPROJECTIONERROR = 5;
60
+//export const SCAN_RANSAC_REPROJECTIONERROR = 5;
61
+
62
+/** Reprojection error, in NIS pixels, used when estimating a motion model (scanning state) */
63
+export const SCAN_RANSAC_REPROJECTIONERROR_NIS = (NIS_SIZE * 0.02) | 0;
64
+
65
+/** Reprojection error, in NDC, used when estimating a motion model (scanning state) */
66
+export const SCAN_RANSAC_REPROJECTIONERROR_NDC = SCAN_RANSAC_REPROJECTIONERROR_NIS / (NIS_SIZE / 2);
58
 
67
 
59
 /** Number of tables used in the LSH-based keypoint matching */
68
 /** Number of tables used in the LSH-based keypoint matching */
60
 export const SCAN_LSH_TABLES = 8; // up to 32
69
 export const SCAN_LSH_TABLES = 8; // up to 32
119
 /** Reprojection error, in pixels, used when estimating a motion model (tracking state) */
128
 /** Reprojection error, in pixels, used when estimating a motion model (tracking state) */
120
 export const TRACK_RANSAC_REPROJECTIONERROR = 3; //2.5;
129
 export const TRACK_RANSAC_REPROJECTIONERROR = 3; //2.5;
121
 
130
 
131
+// FIXME
132
+
133
+/** Reprojection error, in NIS pixels, used when estimating a motion model (tracking state) */
134
+export const TRACK_RANSAC_REPROJECTIONERROR_NIS = (NIS_SIZE * 0.0125) | 0;
135
+
136
+/** Reprojection error, in NDC, used when estimating a motion model (tracking state) */
137
+export const TRACK_RANSAC_REPROJECTIONERROR_NDC = TRACK_RANSAC_REPROJECTIONERROR_NIS / (NIS_SIZE / 2);
138
+
122
 /** We use a N x N grid to spatially distribute the keypoints in order to compute a better homography */
139
 /** We use a N x N grid to spatially distribute the keypoints in order to compute a better homography */
123
 export const TRACK_GRID_GRANULARITY = 10; //20; // the value of N
140
 export const TRACK_GRID_GRANULARITY = 10; //20; // the value of N
124
 
141
 

Loading…
Cancel
Save