@zappar/zappar-cv 4.0.0-beta.3 → 4.1.0-beta.2
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.
- package/README.md +2 -2
- package/lib/file-locator.d.ts +13 -0
- package/lib/file-locator.js +17 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/landmarkdatagenerate.js +3 -2
- package/lib/native.js +5 -4
- package/lib/src/file-locator.d.ts +13 -0
- package/lib/src/index.d.ts +1 -0
- package/lib/src/version.d.ts +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/worker-client.js +30 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,8 +18,8 @@ npm i @zappar/zappar-cv
|
|
|
18
18
|
|
|
19
19
|
You can use our CDN from within your HTML:
|
|
20
20
|
```
|
|
21
|
-
<script src="https://libs.zappar.com/zappar-cv/4.
|
|
21
|
+
<script src="https://libs.zappar.com/zappar-cv/4.1.0-beta.2/zappar-cv.js"></script>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
Or you can download and host our standalone JavaScript bundle:
|
|
25
|
-
[https://libs.zappar.com/zappar-cv/4.
|
|
25
|
+
[https://libs.zappar.com/zappar-cv/4.1.0-beta.2/zappar-cv.zip](https://libs.zappar.com/zappar-cv/4.1.0-beta.2/zappar-cv.zip)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Returns the URL to load an asset from, or a falsy value to use the default. */
|
|
2
|
+
export declare type FileLocator = (filename: string, defaultUrl: string) => string | void | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* Overrides where the library loads its runtime assets from. Call before
|
|
5
|
+
* `initialize()`; pass nothing to clear.
|
|
6
|
+
*
|
|
7
|
+
* The locator runs once per asset, where `filename` is one of:
|
|
8
|
+
* `zappar-cv.wasm`, `face_tracking_model.zbin`, `face_mesh_face_model.zbin`,
|
|
9
|
+
* `face_mesh_full_head_simplified_model.zbin`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function setFileLocator(locator?: FileLocator): void;
|
|
12
|
+
/** Resolves an asset URL, routing it through the locator if one is set. */
|
|
13
|
+
export declare function resolveFileUrl(filename: string, defaultUrl: URL | string): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
let fileLocator;
|
|
2
|
+
/**
|
|
3
|
+
* Overrides where the library loads its runtime assets from. Call before
|
|
4
|
+
* `initialize()`; pass nothing to clear.
|
|
5
|
+
*
|
|
6
|
+
* The locator runs once per asset, where `filename` is one of:
|
|
7
|
+
* `zappar-cv.wasm`, `face_tracking_model.zbin`, `face_mesh_face_model.zbin`,
|
|
8
|
+
* `face_mesh_full_head_simplified_model.zbin`.
|
|
9
|
+
*/
|
|
10
|
+
export function setFileLocator(locator) {
|
|
11
|
+
fileLocator = locator;
|
|
12
|
+
}
|
|
13
|
+
/** Resolves an asset URL, routing it through the locator if one is set. */
|
|
14
|
+
export function resolveFileUrl(filename, defaultUrl) {
|
|
15
|
+
const url = defaultUrl.toString();
|
|
16
|
+
return (fileLocator === null || fileLocator === void 0 ? void 0 : fileLocator(filename, url)) || url;
|
|
17
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ import { Options } from "./options.js";
|
|
|
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.js';
|
|
7
|
+
export { setFileLocator, FileLocator } from "./file-locator.js";
|
|
7
8
|
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, zappar_custom_anchor_t, zappar_d3_tracker_t, barcode_format_t, world_scale_mode_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, transform_orientation_t, plane_orientation_t, anchor_status_t, } from "./gen/zappar.js";
|
package/lib/index.js
CHANGED
|
@@ -4,4 +4,5 @@ export function initialize(opts) {
|
|
|
4
4
|
console.log(`Zappar CV v${VERSION}`);
|
|
5
5
|
return nativeInitialize(opts);
|
|
6
6
|
}
|
|
7
|
+
export { setFileLocator } from "./file-locator.js";
|
|
7
8
|
export { barcode_format_t, world_scale_mode_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, transform_orientation_t, plane_orientation_t, anchor_status_t, } from "./gen/zappar.js";
|
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { FaceMesh } from "./facemesh.js";
|
|
11
11
|
import { face_landmark_name_t } from "./gen/zappar.js";
|
|
12
|
+
import { resolveFileUrl } from "./file-locator.js";
|
|
12
13
|
let vertexIndexByName = new Map([
|
|
13
14
|
[face_landmark_name_t.EAR_LEFT, 888],
|
|
14
15
|
[face_landmark_name_t.EAR_RIGHT, 467],
|
|
@@ -27,7 +28,7 @@ let vertexIndexByName = new Map([
|
|
|
27
28
|
export function generateDataJSON() {
|
|
28
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
30
|
let mesh = new FaceMesh();
|
|
30
|
-
let url = new URL("./face_mesh_face_model.zbin", import.meta.url);
|
|
31
|
+
let url = resolveFileUrl("face_mesh_face_model.zbin", new URL("./face_mesh_face_model.zbin", import.meta.url));
|
|
31
32
|
let req = yield fetch(url.toString());
|
|
32
33
|
mesh.loadFromMemory(yield req.arrayBuffer(), false, false, false, false);
|
|
33
34
|
let names = new Set([face_landmark_name_t.EYE_LEFT, face_landmark_name_t.EYE_RIGHT, face_landmark_name_t.EAR_LEFT, face_landmark_name_t.EAR_RIGHT, face_landmark_name_t.NOSE_BRIDGE, face_landmark_name_t.NOSE_TIP, face_landmark_name_t.NOSE_BASE, face_landmark_name_t.LIP_TOP, face_landmark_name_t.LIP_BOTTOM, face_landmark_name_t.MOUTH_CENTER, face_landmark_name_t.CHIN, face_landmark_name_t.EYEBROW_LEFT, face_landmark_name_t.EYEBROW_RIGHT]);
|
|
@@ -58,7 +59,7 @@ function arrayAsCPPLiteral(a) {
|
|
|
58
59
|
export function generateDataCPP() {
|
|
59
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
61
|
let mesh = new FaceMesh();
|
|
61
|
-
let url = new URL("./face_mesh_face_model.zbin", import.meta.url);
|
|
62
|
+
let url = resolveFileUrl("face_mesh_face_model.zbin", new URL("./face_mesh_face_model.zbin", import.meta.url));
|
|
62
63
|
let req = yield fetch(url.toString());
|
|
63
64
|
mesh.loadFromMemory(yield req.arrayBuffer(), false, false, false, false);
|
|
64
65
|
let names = [face_landmark_name_t.EYE_LEFT, face_landmark_name_t.EYE_RIGHT, face_landmark_name_t.EAR_LEFT, face_landmark_name_t.EAR_RIGHT, face_landmark_name_t.NOSE_BRIDGE, face_landmark_name_t.NOSE_TIP, face_landmark_name_t.NOSE_BASE, face_landmark_name_t.LIP_TOP, face_landmark_name_t.LIP_BOTTOM, face_landmark_name_t.MOUTH_CENTER, face_landmark_name_t.CHIN, face_landmark_name_t.EYEBROW_LEFT, face_landmark_name_t.EYEBROW_RIGHT];
|
package/lib/native.js
CHANGED
|
@@ -35,6 +35,7 @@ import { BridgedCameraSource } from "./bridged-camera-source.js";
|
|
|
35
35
|
import { WebXRCameraSource } from "./webxr-camera-source.js";
|
|
36
36
|
import { WebXRWorldTracker } from "./webxr-world-tracker.js";
|
|
37
37
|
import { profile } from "./profile.js";
|
|
38
|
+
import { resolveFileUrl } from "./file-locator.js";
|
|
38
39
|
let client;
|
|
39
40
|
const pipelineByWorldTracker = new Map();
|
|
40
41
|
const d3TrackerSizeById = new Map();
|
|
@@ -861,7 +862,7 @@ export function initialize(opts) {
|
|
|
861
862
|
zcwarn("attempting to call face_mesh_load_default on a destroyed zappar_face_mesh_t");
|
|
862
863
|
return;
|
|
863
864
|
}
|
|
864
|
-
let url = new URL("./face_mesh_face_model.zbin", import.meta.url);
|
|
865
|
+
let url = resolveFileUrl("face_mesh_face_model.zbin", new URL("./face_mesh_face_model.zbin", import.meta.url));
|
|
865
866
|
let req = yield fetch(url.toString());
|
|
866
867
|
obj.loadFromMemory(yield req.arrayBuffer(), false, false, false, false);
|
|
867
868
|
}), face_mesh_load_default_face: (m, fillMouth, fillEyeL, fillEyeR) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -870,7 +871,7 @@ export function initialize(opts) {
|
|
|
870
871
|
zcwarn("attempting to call face_mesh_load_default_face on a destroyed zappar_face_mesh_t");
|
|
871
872
|
return;
|
|
872
873
|
}
|
|
873
|
-
let url = new URL("./face_mesh_face_model.zbin", import.meta.url);
|
|
874
|
+
let url = resolveFileUrl("face_mesh_face_model.zbin", new URL("./face_mesh_face_model.zbin", import.meta.url));
|
|
874
875
|
let req = yield fetch(url.toString());
|
|
875
876
|
obj.loadFromMemory(yield req.arrayBuffer(), fillMouth, fillEyeL, fillEyeR, false);
|
|
876
877
|
}), face_mesh_load_default_full_head_simplified: (m, fillMouth, fillEyeL, fillEyeR, fillNeck) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -879,7 +880,7 @@ export function initialize(opts) {
|
|
|
879
880
|
zcwarn("attempting to call face_mesh_load_default_full_head_simplified on a destroyed zappar_face_mesh_t");
|
|
880
881
|
return;
|
|
881
882
|
}
|
|
882
|
-
let url = new URL("./face_mesh_full_head_simplified_model.zbin", import.meta.url);
|
|
883
|
+
let url = resolveFileUrl("face_mesh_full_head_simplified_model.zbin", new URL("./face_mesh_full_head_simplified_model.zbin", import.meta.url));
|
|
883
884
|
let req = yield fetch(url.toString());
|
|
884
885
|
obj.loadFromMemory(yield req.arrayBuffer(), fillMouth, fillEyeL, fillEyeR, fillNeck);
|
|
885
886
|
}), face_mesh_loaded_version: (m) => {
|
|
@@ -1014,7 +1015,7 @@ export function initialize(opts) {
|
|
|
1014
1015
|
}
|
|
1015
1016
|
function loadDefaultFaceModel(o) {
|
|
1016
1017
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1017
|
-
let url = new URL("./face_tracking_model.zbin", import.meta.url);
|
|
1018
|
+
let url = resolveFileUrl("face_tracking_model.zbin", new URL("./face_tracking_model.zbin", import.meta.url));
|
|
1018
1019
|
let data = yield fetch(url.toString());
|
|
1019
1020
|
let ab = yield data.arrayBuffer();
|
|
1020
1021
|
client === null || client === void 0 ? void 0 : client.face_tracker_model_load_from_memory(o, ab);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Returns the URL to load an asset from, or a falsy value to use the default. */
|
|
2
|
+
export declare type FileLocator = (filename: string, defaultUrl: string) => string | void | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* Overrides where the library loads its runtime assets from. Call before
|
|
5
|
+
* `initialize()`; pass nothing to clear.
|
|
6
|
+
*
|
|
7
|
+
* The locator runs once per asset, where `filename` is one of:
|
|
8
|
+
* `zappar-cv.wasm`, `face_tracking_model.zbin`, `face_mesh_face_model.zbin`,
|
|
9
|
+
* `face_mesh_full_head_simplified_model.zbin`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function setFileLocator(locator?: FileLocator): void;
|
|
12
|
+
/** Resolves an asset URL, routing it through the locator if one is set. */
|
|
13
|
+
export declare function resolveFileUrl(filename: string, defaultUrl: URL | string): string;
|
package/lib/src/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ import { Options } from "./options.js";
|
|
|
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.js';
|
|
7
|
+
export { setFileLocator, FileLocator } from "./file-locator.js";
|
|
7
8
|
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, zappar_custom_anchor_t, zappar_d3_tracker_t, barcode_format_t, world_scale_mode_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, transform_orientation_t, plane_orientation_t, anchor_status_t, } from "./gen/zappar.js";
|
package/lib/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "4.
|
|
1
|
+
export declare const VERSION = "4.1.0-beta.2";
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "4.
|
|
1
|
+
export declare const VERSION = "4.1.0-beta.2";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "4.
|
|
1
|
+
export const VERSION = "4.1.0-beta.2";
|
package/lib/worker-client.js
CHANGED
|
@@ -9,22 +9,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
var _a;
|
|
11
11
|
import { MsgManager } from "./messages.js";
|
|
12
|
+
import { resolveFileUrl } from "./file-locator.js";
|
|
12
13
|
export let messageManager = new MsgManager();
|
|
13
14
|
const params = new URLSearchParams(window.location.search);
|
|
14
15
|
const shouldRecordData = parseInt((_a = params.get('_zrecorddata')) !== null && _a !== void 0 ? _a : '0');
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
function wasmUrl() {
|
|
17
|
+
return resolveFileUrl("zappar-cv.wasm", new URL("./zappar-cv.wasm", import.meta.url));
|
|
18
|
+
}
|
|
19
|
+
function compileWasm(url) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
if (typeof WebAssembly.compileStreaming === "function") {
|
|
22
|
+
try {
|
|
23
|
+
return yield WebAssembly.compileStreaming(fetch(url));
|
|
24
|
+
}
|
|
25
|
+
catch (_a) {
|
|
26
|
+
// Fall back to a buffered compile if the server sends a non-wasm MIME type.
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const response = yield fetch(url);
|
|
30
|
+
return WebAssembly.compile(yield response.arrayBuffer());
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
let wasmModulePromise;
|
|
34
|
+
function getWasmModule() {
|
|
35
|
+
if (!wasmModulePromise)
|
|
36
|
+
wasmModulePromise = compileWasm(wasmUrl());
|
|
37
|
+
return wasmModulePromise;
|
|
38
|
+
}
|
|
20
39
|
export function launchWorker(worker) {
|
|
21
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
41
|
if (!worker)
|
|
23
42
|
worker = new Worker(new URL("./worker", import.meta.url), { type: 'module' });
|
|
24
43
|
worker.postMessage({
|
|
25
44
|
t: "wasm",
|
|
26
|
-
url:
|
|
27
|
-
module: yield
|
|
45
|
+
url: wasmUrl(),
|
|
46
|
+
module: yield getWasmModule(),
|
|
28
47
|
shouldRecordData
|
|
29
48
|
});
|
|
30
49
|
yield waitForLoad(worker);
|
|
@@ -48,8 +67,8 @@ export function launchCeresWorkers(port0, port1, worker0, worker1) {
|
|
|
48
67
|
worker0 = new Worker(new URL("./ceres-worker", import.meta.url), { type: 'module' });
|
|
49
68
|
worker0.postMessage({
|
|
50
69
|
t: "wasm",
|
|
51
|
-
url:
|
|
52
|
-
module: yield
|
|
70
|
+
url: wasmUrl(),
|
|
71
|
+
module: yield getWasmModule(),
|
|
53
72
|
port: port0,
|
|
54
73
|
instance: 0,
|
|
55
74
|
}, [port0]);
|
|
@@ -59,8 +78,8 @@ export function launchCeresWorkers(port0, port1, worker0, worker1) {
|
|
|
59
78
|
worker1 = new Worker(new URL("./ceres-worker", import.meta.url), { type: 'module' });
|
|
60
79
|
worker1.postMessage({
|
|
61
80
|
t: "wasm",
|
|
62
|
-
url:
|
|
63
|
-
module: yield
|
|
81
|
+
url: wasmUrl(),
|
|
82
|
+
module: yield getWasmModule(),
|
|
64
83
|
port: port1,
|
|
65
84
|
instance: 1,
|
|
66
85
|
}, [port1]);
|