@zappar/zappar-cv 3.0.1-alpha.5 → 3.0.1-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +2 -2
  2. package/lib/gen/zappar-bridge.d.ts +13 -0
  3. package/lib/gen/zappar-bridge.js +1 -0
  4. package/lib/gen/zappar-client.d.ts +1 -0
  5. package/lib/gen/zappar-client.js +125 -16
  6. package/lib/gen/zappar-cwrap.js +81 -3
  7. package/lib/gen/zappar-native.d.ts +17 -1
  8. package/lib/gen/zappar-native.js +6 -0
  9. package/lib/gen/zappar-server.d.ts +3 -0
  10. package/lib/gen/zappar-server.js +81 -15
  11. package/lib/gen/zappar.d.ts +17 -0
  12. package/lib/gen/zappar.js +1 -0
  13. package/lib/html-element-source.d.ts +3 -1
  14. package/lib/html-element-source.js +12 -6
  15. package/lib/image-process-gl.d.ts +3 -2
  16. package/lib/image-process-gl.js +9 -7
  17. package/lib/imagebitmap-camera-source.d.ts +3 -1
  18. package/lib/imagebitmap-camera-source.js +10 -4
  19. package/lib/index.d.ts +1 -1
  20. package/lib/index.js +1 -1
  21. package/lib/mstp-camera-source.d.ts +2 -1
  22. package/lib/mstp-camera-source.js +5 -0
  23. package/lib/native.js +20 -1
  24. package/lib/pipeline.d.ts +3 -1
  25. package/lib/pipeline.js +12 -2
  26. package/lib/profile.d.ts +2 -2
  27. package/lib/profile.js +3 -3
  28. package/lib/version.d.ts +1 -1
  29. package/lib/version.js +1 -1
  30. package/lib/worker-imagebitmap.js +5 -4
  31. package/lib/worker-server.js +19 -8
  32. package/lib/workerinterface.d.ts +8 -1
  33. package/lib/zappar-cv.js +203 -166
  34. package/lib/zappar-cv.wasm +0 -0
  35. package/package.json +1 -1
  36. package/umd/{17cb8e68ad2789719d7f.wasm → 5a86c8fa5c139c48ad64.wasm} +0 -0
  37. package/umd/751.zappar-cv.js +1 -1
  38. package/umd/867.zappar-cv.js +1 -1
  39. package/umd/zappar-cv.js +1 -1
  40. package/umd/zappar-cv.worker.js +1 -1
@@ -24,6 +24,8 @@ export class zappar_server {
24
24
  this._barcode_finder_by_instance = new Map();
25
25
  this._pipeline_id_by_instant_world_tracker_id = new Map();
26
26
  this._instant_world_tracker_by_instance = new Map();
27
+ this._pipeline_id_by_zapcode_tracker_id = new Map();
28
+ this._zapcode_tracker_by_instance = new Map();
27
29
  this._pipeline_id_by_world_tracker_id = new Map();
28
30
  this._world_tracker_by_instance = new Map();
29
31
  }
@@ -351,6 +353,40 @@ export class zappar_server {
351
353
  break;
352
354
  }
353
355
  case 41: {
356
+ let clientId = msg.type();
357
+ let arg_pipeline_id = msg.type();
358
+ let arg_pipeline = this._pipeline_by_instance.get(arg_pipeline_id);
359
+ let handle = this._impl.zapcode_tracker_create(arg_pipeline);
360
+ this._zapcode_tracker_by_instance.set(clientId, handle);
361
+ this._pipeline_id_by_zapcode_tracker_id.set(clientId, arg_pipeline_id);
362
+ break;
363
+ }
364
+ case 44: {
365
+ let clientId = msg.type();
366
+ let obj = this._zapcode_tracker_by_instance.get(clientId);
367
+ if (obj === undefined)
368
+ return;
369
+ this._impl.zapcode_tracker_destroy(obj);
370
+ this._zapcode_tracker_by_instance.delete(clientId);
371
+ break;
372
+ }
373
+ case 43: {
374
+ let clientId = msg.type();
375
+ let obj = this._zapcode_tracker_by_instance.get(clientId);
376
+ if (obj === undefined)
377
+ return;
378
+ this._impl.zapcode_tracker_target_load_from_memory(obj, msg.dataWithLength());
379
+ break;
380
+ }
381
+ case 42: {
382
+ let clientId = msg.type();
383
+ let obj = this._zapcode_tracker_by_instance.get(clientId);
384
+ if (obj === undefined)
385
+ return;
386
+ this._impl.zapcode_tracker_enabled_set(obj, msg.bool());
387
+ break;
388
+ }
389
+ case 45: {
354
390
  let clientId = msg.type();
355
391
  let arg_pipeline_id = msg.type();
356
392
  let arg_pipeline = this._pipeline_by_instance.get(arg_pipeline_id);
@@ -359,7 +395,7 @@ export class zappar_server {
359
395
  this._pipeline_id_by_world_tracker_id.set(clientId, arg_pipeline_id);
360
396
  break;
361
397
  }
362
- case 42: {
398
+ case 46: {
363
399
  let clientId = msg.type();
364
400
  let obj = this._world_tracker_by_instance.get(clientId);
365
401
  if (obj === undefined)
@@ -368,7 +404,7 @@ export class zappar_server {
368
404
  this._world_tracker_by_instance.delete(clientId);
369
405
  break;
370
406
  }
371
- case 43: {
407
+ case 47: {
372
408
  let clientId = msg.type();
373
409
  let obj = this._world_tracker_by_instance.get(clientId);
374
410
  if (obj === undefined)
@@ -376,7 +412,7 @@ export class zappar_server {
376
412
  this._impl.world_tracker_enabled_set(obj, msg.bool());
377
413
  break;
378
414
  }
379
- case 44: {
415
+ case 48: {
380
416
  let clientId = msg.type();
381
417
  let obj = this._world_tracker_by_instance.get(clientId);
382
418
  if (obj === undefined)
@@ -384,7 +420,7 @@ export class zappar_server {
384
420
  this._impl.world_tracker_reset(obj);
385
421
  break;
386
422
  }
387
- case 45: {
423
+ case 49: {
388
424
  let clientId = msg.type();
389
425
  let obj = this._world_tracker_by_instance.get(clientId);
390
426
  if (obj === undefined)
@@ -568,6 +604,36 @@ export class zappar_server {
568
604
  msg.matrix4x4(this._impl.instant_world_tracker_anchor_pose_raw(v));
569
605
  });
570
606
  }
607
+ for (let [k, v] of this._zapcode_tracker_by_instance) {
608
+ let pipeline = this._pipeline_id_by_zapcode_tracker_id.get(k);
609
+ if (!pipeline)
610
+ continue;
611
+ let serializer = this.serializersByPipelineId.get(pipeline);
612
+ if (!serializer)
613
+ continue;
614
+ serializer.sendMessage(24, msg => {
615
+ msg.type(k);
616
+ msg.int(this._impl.zapcode_tracker_target_loaded_version(v));
617
+ });
618
+ serializer.sendMessage(21, msg => {
619
+ msg.type(k);
620
+ msg.int(this._impl.zapcode_tracker_anchor_count(v));
621
+ });
622
+ for (let i = 0; i < this._impl.zapcode_tracker_anchor_count(v); i++) {
623
+ serializer.sendMessage(22, msg => {
624
+ msg.type(k);
625
+ msg.int(i);
626
+ msg.string(this._impl.zapcode_tracker_anchor_id(v, i));
627
+ });
628
+ }
629
+ for (let i = 0; i < this._impl.zapcode_tracker_anchor_count(v); i++) {
630
+ serializer.sendMessage(23, msg => {
631
+ msg.type(k);
632
+ msg.int(i);
633
+ msg.matrix4x4(this._impl.zapcode_tracker_anchor_pose_raw(v, i));
634
+ });
635
+ }
636
+ }
571
637
  for (let [k, v] of this._world_tracker_by_instance) {
572
638
  let pipeline = this._pipeline_id_by_world_tracker_id.get(k);
573
639
  if (!pipeline)
@@ -575,50 +641,50 @@ export class zappar_server {
575
641
  let serializer = this.serializersByPipelineId.get(pipeline);
576
642
  if (!serializer)
577
643
  continue;
578
- serializer.sendMessage(27, msg => {
644
+ serializer.sendMessage(31, msg => {
579
645
  msg.type(k);
580
646
  msg.int(this._impl.world_tracker_quality(v));
581
647
  });
582
- serializer.sendMessage(21, msg => {
648
+ serializer.sendMessage(25, msg => {
583
649
  msg.type(k);
584
650
  msg.int(this._impl.world_tracker_plane_count(v));
585
651
  });
586
652
  for (let i = 0; i < this._impl.world_tracker_plane_count(v); i++) {
587
- serializer.sendMessage(22, msg => {
653
+ serializer.sendMessage(26, msg => {
588
654
  msg.type(k);
589
655
  msg.int(i);
590
656
  msg.matrix4x4(this._impl.world_tracker_plane_pose_raw(v, i));
591
657
  });
592
658
  }
593
- serializer.sendMessage(23, msg => {
659
+ serializer.sendMessage(27, msg => {
594
660
  msg.type(k);
595
661
  msg.bool(this._impl.world_tracker_world_anchor_valid(v));
596
662
  });
597
- serializer.sendMessage(24, msg => {
663
+ serializer.sendMessage(28, msg => {
598
664
  msg.type(k);
599
665
  msg.matrix4x4(this._impl.world_tracker_world_anchor_pose_raw(v));
600
666
  });
601
- serializer.sendMessage(23, msg => {
667
+ serializer.sendMessage(27, msg => {
602
668
  msg.type(k);
603
669
  msg.bool(this._impl.world_tracker_ground_anchor_valid(v));
604
670
  });
605
- serializer.sendMessage(26, msg => {
671
+ serializer.sendMessage(30, msg => {
606
672
  msg.type(k);
607
673
  msg.matrix4x4(this._impl.world_tracker_ground_anchor_pose_raw(v));
608
674
  });
609
- serializer.sendMessage(29, msg => {
675
+ serializer.sendMessage(33, msg => {
610
676
  msg.type(k);
611
677
  msg.int(this._impl.world_tracker_debug_tracks_data_size(v));
612
678
  });
613
- serializer.sendMessage(28, msg => {
679
+ serializer.sendMessage(32, msg => {
614
680
  msg.type(k);
615
681
  msg.floatArray(this._impl.world_tracker_debug_tracks_data(v));
616
682
  });
617
- serializer.sendMessage(31, msg => {
683
+ serializer.sendMessage(35, msg => {
618
684
  msg.type(k);
619
685
  msg.int(this._impl.world_tracker_debug_projections_data_size(v));
620
686
  });
621
- serializer.sendMessage(30, msg => {
687
+ serializer.sendMessage(34, msg => {
622
688
  msg.type(k);
623
689
  msg.floatArray(this._impl.world_tracker_debug_projections_data(v));
624
690
  });
@@ -10,6 +10,8 @@ export { log_level_t } from "./zappar-native";
10
10
  import { image_target_type_t } from "./zappar-native";
11
11
  export { image_target_type_t } from "./zappar-native";
12
12
  export { world_tracker_quality_t } from "./zappar-native";
13
+ import { camera_profile_t } from "./zappar-native";
14
+ export { camera_profile_t } from "./zappar-native";
13
15
  export declare type zappar_pipeline_t = number & {
14
16
  _: 'zappar_pipeline_t';
15
17
  };
@@ -37,6 +39,9 @@ export declare type zappar_barcode_finder_t = number & {
37
39
  export declare type zappar_instant_world_tracker_t = number & {
38
40
  _: 'zappar_instant_world_tracker_t';
39
41
  };
42
+ export declare type zappar_zapcode_tracker_t = number & {
43
+ _: 'zappar_zapcode_tracker_t';
44
+ };
40
45
  export declare type zappar_world_tracker_t = number & {
41
46
  _: 'zappar_world_tracker_t';
42
47
  };
@@ -99,6 +104,7 @@ export interface zappar {
99
104
  camera_source_destroy(o: zappar_camera_source_t): void;
100
105
  camera_source_start(o: zappar_camera_source_t): void;
101
106
  camera_source_pause(o: zappar_camera_source_t): void;
107
+ camera_source_profile_set(o: zappar_camera_source_t, profile: camera_profile_t): void;
102
108
  sequence_source_create(pipeline: zappar_pipeline_t): zappar_sequence_source_t;
103
109
  sequence_source_destroy(o: zappar_sequence_source_t): void;
104
110
  sequence_source_start(o: zappar_sequence_source_t): void;
@@ -183,6 +189,17 @@ export interface zappar {
183
189
  instant_world_tracker_anchor_pose(o: zappar_instant_world_tracker_t, camera_pose: Float32Array, mirror: boolean): Float32Array;
184
190
  instant_world_tracker_anchor_pose_set_from_camera_offset_raw(o: zappar_instant_world_tracker_t, x: number, y: number, z: number, orientation: instant_world_tracker_transform_orientation_t): void;
185
191
  instant_world_tracker_anchor_pose_set_from_camera_offset(o: zappar_instant_world_tracker_t, x: number, y: number, z: number, orientation: instant_world_tracker_transform_orientation_t): void;
192
+ zapcode_tracker_create(pipeline: zappar_pipeline_t): zappar_zapcode_tracker_t;
193
+ zapcode_tracker_destroy(o: zappar_zapcode_tracker_t): void;
194
+ zapcode_tracker_target_load_from_memory(o: zappar_zapcode_tracker_t, data: ArrayBuffer): void;
195
+ zapcode_tracker_target_loaded_version(o: zappar_zapcode_tracker_t): number;
196
+ zapcode_tracker_enabled(o: zappar_zapcode_tracker_t): boolean;
197
+ zapcode_tracker_enabled_set(o: zappar_zapcode_tracker_t, enabled: boolean): void;
198
+ zapcode_tracker_anchor_count(o: zappar_zapcode_tracker_t): number;
199
+ zapcode_tracker_anchor_id(o: zappar_zapcode_tracker_t, indx: number): string;
200
+ zapcode_tracker_anchor_pose_raw(o: zappar_zapcode_tracker_t, indx: number): Float32Array;
201
+ zapcode_tracker_anchor_pose_camera_relative(o: zappar_zapcode_tracker_t, indx: number, mirror: boolean): Float32Array;
202
+ zapcode_tracker_anchor_pose(o: zappar_zapcode_tracker_t, indx: number, camera_pose: Float32Array, mirror: boolean): Float32Array;
186
203
  world_tracker_create(pipeline: zappar_pipeline_t): zappar_world_tracker_t;
187
204
  world_tracker_destroy(o: zappar_world_tracker_t): void;
188
205
  world_tracker_enabled(o: zappar_world_tracker_t): boolean;
package/lib/gen/zappar.js CHANGED
@@ -5,3 +5,4 @@ export { instant_world_tracker_transform_orientation_t } from "./zappar-native";
5
5
  export { log_level_t } from "./zappar-native";
6
6
  export { image_target_type_t } from "./zappar-native";
7
7
  export { world_tracker_quality_t } from "./zappar-native";
8
+ export { camera_profile_t } from "./zappar-native";
@@ -1,4 +1,4 @@
1
- import { zappar_pipeline_t } from "./gen/zappar";
1
+ import { camera_profile_t, zappar_pipeline_t } from "./gen/zappar";
2
2
  import { Source } from "./source";
3
3
  import { zappar_html_element_source_t } from "./additional";
4
4
  export declare class HTMLElementSource extends Source {
@@ -14,6 +14,7 @@ export declare class HTMLElementSource extends Source {
14
14
  private _cameraToDeviceTransform;
15
15
  private _cameraToDeviceTransformUserFacing;
16
16
  private _cameraModel;
17
+ private _profile;
17
18
  static createVideoElementSource(p: zappar_pipeline_t, element: HTMLVideoElement | HTMLImageElement): zappar_html_element_source_t;
18
19
  static getVideoElementSource(m: zappar_html_element_source_t): HTMLElementSource | undefined;
19
20
  constructor(_video: HTMLVideoElement | HTMLImageElement, _pipeline: zappar_pipeline_t);
@@ -24,4 +25,5 @@ export declare class HTMLElementSource extends Source {
24
25
  getFrame(currentlyProcessing: boolean): void;
25
26
  private _processFrame;
26
27
  uploadGL(): void;
28
+ setProfile(p: camera_profile_t): void;
27
29
  }
@@ -1,3 +1,4 @@
1
+ import { camera_profile_t } from "./gen/zappar";
1
2
  import { Pipeline } from "./pipeline";
2
3
  import { Source } from "./source";
3
4
  import { profile } from "./profile";
@@ -19,6 +20,7 @@ export class HTMLElementSource extends Source {
19
20
  this._cameraToDeviceTransform = mat4.create();
20
21
  this._cameraToDeviceTransformUserFacing = mat4.create();
21
22
  this._cameraModel = new Float32Array([300, 300, 160, 120, 0, 0]);
23
+ this._profile = camera_profile_t.DEFAULT;
22
24
  mat4.fromScaling(this._cameraToDeviceTransformUserFacing, [-1, 1, -1]);
23
25
  let video = this._video;
24
26
  if (this._video instanceof HTMLVideoElement) {
@@ -109,14 +111,15 @@ export class HTMLElementSource extends Source {
109
111
  }
110
112
  if (!this._currentVideoTexture)
111
113
  return undefined;
112
- this._imageProcessor.uploadFrame(this._currentVideoTexture, this._video, rotation, this._isUserFacing);
114
+ this._imageProcessor.uploadFrame(this._currentVideoTexture, this._video, rotation, this._isUserFacing, this._profile);
113
115
  this._isUploadFrame = !this._isUploadFrame;
114
116
  return undefined;
115
117
  }
116
118
  if (currentlyProcessing || !this._currentVideoTexture)
117
119
  return undefined;
118
120
  this._isUploadFrame = !this._isUploadFrame;
119
- let greySize = profile.dataWidth * profile.dataHeight;
121
+ const [dataWidth, dataHeight] = profile.getDataSize(this._profile);
122
+ let greySize = dataWidth * dataHeight;
120
123
  let pixels = pipeline.cameraPixelArrays.pop();
121
124
  while (pixels) {
122
125
  if (pixels.byteLength === greySize)
@@ -128,14 +131,17 @@ export class HTMLElementSource extends Source {
128
131
  }
129
132
  let tex = this._currentVideoTexture;
130
133
  this._currentVideoTexture = undefined;
131
- let focalLength = 300.0 * profile.dataWidth / 320.0;
134
+ let focalLength = 300.0 * dataWidth / 320.0;
132
135
  this._cameraModel[0] = focalLength;
133
136
  this._cameraModel[1] = focalLength;
134
- this._cameraModel[2] = profile.dataWidth * 0.5;
135
- this._cameraModel[3] = profile.dataHeight * 0.5;
136
- return Object.assign(Object.assign({}, this._imageProcessor.readFrame(tex, pixels)), { cameraModel: this._cameraModel, cameraSource: this, cameraToDevice: (this._isUserFacing ? this._cameraToDeviceTransformUserFacing : this._cameraToDeviceTransform) });
137
+ this._cameraModel[2] = dataWidth * 0.5;
138
+ this._cameraModel[3] = dataHeight * 0.5;
139
+ return Object.assign(Object.assign({}, this._imageProcessor.readFrame(tex, pixels, this._profile)), { cameraModel: this._cameraModel, cameraSource: this, cameraToDevice: (this._isUserFacing ? this._cameraToDeviceTransformUserFacing : this._cameraToDeviceTransform) });
137
140
  }
138
141
  uploadGL() {
139
142
  // No-op as already uploaded
140
143
  }
144
+ setProfile(p) {
145
+ this._profile = p;
146
+ }
141
147
  }
@@ -1,3 +1,4 @@
1
+ import { camera_profile_t } from "./gen/zappar-native";
1
2
  export interface ProcessedFrame {
2
3
  data?: ArrayBuffer;
3
4
  texture: WebGLTexture | undefined;
@@ -28,8 +29,8 @@ export declare class ImageProcessGL {
28
29
  constructor(_gl: WebGL2RenderingContext | WebGLRenderingContext);
29
30
  resetGLContext(): void;
30
31
  destroy(): void;
31
- uploadFrame(texture: WebGLTexture, img: HTMLVideoElement | HTMLImageElement | ImageBitmap, rotation: number, fc: boolean): void;
32
- readFrame(texture: WebGLTexture, pixels: ArrayBuffer): ProcessedFrame;
32
+ uploadFrame(texture: WebGLTexture, img: HTMLVideoElement | HTMLImageElement | ImageBitmap, rotation: number, fc: boolean, cp: camera_profile_t): void;
33
+ readFrame(texture: WebGLTexture, pixels: ArrayBuffer, cp: camera_profile_t): ProcessedFrame;
33
34
  private _updateTransforms;
34
35
  private _getCameraUvTransform;
35
36
  private _getFramebuffer;
@@ -33,7 +33,7 @@ export class ImageProcessGL {
33
33
  destroy() {
34
34
  this.resetGLContext();
35
35
  }
36
- uploadFrame(texture, img, rotation, fc) {
36
+ uploadFrame(texture, img, rotation, fc, cp) {
37
37
  let gl = this._gl;
38
38
  const glStateManager = GLStateManager.get(gl);
39
39
  glStateManager.push();
@@ -75,7 +75,8 @@ export class ImageProcessGL {
75
75
  if (videoHeight > videoWidth)
76
76
  videoHeight = [videoWidth, videoWidth = videoHeight][0];
77
77
  this._updateTransforms(rotation, fc);
78
- let framebuffer = this._getFramebuffer(gl, profile.dataWidth / 4, profile.dataHeight);
78
+ const [dataWidth, dataHeight] = profile.getDataSize(cp);
79
+ let framebuffer = this._getFramebuffer(gl, dataWidth / 4, dataHeight);
79
80
  let vbo = this._getVertexBuffer(gl);
80
81
  let ibo = this._getIndexBuffer(gl);
81
82
  let shader = this._getGreyscaleShader(gl);
@@ -123,7 +124,7 @@ export class ImageProcessGL {
123
124
  // Tell WebGL to use our program when drawing
124
125
  gl.useProgram(shader.program);
125
126
  // Specify greyscale width for the correct offsets, and the uv transform
126
- gl.uniform1f(shader.uTexWidthLoc, profile.dataWidth);
127
+ gl.uniform1f(shader.uTexWidthLoc, dataWidth);
127
128
  gl.uniformMatrix4fv(shader.uUvTransformLoc, false, this._cameraUvTransform);
128
129
  gl.activeTexture(gl.TEXTURE0);
129
130
  // Bind the texture to texture unit 0
@@ -167,11 +168,12 @@ export class ImageProcessGL {
167
168
  if (reenableStencilTest)
168
169
  gl.enable(gl.STENCIL_TEST);
169
170
  }
170
- readFrame(texture, pixels) {
171
+ readFrame(texture, pixels, cp) {
171
172
  let gl = this._gl;
172
173
  let pixelsView = new Uint8Array(pixels);
173
174
  const previousBoundFramebuffer = gl.getParameter(gl.FRAMEBUFFER_BINDING);
174
- let framebuffer = this._getFramebuffer(gl, profile.dataWidth / 4, profile.dataHeight);
175
+ const [dataWidth, dataHeight] = profile.getDataSize(cp);
176
+ let framebuffer = this._getFramebuffer(gl, dataWidth / 4, dataHeight);
175
177
  gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
176
178
  gl.readPixels(0, 0, this._framebufferWidth, this._framebufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixelsView);
177
179
  gl.bindFramebuffer(gl.FRAMEBUFFER, previousBoundFramebuffer);
@@ -179,8 +181,8 @@ export class ImageProcessGL {
179
181
  uvTransform: this._cameraUvTransform,
180
182
  data: pixels,
181
183
  texture,
182
- dataWidth: profile.dataWidth,
183
- dataHeight: profile.dataHeight,
184
+ dataWidth,
185
+ dataHeight,
184
186
  userFacing: this._computedFrontCameraRotation
185
187
  };
186
188
  }
@@ -1,4 +1,4 @@
1
- import { zappar_camera_source_t, zappar_pipeline_t } from "./gen/zappar";
1
+ import { camera_profile_t, zappar_camera_source_t, zappar_pipeline_t } from "./gen/zappar";
2
2
  import { CameraFrameInfo, Source } from "./source";
3
3
  export declare class ImageBitmapCameraSource extends Source {
4
4
  private _impl;
@@ -18,8 +18,10 @@ export declare class ImageBitmapCameraSource extends Source {
18
18
  private _cameraToDeviceTransform;
19
19
  private _cameraToDeviceTransformUserFacing;
20
20
  private _cameraModel;
21
+ private _profile;
21
22
  constructor(_impl: zappar_camera_source_t, _pipeline: zappar_pipeline_t, _deviceId: string);
22
23
  destroy(): void;
24
+ setProfile(p: camera_profile_t): void;
23
25
  private _stop;
24
26
  pause(): void;
25
27
  start(): void;
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { camera_profile_t } from "./gen/zappar";
10
11
  import { profile } from "./profile";
11
12
  import { Pipeline } from "./pipeline";
12
13
  import { Source } from "./source";
@@ -32,6 +33,7 @@ export class ImageBitmapCameraSource extends Source {
32
33
  this._cameraToDeviceTransform = mat4.create();
33
34
  this._cameraToDeviceTransformUserFacing = mat4.create();
34
35
  this._cameraModel = new Float32Array([300, 300, 160, 120, 0, 0]);
36
+ this._profile = camera_profile_t.DEFAULT;
35
37
  this._hasStartedOrientation = false;
36
38
  this._lastTimestamp = -1;
37
39
  this._deviceMotionListener = (ev) => {
@@ -85,6 +87,9 @@ export class ImageBitmapCameraSource extends Source {
85
87
  this.pause();
86
88
  deleteCameraSource(this._impl);
87
89
  }
90
+ setProfile(p) {
91
+ this._profile = p;
92
+ }
88
93
  _stop() {
89
94
  if (!this._currentStream)
90
95
  return;
@@ -185,11 +190,12 @@ export class ImageBitmapCameraSource extends Source {
185
190
  let pipeline = Pipeline.get(this._pipeline);
186
191
  if (!pipeline)
187
192
  return;
188
- let focalLength = 300.0 * profile.dataWidth / 320.0;
193
+ const [dataWidth, dataHeight] = profile.getDataSize(this._profile);
194
+ let focalLength = 300.0 * dataWidth / 320.0;
189
195
  this._cameraModel[0] = focalLength;
190
196
  this._cameraModel[1] = focalLength;
191
- this._cameraModel[2] = profile.dataWidth * 0.5;
192
- this._cameraModel[3] = profile.dataHeight * 0.5;
197
+ this._cameraModel[2] = dataWidth * 0.5;
198
+ this._cameraModel[3] = dataHeight * 0.5;
193
199
  let token = pipeline.registerToken({
194
200
  dataWidth: this._canvas.width,
195
201
  dataHeight: this._canvas.height,
@@ -199,7 +205,7 @@ export class ImageBitmapCameraSource extends Source {
199
205
  cameraModel: this._cameraModel.slice(),
200
206
  cameraToDevice: this._isUserFacing ? this._cameraToDeviceTransformUserFacing : this._cameraToDeviceTransform
201
207
  });
202
- (_b = (_a = Pipeline.get(this._pipeline)) === null || _a === void 0 ? void 0 : _a.sendImageBitmapToWorker) === null || _b === void 0 ? void 0 : _b.call(_a, imageBitmap, rotation, this._isUserFacing, token, this._cameraModel, this._isUserFacing ? this._cameraToDeviceTransformUserFacing : this._cameraToDeviceTransform);
208
+ (_b = (_a = Pipeline.get(this._pipeline)) === null || _a === void 0 ? void 0 : _a.sendImageBitmapToWorker) === null || _b === void 0 ? void 0 : _b.call(_a, imageBitmap, rotation, this._isUserFacing, token, this._cameraModel, this._isUserFacing ? this._cameraToDeviceTransformUserFacing : this._cameraToDeviceTransform, this._profile);
203
209
  return;
204
210
  }
205
211
  _getUserMedia() {
package/lib/index.d.ts CHANGED
@@ -4,4 +4,4 @@ import { Options } from "./options";
4
4
  export declare type Zappar = zappar & Additional;
5
5
  export declare function initialize(opts?: Options): Zappar;
6
6
  export { CameraFrameData } from './camera-frame-data';
7
- export { zappar_image_tracker_t, zappar_instant_world_tracker_t, zappar_world_tracker_t, zappar_barcode_finder_t, zappar_face_tracker_t, zappar_face_landmark_t, barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t, zappar_face_mesh_t, zappar_pipeline_t, zappar_camera_source_t, zappar_sequence_source_t, image_target_type_t, world_tracker_quality_t } from "./gen/zappar";
7
+ export { zappar_image_tracker_t, zappar_instant_world_tracker_t, zappar_world_tracker_t, zappar_barcode_finder_t, zappar_face_tracker_t, zappar_face_landmark_t, zappar_zapcode_tracker_t, barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t, zappar_face_mesh_t, zappar_pipeline_t, zappar_camera_source_t, zappar_sequence_source_t, image_target_type_t, world_tracker_quality_t, camera_profile_t } from "./gen/zappar";
package/lib/index.js CHANGED
@@ -4,4 +4,4 @@ export function initialize(opts) {
4
4
  console.log(`Zappar CV v${VERSION}`);
5
5
  return nativeInitialize(opts);
6
6
  }
7
- export { barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t, image_target_type_t, world_tracker_quality_t } from "./gen/zappar";
7
+ export { barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t, image_target_type_t, world_tracker_quality_t, camera_profile_t } from "./gen/zappar";
@@ -1,4 +1,4 @@
1
- import { zappar_camera_source_t, zappar_pipeline_t } from "./gen/zappar";
1
+ import { camera_profile_t, zappar_camera_source_t, zappar_pipeline_t } from "./gen/zappar";
2
2
  import { CameraFrameInfo, Source } from "./source";
3
3
  export declare class MSTPCameraSource extends Source {
4
4
  private _impl;
@@ -24,6 +24,7 @@ export declare class MSTPCameraSource extends Source {
24
24
  private _getUserMedia;
25
25
  streamEnded(): void;
26
26
  private _syncCamera;
27
+ setProfile(profile: camera_profile_t): void;
27
28
  private _hasStartedOrientation;
28
29
  private _lastTimestamp;
29
30
  private _deviceMotionListener;
@@ -249,6 +249,11 @@ export class MSTPCameraSource extends Source {
249
249
  }
250
250
  });
251
251
  }
252
+ setProfile(profile) {
253
+ let p = Pipeline.get(this._pipeline);
254
+ if (p)
255
+ p.sendCameraProfileToWorker(this._impl, profile);
256
+ }
252
257
  _startDeviceOrientation() {
253
258
  if (this._hasStartedOrientation)
254
259
  return;
package/lib/native.js CHANGED
@@ -147,7 +147,7 @@ export function initialize(opts) {
147
147
  }
148
148
  }
149
149
  });
150
- client = Object.assign(Object.assign({}, c.impl), { loaded: () => loaded, camera_default_device_id: userFacing => userFacing ? CameraSource.USER_DEFAULT_DEVICE_ID : CameraSource.DEFAULT_DEVICE_ID, camera_source_create: (p, deviceId) => createCameraSource(p, deviceId), camera_source_destroy: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.destroy(); }, camera_source_pause: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.pause(); }, camera_source_start: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.start(); }, camera_count: () => 2, camera_id: indx => indx === 0 ? CameraSource.DEFAULT_DEVICE_ID : CameraSource.USER_DEFAULT_DEVICE_ID, camera_name: indx => indx === 0 ? "Rear-facing Camera" : "User-facing Camera", camera_user_facing: indx => indx !== 0, pose_from_raw: (raw_pose, mirror) => {
150
+ client = Object.assign(Object.assign({}, c.impl), { loaded: () => loaded, camera_default_device_id: userFacing => userFacing ? CameraSource.USER_DEFAULT_DEVICE_ID : CameraSource.DEFAULT_DEVICE_ID, camera_source_create: (p, deviceId) => createCameraSource(p, deviceId), camera_source_destroy: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.destroy(); }, camera_source_pause: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.pause(); }, camera_source_start: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.start(); }, camera_source_profile_set: (cam, p) => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.setProfile(p); }, camera_count: () => 2, camera_id: indx => indx === 0 ? CameraSource.DEFAULT_DEVICE_ID : CameraSource.USER_DEFAULT_DEVICE_ID, camera_name: indx => indx === 0 ? "Rear-facing Camera" : "User-facing Camera", camera_user_facing: indx => indx !== 0, pose_from_raw: (raw_pose, mirror) => {
151
151
  let res = applyScreenCounterRotation(undefined, raw_pose);
152
152
  if (mirror) {
153
153
  let scale = mat4.create();
@@ -377,6 +377,25 @@ export function initialize(opts) {
377
377
  return 0;
378
378
  }
379
379
  return obj.getPreviewMesh(indx).normals.length;
380
+ }, zapcode_tracker_anchor_pose_camera_relative: (o, indx, mirror) => {
381
+ let res = applyScreenCounterRotation(undefined, c.impl.zapcode_tracker_anchor_pose_raw(o, indx));
382
+ if (mirror) {
383
+ let scale = mat4.create();
384
+ mat4.fromScaling(scale, [-1, 1, 1]);
385
+ mat4.multiply(res, scale, res);
386
+ mat4.multiply(res, res, scale);
387
+ }
388
+ return res;
389
+ }, zapcode_tracker_anchor_pose: (o, indx, cameraPose, mirror) => {
390
+ let res = applyScreenCounterRotation(undefined, c.impl.zapcode_tracker_anchor_pose_raw(o, indx));
391
+ if (mirror) {
392
+ let scale = mat4.create();
393
+ mat4.fromScaling(scale, [-1, 1, 1]);
394
+ mat4.multiply(res, scale, res);
395
+ mat4.multiply(res, res, scale);
396
+ }
397
+ mat4.multiply(res, cameraPose, res);
398
+ return res;
380
399
  }, face_tracker_anchor_pose_camera_relative: (o, indx, mirror) => {
381
400
  let res = applyScreenCounterRotation(undefined, c.impl.face_tracker_anchor_pose_raw(o, indx));
382
401
  if (mirror) {
package/lib/pipeline.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /// <reference types="dom-webcodecs" />
2
2
  import { zappar_pipeline_t, zappar_camera_source_t } from "./gen/zappar";
3
+ import { camera_profile_t } from "./gen/zappar-native";
3
4
  import { zappar_client } from "./gen/zappar-client";
4
5
  import { MsgManager } from "./messages";
5
6
  import { Source, CameraFrameInfo } from "./source";
@@ -74,8 +75,9 @@ export declare class Pipeline {
74
75
  motionAttitudeSubmit(timestamp: number, x: number, y: number, z: number): void;
75
76
  motionAttitudeMatrix(m: Float32Array): void;
76
77
  sendCameraStreamToWorker(source: zappar_camera_source_t, stream: ReadableStream<VideoFrame>, userFacing: boolean): void;
78
+ sendCameraProfileToWorker(source: zappar_camera_source_t, profile: camera_profile_t): void;
77
79
  sendCameraToScreenRotationToWorker(rot: number): void;
78
- sendImageBitmapToWorker(img: ImageBitmap, rot: number, userFacing: boolean, tokenId: number, cameraModel: Float32Array, cameraToDevice: Float32Array): void;
80
+ sendImageBitmapToWorker(img: ImageBitmap, rot: number, userFacing: boolean, tokenId: number, cameraModel: Float32Array, cameraToDevice: Float32Array, cp: camera_profile_t): void;
79
81
  sendDataToWorker(data: ArrayBuffer, token: number, width: number, height: number, userFacing: boolean, cameraToDevice: Float32Array, cameraModel: Float32Array): void;
80
82
  }
81
83
  export declare function applyScreenCounterRotation(info: CameraFrameInfo | undefined, inp: Float32Array): Float32Array;
package/lib/pipeline.js CHANGED
@@ -448,6 +448,15 @@ export class Pipeline {
448
448
  };
449
449
  this._mgr.postOutgoingMessage(msg, [msg.s]);
450
450
  }
451
+ sendCameraProfileToWorker(source, profile) {
452
+ let msg = {
453
+ t: "cameraProfileC2S",
454
+ p: this._impl,
455
+ source,
456
+ profile
457
+ };
458
+ this._mgr.postOutgoingMessage(msg, []);
459
+ }
451
460
  sendCameraToScreenRotationToWorker(rot) {
452
461
  let msg = {
453
462
  p: this._impl,
@@ -456,7 +465,7 @@ export class Pipeline {
456
465
  };
457
466
  this._mgr.postOutgoingMessage(msg, []);
458
467
  }
459
- sendImageBitmapToWorker(img, rot, userFacing, tokenId, cameraModel, cameraToDevice) {
468
+ sendImageBitmapToWorker(img, rot, userFacing, tokenId, cameraModel, cameraToDevice, cp) {
460
469
  let msg = {
461
470
  p: this._impl,
462
471
  t: "imageBitmapC2S",
@@ -465,7 +474,8 @@ export class Pipeline {
465
474
  tokenId,
466
475
  userFacing,
467
476
  cameraModel,
468
- cameraToDevice
477
+ cameraToDevice,
478
+ cp
469
479
  };
470
480
  this._mgr.postOutgoingMessage(msg, [img]);
471
481
  }
package/lib/profile.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { camera_profile_t } from "./gen/zappar-native";
1
2
  export declare enum EmbeddedVideoImplementation {
2
3
  OBJECT_URL = 0,
3
4
  SRC_OBJECT = 1
@@ -10,8 +11,7 @@ export declare let profile: {
10
11
  requestHighFrameRate: boolean;
11
12
  videoWidth: number;
12
13
  videoHeight: number;
13
- dataWidth: number;
14
- dataHeight: number;
14
+ getDataSize: (p: camera_profile_t) => number[];
15
15
  videoElementInDOM: boolean;
16
16
  preferMediaStreamTrackProcessorCamera: boolean;
17
17
  preferImageBitmapCamera: boolean;
package/lib/profile.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as UAParser from "ua-parser-js";
2
+ import { camera_profile_t } from "./gen/zappar-native";
2
3
  export var EmbeddedVideoImplementation;
3
4
  (function (EmbeddedVideoImplementation) {
4
5
  EmbeddedVideoImplementation[EmbeddedVideoImplementation["OBJECT_URL"] = 0] = "OBJECT_URL";
@@ -12,8 +13,7 @@ export let profile = {
12
13
  requestHighFrameRate: false,
13
14
  videoWidth: 640,
14
15
  videoHeight: 480,
15
- dataWidth: 320,
16
- dataHeight: 240,
16
+ getDataSize: (p) => p === camera_profile_t.HIGH ? [640, 480] : [320, 240],
17
17
  videoElementInDOM: false,
18
18
  preferMediaStreamTrackProcessorCamera: true,
19
19
  preferImageBitmapCamera: false,
@@ -80,7 +80,7 @@ function iDevice(version) {
80
80
  // Avoid bug where iOS letterboxes 16:9 into 4:3 for high fps
81
81
  // Doesn't seem needed with newer versions of iOS, tested on 14.8.1 and 15.2
82
82
  profile.videoHeight = 360;
83
- profile.dataHeight = 180;
83
+ profile.getDataSize = (p) => p === camera_profile_t.HIGH ? [640, 360] : [320, 180];
84
84
  }
85
85
  }
86
86
  if (majorVersion === 16 && minorVersion >= 4) {
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "3.0.1-alpha.5";
1
+ export declare const VERSION = "3.0.1-alpha.8";
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "3.0.1-alpha.5";
1
+ export const VERSION = "3.0.1-alpha.8";
@@ -34,12 +34,13 @@ export function handleImageBitmap(m, r, server, mgr) {
34
34
  }
35
35
  if (!texture)
36
36
  return;
37
- if (!pixels || pixels.byteLength < profile.dataWidth * profile.dataHeight) {
37
+ const [dataWidth, dataHeight] = profile.getDataSize(m.cp);
38
+ if (!pixels || pixels.byteLength < dataWidth * dataHeight) {
38
39
  // console.log("Generating pixel buffer", profile.dataWidth * profile.dataHeight);
39
- pixels = new ArrayBuffer(profile.dataWidth * profile.dataHeight);
40
+ pixels = new ArrayBuffer(dataWidth * dataHeight);
40
41
  }
41
- imageProcessor.uploadFrame(texture, m.i, m.r, m.userFacing);
42
- let info = imageProcessor.readFrame(texture, pixels);
42
+ imageProcessor.uploadFrame(texture, m.i, m.r, m.userFacing, m.cp);
43
+ let info = imageProcessor.readFrame(texture, pixels, m.cp);
43
44
  let msg = {
44
45
  t: "imageBitmapS2C",
45
46
  dataWidth: info.dataWidth,