|
@@ -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();
|