浏览代码

Update _renderAxes() to match the updated CameraModel

customisations
alemart 9 个月前
父节点
当前提交
2de3421f85
共有 2 个文件被更改,包括 20 次插入27 次删除
  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 查看文件

@@ -53,6 +53,7 @@ import { ImageTrackerEvent, ImageTrackerEventType } from './image-tracker-event'
53 53
 import { SpeedyPoint2 } from 'speedy-vision/types/core/speedy-point';
54 54
 import { Viewer } from '../../geometry/viewer';
55 55
 import { Pose } from '../../geometry/pose';
56
+import { CameraModel } from '../../geometry/camera-model';
56 57
 
57 58
 /** A trackable target */
58 59
 export interface TrackableImage extends Trackable
@@ -83,26 +84,17 @@ export interface ImageTrackerOutput extends TrackerOutput
83 84
     /** tracker result to be consumed by the user */
84 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 88
     readonly keypoints?: SpeedyKeypoint[];
91 89
 
92
-    /** optional keypoints */
90
+    /** optional keypoints for visualizing & testing */
93 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 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 100
 /** All possible states of an Image Tracker */

+ 14
- 13
src/ui/gizmos.ts 查看文件

@@ -26,6 +26,7 @@ import { SpeedySize } from 'speedy-vision/types/core/speedy-size';
26 26
 import { SpeedyMatrix } from 'speedy-vision/types/core/speedy-matrix';
27 27
 import { SpeedyKeypoint, SpeedyMatchedKeypoint } from 'speedy-vision/types/core/speedy-keypoint';
28 28
 import { Viewport } from '../core/viewport';
29
+import { CameraModel } from '../geometry/camera-model';
29 30
 import { Tracker, TrackerOutput } from '../trackers/tracker';
30 31
 import { ImageTrackerOutput } from '../trackers/image-tracker/image-tracker';
31 32
 import { NIS_SIZE } from '../trackers/image-tracker/settings';
@@ -125,8 +126,7 @@ class ImageTrackerGizmos implements GizmosRenderer
125 126
         const viewportSize = viewport._realSize;
126 127
         const keypointsNIS = output.keypointsNIS;
127 128
         const polylineNDC = output.polylineNDC;
128
-        const cameraMatrix = output.cameraMatrix;
129
-        const screenSize = output.screenSize;
129
+        const camera = output.camera;
130 130
 
131 131
         // debug
132 132
         //ctx.fillStyle = '#000';
@@ -142,8 +142,8 @@ class ImageTrackerGizmos implements GizmosRenderer
142 142
             this._renderPolylineNDC(ctx, polylineNDC, viewportSize);
143 143
 
144 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,22 +259,23 @@ class ImageTrackerGizmos implements GizmosRenderer
259 259
     /**
260 260
      * Render the axes of a 3D coordinate system
261 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 263
      * @param viewportSize viewport size
265 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 268
         const RED = '#f00', GREEN = '#0f0', BLUE = '#00f';
270 269
         const color = [ RED, GREEN, BLUE ]; // color of each axis: (X,Y,Z)
271 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 280
         [ 0  L  0  0 ]
280 281
         [ 0  0  L  0 ] , where L = length in normalized space of the lines
@@ -288,7 +289,7 @@ class ImageTrackerGizmos implements GizmosRenderer
288 289
 
289 290
         */
290 291
 
291
-        const p = cameraMatrix.read();
292
+        const p = camera.matrix.read();
292 293
         const l = length;
293 294
         const o = [ p[9], p[10], p[11] ]; // origin of the coordinate system
294 295
         const x = [ l*p[0]+p[9], l*p[1]+p[10], l*p[2]+p[11] ]; // x-axis
@@ -303,8 +304,8 @@ class ImageTrackerGizmos implements GizmosRenderer
303 304
             const x = q[0] / q[2], y = q[1] / q[2];
304 305
 
305 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 309
             ctx.strokeStyle = color[i];
309 310
             ctx.lineWidth = lineWidth;
310 311
             ctx.stroke();

正在加载...
取消
保存