veryfi-lens-wasm 3.5.10 → 3.5.11
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/core/camera.js +1 -1
- package/core/constants.js +3 -1
- package/core/state.js +3 -0
- package/core/wasm-processing.js +24 -3
- package/package.json +1 -1
- package/wasm/wasm.js +4 -1
package/core/camera.js
CHANGED
|
@@ -48,7 +48,7 @@ export const getVideo = async (lensFlavor) => {
|
|
|
48
48
|
const isAndroid = /Android/i.test(navigator.userAgent);
|
|
49
49
|
|
|
50
50
|
let videoConfig = {
|
|
51
|
-
...(lensFlavor === '
|
|
51
|
+
...(lensFlavor === 'prescription_label' || state.fullScreenEnabled ? {
|
|
52
52
|
width: { ideal: 1920 },
|
|
53
53
|
height: { ideal: 1080 }
|
|
54
54
|
} : {
|
package/core/constants.js
CHANGED
|
@@ -8,6 +8,7 @@ const WASM_PATH = '/static/wasm/';
|
|
|
8
8
|
|
|
9
9
|
export const WASM = {
|
|
10
10
|
BASE_URL: `${API_BASES.PROD}${WASM_PATH}`,
|
|
11
|
+
LOCAL_BASE_URL: '/wasm/',
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
const buildApiUrls = (base) => ({
|
|
@@ -39,7 +40,7 @@ export const setApiBaseUrl = (base) => {
|
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
export const DEFAULTS = {
|
|
42
|
-
SDK_VERSION: '3.5.
|
|
43
|
+
SDK_VERSION: '3.5.11',
|
|
43
44
|
BLUR_THRESHOLD: 0.7,
|
|
44
45
|
LCD_THRESHOLD: 0.5,
|
|
45
46
|
BOX_COLOR: 'rgba(84, 192, 139, 0.6)',
|
|
@@ -69,6 +70,7 @@ export const DEFAULTS = {
|
|
|
69
70
|
GUIDE_MAX_HEIGHT_SCALE: 0.70,
|
|
70
71
|
CROP_MARGIN: 0.0,
|
|
71
72
|
CHECKS_CROP_MARGIN: 0.1,
|
|
73
|
+
LONG_DOCUMENT_FRAME_SHORT_SIDE: 1080,
|
|
72
74
|
};
|
|
73
75
|
|
|
74
76
|
export const MESSAGES = {
|
package/core/state.js
CHANGED
|
@@ -64,6 +64,7 @@ export const state = {
|
|
|
64
64
|
frontImage: null,
|
|
65
65
|
backImage: null,
|
|
66
66
|
previewData: null,
|
|
67
|
+
longDocumentFrameScale: 1,
|
|
67
68
|
|
|
68
69
|
// Configuration
|
|
69
70
|
clientId: "",
|
|
@@ -79,6 +80,7 @@ export const state = {
|
|
|
79
80
|
enableFullScreen: false,
|
|
80
81
|
testBlurDetection: true,
|
|
81
82
|
useDevApi: false,
|
|
83
|
+
useLocalWasm: false,
|
|
82
84
|
|
|
83
85
|
// UI Configuration
|
|
84
86
|
theme: 'system',
|
|
@@ -377,6 +379,7 @@ export const resetState = () => {
|
|
|
377
379
|
state.frontImage = null;
|
|
378
380
|
state.backImage = null;
|
|
379
381
|
state.previewData = null;
|
|
382
|
+
state.longDocumentFrameScale = 1;
|
|
380
383
|
state.capCircleRadius = DEFAULTS.CAP_CIRCLE_RADIUS;
|
|
381
384
|
state.bottleCapText = MESSAGES.BOTTLE_CAP;
|
|
382
385
|
state.enforceAndSkipBothSides = false;
|
package/core/wasm-processing.js
CHANGED
|
@@ -50,7 +50,8 @@ export const initializeWasmWrapper = async () => {
|
|
|
50
50
|
}
|
|
51
51
|
if (!refs.wasmWrapper.loaded) {
|
|
52
52
|
await refs.wasmWrapper.initialize(state.clientId, {
|
|
53
|
-
wasmBaseUrl: WASM.BASE_URL,
|
|
53
|
+
wasmBaseUrl: state.useLocalWasm ? WASM.LOCAL_BASE_URL : WASM.BASE_URL,
|
|
54
|
+
hostedLayout: !state.useLocalWasm,
|
|
54
55
|
useDevApi: state.useDevApi,
|
|
55
56
|
debug: state.debug_mode,
|
|
56
57
|
});
|
|
@@ -121,7 +122,8 @@ export function logDocument(detectorResult, corners, nDocs) {
|
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
export function logLongDocument(stitcherResult, corners, nDocs, preview) {
|
|
124
|
-
|
|
125
|
+
const scale = state.longDocumentFrameScale;
|
|
126
|
+
state.coordinates = corners.map((corner) => [corner.x / scale, corner.y / scale]);
|
|
125
127
|
state.previewData = preview;
|
|
126
128
|
state.shouldUpdatePreview = stitcherResult === 0;
|
|
127
129
|
state.isDocument = corners.length > 0 && stitcherResult === 0;
|
|
@@ -190,6 +192,23 @@ export const logCard = (status, name, number, date, cvv) => {
|
|
|
190
192
|
}
|
|
191
193
|
};
|
|
192
194
|
|
|
195
|
+
const createLongDocumentFrame = async (video) => {
|
|
196
|
+
const scale = Math.min(
|
|
197
|
+
1,
|
|
198
|
+
DEFAULTS.LONG_DOCUMENT_FRAME_SHORT_SIDE / Math.min(video.videoWidth, video.videoHeight)
|
|
199
|
+
);
|
|
200
|
+
const bitmap = scale < 1
|
|
201
|
+
? await createImageBitmap(video, {
|
|
202
|
+
resizeWidth: Math.round(video.videoWidth * scale),
|
|
203
|
+
resizeHeight: Math.round(video.videoHeight * scale),
|
|
204
|
+
resizeQuality: 'medium',
|
|
205
|
+
})
|
|
206
|
+
: await createImageBitmap(video);
|
|
207
|
+
// Measured from the bitmap because some browsers ignore the resize options.
|
|
208
|
+
state.longDocumentFrameScale = bitmap.width / video.videoWidth;
|
|
209
|
+
return bitmap;
|
|
210
|
+
};
|
|
211
|
+
|
|
193
212
|
export const sendWasm = async (mode) => {
|
|
194
213
|
if (!refs.wasmWrapper) {
|
|
195
214
|
state.debug_mode && console.log("WASM wrapper not initialized");
|
|
@@ -267,7 +286,9 @@ export const sendWasm = async (mode) => {
|
|
|
267
286
|
}
|
|
268
287
|
} else {
|
|
269
288
|
try {
|
|
270
|
-
const bitmap =
|
|
289
|
+
const bitmap = state.lensFlavor === 'long_document'
|
|
290
|
+
? await createLongDocumentFrame(video)
|
|
291
|
+
: await createImageBitmap(video);
|
|
271
292
|
if (state.fullSizeImage?.close) {
|
|
272
293
|
state.fullSizeImage.close();
|
|
273
294
|
}
|
package/package.json
CHANGED
package/wasm/wasm.js
CHANGED
|
@@ -73,6 +73,9 @@ export class WasmWrapper {
|
|
|
73
73
|
* @param {Object} [options]
|
|
74
74
|
* @param {string} [options.wasmBaseUrl] - Base URL for hosted WASM files.
|
|
75
75
|
* Defaults to "/wasm/".
|
|
76
|
+
* @param {boolean} [options.hostedLayout] - When false, variants are read
|
|
77
|
+
* from `<wasmBaseUrl><variant>/` instead of `<wasmBaseUrl>hosted/<variant>/`.
|
|
78
|
+
* Defaults to true.
|
|
76
79
|
* @param {boolean} [options.useDevApi] - When true, WASM model fetches use
|
|
77
80
|
* lens-dev.veryfi.com instead of production.
|
|
78
81
|
*/
|
|
@@ -89,7 +92,7 @@ export class WasmWrapper {
|
|
|
89
92
|
console.log(`[PERF][WASM] feature detection: ${(performance.now() - tFeat0).toFixed(1)}ms (simd=${useSimd})`);
|
|
90
93
|
|
|
91
94
|
const simdDir = this.selectDir(useSimd);
|
|
92
|
-
const dir = "hosted/" + simdDir;
|
|
95
|
+
const dir = (options.hostedLayout === false ? "" : "hosted/") + simdDir;
|
|
93
96
|
console.log("[PERF][WASM] Using hosted build, variant:", simdDir);
|
|
94
97
|
|
|
95
98
|
const scriptUrl = wasmBaseUrl + dir + "/veryfi-wasm.js";
|