Browse Source

Update _renderAxes() to match the updated CameraModel

customisations
alemart 9 months ago
parent
commit
2de3421f85
2 changed files with 20 additions and 27 deletions
  1. 6
    14
      src/trackers/image-tracker/image-tracker.ts
  2. 14
    13
      src/ui/gizmos.ts

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

53
 import { SpeedyPoint2 } from 'speedy-vision/types/core/speedy-point';
53
 import { SpeedyPoint2 } from 'speedy-vision/types/core/speedy-point';
54
 import { Viewer } from '../../geometry/viewer';
54
 import { Viewer } from '../../geometry/viewer';
55
 import { Pose } from '../../geometry/pose';
55
 import { Pose } from '../../geometry/pose';
56
+import { CameraModel } from '../../geometry/camera-model';
56
 
57
 
57
 /** A trackable target */
58
 /** A trackable target */
58
 export interface TrackableImage extends Trackable
59
 export interface TrackableImage extends Trackable
83
     /** tracker result to be consumed by the user */
84
     /** tracker result to be consumed by the user */
84
     readonly exports?: ImageTrackerResult;
85
     readonly exports?: ImageTrackerResult;
85
 
86
 
86
-    /** size of the AR screen space, in pixels */
87
-    readonly screenSize?: SpeedySize;
88
-
89
-    /** optional keypoints */
87
+    /** keypoints found in this framestep */
90
     readonly keypoints?: SpeedyKeypoint[];
88
     readonly keypoints?: SpeedyKeypoint[];
91
 
89
 
92
-    /** optional keypoints */
90
+    /** optional keypoints for visualizing & testing */
93
     readonly keypointsNIS?: SpeedyKeypoint[];
91
     readonly keypointsNIS?: SpeedyKeypoint[];
94
 
92
 
95
-    /** optional polyline for testing */
96
-    readonly polyline?: SpeedyPoint2[];
97
-
98
-    /** optional polyline for testing */
93
+    /** optional polyline for visualizing & testing */
99
     readonly polylineNDC?: SpeedyPoint2[];
94
     readonly polylineNDC?: SpeedyPoint2[];
100
 
95
 
101
-    /** optional 3x4 camera matrix in AR screen space */
102
-    readonly cameraMatrix?: SpeedyMatrix;
103
-
104
-    /** 3x3 homography in AR screen space */
105
-    homography?: SpeedyMatrix;
96
+    /** optional camera model for visualizing & testing */
97
+    readonly camera?: CameraModel;
106
 }
98
 }
107
 
99
 
108
 /** All possible states of an Image Tracker */
100
 /** All possible states of an Image Tracker */

+ 14
- 13
src/ui/gizmos.ts View File

26
 import { SpeedyMatrix } from 'speedy-vision/types/core/speedy-matrix';
26
 import { SpeedyMatrix } from 'speedy-vision/types/core/speedy-matrix';
27
 import { SpeedyKeypoint, SpeedyMatchedKeypoint } from 'speedy-vision/types/core/speedy-keypoint';
27
 import { SpeedyKeypoint, SpeedyMatchedKeypoint } from 'speedy-vision/types/core/speedy-keypoint';
28
 import { Viewport } from '../core/viewport';
28
 import { Viewport } from '../core/viewport';
29
+import { CameraModel } from '../geometry/camera-model';
29
 import { Tracker, TrackerOutput } from '../trackers/tracker';
30
 import { Tracker, TrackerOutput } from '../trackers/tracker';
30
 import { ImageTrackerOutput } from '../trackers/image-tracker/image-tracker';
31
 import { ImageTrackerOutput } from '../trackers/image-tracker/image-tracker';
31
 import { NIS_SIZE } from '../trackers/image-tracker/settings';
32
 import { NIS_SIZE } from '../trackers/image-tracker/settings';
125
         const viewportSize = viewport._realSize;
126
         const viewportSize = viewport._realSize;
126
         const keypointsNIS = output.keypointsNIS;
127
         const keypointsNIS = output.keypointsNIS;
127
         const polylineNDC = output.polylineNDC;
128
         const polylineNDC = output.polylineNDC;
128
-        const cameraMatrix = output.cameraMatrix;
129
-        const screenSize = output.screenSize;
129
+        const camera = output.camera;
130
 
130
 
131
         // debug
131
         // debug
132
         //ctx.fillStyle = '#000';
132
         //ctx.fillStyle = '#000';
142
             this._renderPolylineNDC(ctx, polylineNDC, viewportSize);
142
             this._renderPolylineNDC(ctx, polylineNDC, viewportSize);
143
 
143
 
144
         // render the axes of the 3D coordinate system
144
         // render the axes of the 3D coordinate system
145
-        if(cameraMatrix !== undefined && screenSize !== undefined)
146
-            this._renderAxes(ctx, cameraMatrix, screenSize, viewportSize);
145
+        if(camera !== undefined)
146
+            this._renderAxes(ctx, camera, viewportSize);
147
     }
147
     }
148
 
148
 
149
     /**
149
     /**
259
     /**
259
     /**
260
      * Render the axes of a 3D coordinate system
260
      * Render the axes of a 3D coordinate system
261
      * @param ctx canvas 2D context
261
      * @param ctx canvas 2D context
262
-     * @param cameraMatrix 3x4 camera matrix that maps normalized coordinates [-1,1]^3 to AR screen space
263
-     * @param screenSize AR screen size
262
+     * @param camera camera model
264
      * @param viewportSize viewport size
263
      * @param viewportSize viewport size
265
      * @param lineWidth
264
      * @param lineWidth
266
      */
265
      */
267
-    private _renderAxes(ctx: CanvasRenderingContext2D, cameraMatrix: SpeedyMatrix, screenSize: SpeedySize, viewportSize: SpeedySize, lineWidth = 4): void
266
+    private _renderAxes(ctx: CanvasRenderingContext2D, camera: CameraModel, viewportSize: SpeedySize, lineWidth = 4): void
268
     {
267
     {
269
         const RED = '#f00', GREEN = '#0f0', BLUE = '#00f';
268
         const RED = '#f00', GREEN = '#0f0', BLUE = '#00f';
270
         const color = [ RED, GREEN, BLUE ]; // color of each axis: (X,Y,Z)
269
         const color = [ RED, GREEN, BLUE ]; // color of each axis: (X,Y,Z)
271
         const length = 1; // length of each axis-corresponding line, given in normalized space units
270
         const length = 1; // length of each axis-corresponding line, given in normalized space units
272
-        const sx = viewportSize.width / screenSize.width;
273
-        const sy = viewportSize.height / screenSize.height;
271
+        const w = viewportSize.width;
272
+        const h = viewportSize.height;
273
+        const iw = 1 / (camera.imageSize.width / 2);
274
+        const ih = -1 / (camera.imageSize.height / 2);
274
 
275
 
275
         /*
276
         /*
276
 
277
 
277
-        Multiply the 3x4 camera matrix P by:
278
+        Multiply the 3x4 camera matrix by:
278
 
279
 
279
         [ 0  L  0  0 ]
280
         [ 0  L  0  0 ]
280
         [ 0  0  L  0 ] , where L = length in normalized space of the lines
281
         [ 0  0  L  0 ] , where L = length in normalized space of the lines
288
 
289
 
289
         */
290
         */
290
 
291
 
291
-        const p = cameraMatrix.read();
292
+        const p = camera.matrix.read();
292
         const l = length;
293
         const l = length;
293
         const o = [ p[9], p[10], p[11] ]; // origin of the coordinate system
294
         const o = [ p[9], p[10], p[11] ]; // origin of the coordinate system
294
         const x = [ l*p[0]+p[9], l*p[1]+p[10], l*p[2]+p[11] ]; // x-axis
295
         const x = [ l*p[0]+p[9], l*p[1]+p[10], l*p[2]+p[11] ]; // x-axis
303
             const x = q[0] / q[2], y = q[1] / q[2];
304
             const x = q[0] / q[2], y = q[1] / q[2];
304
 
305
 
305
             ctx.beginPath();
306
             ctx.beginPath();
306
-            ctx.moveTo(ox * sx, oy * sy);
307
-            ctx.lineTo(x * sx, y * sy);
307
+            ctx.moveTo((ox * iw * 0.5 + 0.5) * w, (oy * ih * 0.5 + 0.5) * h);
308
+            ctx.lineTo((x * iw * 0.5 + 0.5) * w, (y * ih * 0.5 + 0.5) * h);
308
             ctx.strokeStyle = color[i];
309
             ctx.strokeStyle = color[i];
309
             ctx.lineWidth = lineWidth;
310
             ctx.lineWidth = lineWidth;
310
             ctx.stroke();
311
             ctx.stroke();

Loading…
Cancel
Save