@stream-io/video-filters-web 0.0.1
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/CHANGELOG.md +10 -0
- package/LICENSE +202 -0
- package/README.md +50 -0
- package/dist/index.cjs.js +1558 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.es.js +1554 -0
- package/dist/index.es.js.map +1 -0
- package/dist/src/compatibility.d.ts +5 -0
- package/dist/src/createRenderer.d.ts +17 -0
- package/dist/src/helpers/webglHelper.d.ts +17 -0
- package/dist/src/segmentation.d.ts +9 -0
- package/dist/src/tflite.d.ts +19 -0
- package/dist/src/version.d.ts +2 -0
- package/dist/src/webgl2/backgroundBlurStage.d.ts +7 -0
- package/dist/src/webgl2/backgroundImageStage.d.ts +8 -0
- package/dist/src/webgl2/jointBilateralFilterStage.d.ts +7 -0
- package/dist/src/webgl2/resizingStage.d.ts +6 -0
- package/dist/src/webgl2/softmaxStage.d.ts +6 -0
- package/dist/src/webgl2/webgl2Pipeline.d.ts +8 -0
- package/index.ts +4 -0
- package/package.json +40 -0
- package/src/compatibility.ts +23 -0
- package/src/createRenderer.ts +63 -0
- package/src/helpers/webglHelper.ts +142 -0
- package/src/segmentation.ts +18 -0
- package/src/tflite-simd.js +874 -0
- package/src/tflite.ts +59 -0
- package/src/version.ts +3 -0
- package/src/webgl2/backgroundBlurStage.ts +307 -0
- package/src/webgl2/backgroundImageStage.ts +222 -0
- package/src/webgl2/jointBilateralFilterStage.ts +159 -0
- package/src/webgl2/resizingStage.ts +103 -0
- package/src/webgl2/softmaxStage.ts +103 -0
- package/src/webgl2/webgl2Pipeline.ts +200 -0
- package/tf/models/segm_full_v679.tflite +0 -0
- package/tf/tflite/tflite-simd.wasm +0 -0
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,1554 @@
|
|
|
1
|
+
import { simd } from 'wasm-feature-detect';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if the current platform is a mobile device.
|
|
5
|
+
*
|
|
6
|
+
* See:
|
|
7
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
|
|
8
|
+
*/
|
|
9
|
+
const isMobile = () => /Mobi/i.test(navigator.userAgent);
|
|
10
|
+
/**
|
|
11
|
+
* Runs a check to see if the current platform supports
|
|
12
|
+
* the necessary APIs required for the video filters.
|
|
13
|
+
*/
|
|
14
|
+
const isPlatformSupported = async () => typeof document !== 'undefined' &&
|
|
15
|
+
typeof window !== 'undefined' &&
|
|
16
|
+
typeof navigator !== 'undefined' &&
|
|
17
|
+
!isMobile() && // we don't support mobile devices yet due to performance issues
|
|
18
|
+
typeof WebAssembly !== 'undefined' &&
|
|
19
|
+
!!window.WebGL2RenderingContext && // WebGL2 is required for the video filters
|
|
20
|
+
!!document.createElement('canvas').getContext('webgl2') &&
|
|
21
|
+
(await simd()); // SIMD is required for the wasm module
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Use it along with boyswan.glsl-literal VSCode extension
|
|
25
|
+
* to get GLSL syntax highlighting.
|
|
26
|
+
* https://marketplace.visualstudio.com/items?itemName=boyswan.glsl-literal
|
|
27
|
+
*
|
|
28
|
+
* On VSCode OSS, boyswan.glsl-literal requires slevesque.shader extension
|
|
29
|
+
* to be installed as well.
|
|
30
|
+
* https://marketplace.visualstudio.com/items?itemName=slevesque.shader
|
|
31
|
+
*/
|
|
32
|
+
const glsl = String.raw;
|
|
33
|
+
function createPipelineStageProgram(gl, vertexShader, fragmentShader, positionBuffer, texCoordBuffer) {
|
|
34
|
+
const program = createProgram(gl, vertexShader, fragmentShader);
|
|
35
|
+
const positionAttributeLocation = gl.getAttribLocation(program, 'a_position');
|
|
36
|
+
gl.enableVertexAttribArray(positionAttributeLocation);
|
|
37
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
|
|
38
|
+
gl.vertexAttribPointer(positionAttributeLocation, 2, gl.FLOAT, false, 0, 0);
|
|
39
|
+
const texCoordAttributeLocation = gl.getAttribLocation(program, 'a_texCoord');
|
|
40
|
+
gl.enableVertexAttribArray(texCoordAttributeLocation);
|
|
41
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
|
|
42
|
+
gl.vertexAttribPointer(texCoordAttributeLocation, 2, gl.FLOAT, false, 0, 0);
|
|
43
|
+
return program;
|
|
44
|
+
}
|
|
45
|
+
function createProgram(gl, vertexShader, fragmentShader) {
|
|
46
|
+
const program = gl.createProgram();
|
|
47
|
+
gl.attachShader(program, vertexShader);
|
|
48
|
+
gl.attachShader(program, fragmentShader);
|
|
49
|
+
gl.linkProgram(program);
|
|
50
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
51
|
+
throw new Error(`Could not link WebGL program: ${gl.getProgramInfoLog(program)}`);
|
|
52
|
+
}
|
|
53
|
+
return program;
|
|
54
|
+
}
|
|
55
|
+
function compileShader(gl, shaderType, shaderSource) {
|
|
56
|
+
const shader = gl.createShader(shaderType);
|
|
57
|
+
gl.shaderSource(shader, shaderSource);
|
|
58
|
+
gl.compileShader(shader);
|
|
59
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
60
|
+
throw new Error(`Could not compile shader: ${gl.getShaderInfoLog(shader)}`);
|
|
61
|
+
}
|
|
62
|
+
return shader;
|
|
63
|
+
}
|
|
64
|
+
function createTexture(gl, internalformat, width, height, minFilter = gl.NEAREST, magFilter = gl.NEAREST) {
|
|
65
|
+
const texture = gl.createTexture();
|
|
66
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
67
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
68
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
69
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
|
|
70
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);
|
|
71
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, internalformat, width, height);
|
|
72
|
+
return texture;
|
|
73
|
+
}
|
|
74
|
+
async function readPixelsAsync(gl, x, y, width, height, format, type, dest) {
|
|
75
|
+
const buf = gl.createBuffer();
|
|
76
|
+
gl.bindBuffer(gl.PIXEL_PACK_BUFFER, buf);
|
|
77
|
+
gl.bufferData(gl.PIXEL_PACK_BUFFER, dest.byteLength, gl.STREAM_READ);
|
|
78
|
+
gl.readPixels(x, y, width, height, format, type, 0);
|
|
79
|
+
gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
|
|
80
|
+
await getBufferSubDataAsync(gl, gl.PIXEL_PACK_BUFFER, buf, 0, dest);
|
|
81
|
+
gl.deleteBuffer(buf);
|
|
82
|
+
return dest;
|
|
83
|
+
}
|
|
84
|
+
async function getBufferSubDataAsync(gl, target, buffer, srcByteOffset, dstBuffer, dstOffset, length) {
|
|
85
|
+
const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
|
|
86
|
+
gl.flush();
|
|
87
|
+
const res = await clientWaitAsync(gl, sync);
|
|
88
|
+
gl.deleteSync(sync);
|
|
89
|
+
if (res !== gl.WAIT_FAILED) {
|
|
90
|
+
gl.bindBuffer(target, buffer);
|
|
91
|
+
gl.getBufferSubData(target, srcByteOffset, dstBuffer, dstOffset, length);
|
|
92
|
+
gl.bindBuffer(target, null);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function clientWaitAsync(gl, sync) {
|
|
96
|
+
return new Promise((resolve) => {
|
|
97
|
+
function test() {
|
|
98
|
+
const res = gl.clientWaitSync(sync, 0, 0);
|
|
99
|
+
if (res === gl.WAIT_FAILED) {
|
|
100
|
+
resolve(res);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (res === gl.TIMEOUT_EXPIRED) {
|
|
104
|
+
setTimeout(test);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
resolve(res);
|
|
108
|
+
}
|
|
109
|
+
setTimeout(test);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function buildBackgroundBlurStage(gl, vertexShader, positionBuffer, texCoordBuffer, personMaskTexture, canvas, blurLevel) {
|
|
114
|
+
const blurPass = buildBlurPass(gl, vertexShader, positionBuffer, texCoordBuffer, personMaskTexture, canvas, blurLevel);
|
|
115
|
+
const blendPass = buildBlendPass(gl, positionBuffer, texCoordBuffer, canvas);
|
|
116
|
+
function render() {
|
|
117
|
+
blurPass.render();
|
|
118
|
+
blendPass.render();
|
|
119
|
+
}
|
|
120
|
+
function updateCoverage(coverage) {
|
|
121
|
+
blendPass.updateCoverage(coverage);
|
|
122
|
+
}
|
|
123
|
+
function cleanUp() {
|
|
124
|
+
blendPass.cleanUp();
|
|
125
|
+
blurPass.cleanUp();
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
render,
|
|
129
|
+
updateCoverage,
|
|
130
|
+
cleanUp,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function buildBlurPass(gl, vertexShader, positionBuffer, texCoordBuffer, personMaskTexture, canvas, blurLevel) {
|
|
134
|
+
const weights = blurLevel === 'low'
|
|
135
|
+
? [0.227027027, 0.1545945946, 0.1016216216, 0.0340540541, 0.0142162162]
|
|
136
|
+
: blurLevel === 'medium'
|
|
137
|
+
? [0.327027027, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162]
|
|
138
|
+
: [0.627027027, 0.3445945946, 0.2216216216, 0.0540540541, 0.0162162162];
|
|
139
|
+
const fragmentShaderSource = glsl `#version 300 es
|
|
140
|
+
|
|
141
|
+
precision highp float;
|
|
142
|
+
|
|
143
|
+
uniform sampler2D u_inputFrame;
|
|
144
|
+
uniform sampler2D u_personMask;
|
|
145
|
+
uniform vec2 u_texelSize;
|
|
146
|
+
|
|
147
|
+
in vec2 v_texCoord;
|
|
148
|
+
out vec4 outColor;
|
|
149
|
+
|
|
150
|
+
const float offset[5] = float[](0.0, 1.0, 2.0, 3.0, 4.0);
|
|
151
|
+
const float weight[5] = float[](
|
|
152
|
+
${weights.join(',')}
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
void main() {
|
|
156
|
+
vec4 centerColor = texture(u_inputFrame, v_texCoord);
|
|
157
|
+
float personMask = texture(u_personMask, v_texCoord).a;
|
|
158
|
+
|
|
159
|
+
vec4 frameColor = centerColor * weight[0] * (1.0 - personMask);
|
|
160
|
+
|
|
161
|
+
for (int i = 1; i < 5; i++) {
|
|
162
|
+
vec2 offset = vec2(offset[i]) * u_texelSize;
|
|
163
|
+
|
|
164
|
+
vec2 texCoord = v_texCoord + offset;
|
|
165
|
+
frameColor += texture(u_inputFrame, texCoord)
|
|
166
|
+
* weight[i]
|
|
167
|
+
* (1.0 - texture(u_personMask, texCoord).a);
|
|
168
|
+
|
|
169
|
+
texCoord = v_texCoord - offset;
|
|
170
|
+
frameColor += texture(u_inputFrame, texCoord)
|
|
171
|
+
* weight[i]
|
|
172
|
+
* (1.0 - texture(u_personMask, texCoord).a);
|
|
173
|
+
}
|
|
174
|
+
outColor = vec4(frameColor.rgb + (1.0 - frameColor.a) * centerColor.rgb, 1.0);
|
|
175
|
+
}
|
|
176
|
+
`;
|
|
177
|
+
const scale = 0.5;
|
|
178
|
+
const outputWidth = canvas.width * scale;
|
|
179
|
+
const outputHeight = canvas.height * scale;
|
|
180
|
+
const texelWidth = 1 / outputWidth;
|
|
181
|
+
const texelHeight = 1 / outputHeight;
|
|
182
|
+
const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);
|
|
183
|
+
const program = createPipelineStageProgram(gl, vertexShader, fragmentShader, positionBuffer, texCoordBuffer);
|
|
184
|
+
const inputFrameLocation = gl.getUniformLocation(program, 'u_inputFrame');
|
|
185
|
+
const personMaskLocation = gl.getUniformLocation(program, 'u_personMask');
|
|
186
|
+
const texelSizeLocation = gl.getUniformLocation(program, 'u_texelSize');
|
|
187
|
+
const texture1 = createTexture(gl, gl.RGBA8, outputWidth, outputHeight, gl.NEAREST,
|
|
188
|
+
// @ts-expect-error types are incomplete
|
|
189
|
+
gl.LINEAR);
|
|
190
|
+
const texture2 = createTexture(gl, gl.RGBA8, outputWidth, outputHeight, gl.NEAREST,
|
|
191
|
+
// @ts-expect-error types are incomplete
|
|
192
|
+
gl.LINEAR);
|
|
193
|
+
const frameBuffer1 = gl.createFramebuffer();
|
|
194
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer1);
|
|
195
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture1, 0);
|
|
196
|
+
const frameBuffer2 = gl.createFramebuffer();
|
|
197
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer2);
|
|
198
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture2, 0);
|
|
199
|
+
gl.useProgram(program);
|
|
200
|
+
gl.uniform1i(personMaskLocation, 1);
|
|
201
|
+
function render() {
|
|
202
|
+
gl.viewport(0, 0, outputWidth, outputHeight);
|
|
203
|
+
gl.useProgram(program);
|
|
204
|
+
gl.uniform1i(inputFrameLocation, 0);
|
|
205
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
206
|
+
gl.bindTexture(gl.TEXTURE_2D, personMaskTexture);
|
|
207
|
+
for (let i = 0; i < 3; i++) {
|
|
208
|
+
gl.uniform2f(texelSizeLocation, 0, texelHeight);
|
|
209
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer1);
|
|
210
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
211
|
+
gl.activeTexture(gl.TEXTURE2);
|
|
212
|
+
gl.bindTexture(gl.TEXTURE_2D, texture1);
|
|
213
|
+
gl.uniform1i(inputFrameLocation, 2);
|
|
214
|
+
gl.uniform2f(texelSizeLocation, texelWidth, 0);
|
|
215
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer2);
|
|
216
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
217
|
+
gl.bindTexture(gl.TEXTURE_2D, texture2);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function cleanUp() {
|
|
221
|
+
gl.deleteFramebuffer(frameBuffer2);
|
|
222
|
+
gl.deleteFramebuffer(frameBuffer1);
|
|
223
|
+
gl.deleteTexture(texture2);
|
|
224
|
+
gl.deleteTexture(texture1);
|
|
225
|
+
gl.deleteProgram(program);
|
|
226
|
+
gl.deleteShader(fragmentShader);
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
render,
|
|
230
|
+
cleanUp,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function buildBlendPass(gl, positionBuffer, texCoordBuffer, canvas) {
|
|
234
|
+
const vertexShaderSource = glsl `#version 300 es
|
|
235
|
+
|
|
236
|
+
in vec2 a_position;
|
|
237
|
+
in vec2 a_texCoord;
|
|
238
|
+
|
|
239
|
+
out vec2 v_texCoord;
|
|
240
|
+
|
|
241
|
+
void main() {
|
|
242
|
+
// Flipping Y is required when rendering to canvas
|
|
243
|
+
gl_Position = vec4(a_position * vec2(1.0, -1.0), 0.0, 1.0);
|
|
244
|
+
v_texCoord = a_texCoord;
|
|
245
|
+
}
|
|
246
|
+
`;
|
|
247
|
+
const fragmentShaderSource = glsl `#version 300 es
|
|
248
|
+
|
|
249
|
+
precision highp float;
|
|
250
|
+
|
|
251
|
+
uniform sampler2D u_inputFrame;
|
|
252
|
+
uniform sampler2D u_personMask;
|
|
253
|
+
uniform sampler2D u_blurredInputFrame;
|
|
254
|
+
uniform vec2 u_coverage;
|
|
255
|
+
|
|
256
|
+
in vec2 v_texCoord;
|
|
257
|
+
|
|
258
|
+
out vec4 outColor;
|
|
259
|
+
|
|
260
|
+
void main() {
|
|
261
|
+
vec3 color = texture(u_inputFrame, v_texCoord).rgb;
|
|
262
|
+
vec3 blurredColor = texture(u_blurredInputFrame, v_texCoord).rgb;
|
|
263
|
+
float personMask = texture(u_personMask, v_texCoord).a;
|
|
264
|
+
personMask = smoothstep(u_coverage.x, u_coverage.y, personMask);
|
|
265
|
+
outColor = vec4(mix(blurredColor, color, personMask), 1.0);
|
|
266
|
+
}
|
|
267
|
+
`;
|
|
268
|
+
const { width: outputWidth, height: outputHeight } = canvas;
|
|
269
|
+
const vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexShaderSource);
|
|
270
|
+
const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);
|
|
271
|
+
const program = createPipelineStageProgram(gl, vertexShader, fragmentShader, positionBuffer, texCoordBuffer);
|
|
272
|
+
const inputFrameLocation = gl.getUniformLocation(program, 'u_inputFrame');
|
|
273
|
+
const personMaskLocation = gl.getUniformLocation(program, 'u_personMask');
|
|
274
|
+
const blurredInputFrame = gl.getUniformLocation(program, 'u_blurredInputFrame');
|
|
275
|
+
const coverageLocation = gl.getUniformLocation(program, 'u_coverage');
|
|
276
|
+
gl.useProgram(program);
|
|
277
|
+
gl.uniform1i(inputFrameLocation, 0);
|
|
278
|
+
gl.uniform1i(personMaskLocation, 1);
|
|
279
|
+
gl.uniform1i(blurredInputFrame, 2);
|
|
280
|
+
gl.uniform2f(coverageLocation, 0, 1);
|
|
281
|
+
function render() {
|
|
282
|
+
gl.viewport(0, 0, outputWidth, outputHeight);
|
|
283
|
+
gl.useProgram(program);
|
|
284
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
285
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
286
|
+
}
|
|
287
|
+
function updateCoverage(coverage) {
|
|
288
|
+
gl.useProgram(program);
|
|
289
|
+
gl.uniform2f(coverageLocation, coverage[0], coverage[1]);
|
|
290
|
+
}
|
|
291
|
+
function cleanUp() {
|
|
292
|
+
gl.deleteProgram(program);
|
|
293
|
+
gl.deleteShader(fragmentShader);
|
|
294
|
+
gl.deleteShader(vertexShader);
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
render,
|
|
298
|
+
updateCoverage,
|
|
299
|
+
cleanUp,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function buildBackgroundImageStage(gl, positionBuffer, texCoordBuffer, personMaskTexture, backgroundImage, canvas) {
|
|
304
|
+
const vertexShaderSource = glsl `#version 300 es
|
|
305
|
+
|
|
306
|
+
uniform vec2 u_backgroundScale;
|
|
307
|
+
uniform vec2 u_backgroundOffset;
|
|
308
|
+
|
|
309
|
+
in vec2 a_position;
|
|
310
|
+
in vec2 a_texCoord;
|
|
311
|
+
|
|
312
|
+
out vec2 v_texCoord;
|
|
313
|
+
out vec2 v_backgroundCoord;
|
|
314
|
+
|
|
315
|
+
void main() {
|
|
316
|
+
// Flipping Y is required when rendering to canvas
|
|
317
|
+
gl_Position = vec4(a_position * vec2(1.0, -1.0), 0.0, 1.0);
|
|
318
|
+
v_texCoord = a_texCoord;
|
|
319
|
+
v_backgroundCoord = a_texCoord * u_backgroundScale + u_backgroundOffset;
|
|
320
|
+
}
|
|
321
|
+
`;
|
|
322
|
+
const fragmentShaderSource = glsl `#version 300 es
|
|
323
|
+
|
|
324
|
+
precision highp float;
|
|
325
|
+
|
|
326
|
+
uniform sampler2D u_inputFrame;
|
|
327
|
+
uniform sampler2D u_personMask;
|
|
328
|
+
uniform sampler2D u_background;
|
|
329
|
+
uniform vec2 u_coverage;
|
|
330
|
+
uniform float u_lightWrapping;
|
|
331
|
+
uniform float u_blendMode;
|
|
332
|
+
|
|
333
|
+
in vec2 v_texCoord;
|
|
334
|
+
in vec2 v_backgroundCoord;
|
|
335
|
+
|
|
336
|
+
out vec4 outColor;
|
|
337
|
+
|
|
338
|
+
vec3 screen(vec3 a, vec3 b) {
|
|
339
|
+
return 1.0 - (1.0 - a) * (1.0 - b);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
vec3 linearDodge(vec3 a, vec3 b) {
|
|
343
|
+
return a + b;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
void main() {
|
|
347
|
+
vec3 frameColor = texture(u_inputFrame, v_texCoord).rgb;
|
|
348
|
+
vec3 backgroundColor = texture(u_background, v_backgroundCoord).rgb;
|
|
349
|
+
float personMask = texture(u_personMask, v_texCoord).a;
|
|
350
|
+
float lightWrapMask = 1.0 - max(0.0, personMask - u_coverage.y) / (1.0 - u_coverage.y);
|
|
351
|
+
vec3 lightWrap = u_lightWrapping * lightWrapMask * backgroundColor;
|
|
352
|
+
|
|
353
|
+
frameColor = u_blendMode * linearDodge(frameColor, lightWrap)
|
|
354
|
+
+ (1.0 - u_blendMode) * screen(frameColor, lightWrap);
|
|
355
|
+
personMask = smoothstep(u_coverage.x, u_coverage.y, personMask);
|
|
356
|
+
outColor = vec4(frameColor * personMask + backgroundColor * (1.0 - personMask), 1.0);
|
|
357
|
+
}
|
|
358
|
+
`;
|
|
359
|
+
const { width: outputWidth, height: outputHeight } = canvas;
|
|
360
|
+
const outputRatio = outputWidth / outputHeight;
|
|
361
|
+
const vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexShaderSource);
|
|
362
|
+
const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);
|
|
363
|
+
const program = createPipelineStageProgram(gl, vertexShader, fragmentShader, positionBuffer, texCoordBuffer);
|
|
364
|
+
const backgroundScaleLocation = gl.getUniformLocation(program, 'u_backgroundScale');
|
|
365
|
+
const backgroundOffsetLocation = gl.getUniformLocation(program, 'u_backgroundOffset');
|
|
366
|
+
const inputFrameLocation = gl.getUniformLocation(program, 'u_inputFrame');
|
|
367
|
+
const personMaskLocation = gl.getUniformLocation(program, 'u_personMask');
|
|
368
|
+
const backgroundLocation = gl.getUniformLocation(program, 'u_background');
|
|
369
|
+
const coverageLocation = gl.getUniformLocation(program, 'u_coverage');
|
|
370
|
+
const lightWrappingLocation = gl.getUniformLocation(program, 'u_lightWrapping');
|
|
371
|
+
const blendModeLocation = gl.getUniformLocation(program, 'u_blendMode');
|
|
372
|
+
gl.useProgram(program);
|
|
373
|
+
gl.uniform2f(backgroundScaleLocation, 1, 1);
|
|
374
|
+
gl.uniform2f(backgroundOffsetLocation, 0, 0);
|
|
375
|
+
gl.uniform1i(inputFrameLocation, 0);
|
|
376
|
+
gl.uniform1i(personMaskLocation, 1);
|
|
377
|
+
gl.uniform2f(coverageLocation, 0, 1);
|
|
378
|
+
gl.uniform1f(lightWrappingLocation, 0);
|
|
379
|
+
gl.uniform1f(blendModeLocation, 0);
|
|
380
|
+
let backgroundTexture = null;
|
|
381
|
+
// TODO Find a better to handle background being loaded
|
|
382
|
+
if (backgroundImage?.complete) {
|
|
383
|
+
updateBackgroundImage(backgroundImage);
|
|
384
|
+
}
|
|
385
|
+
else if (backgroundImage) {
|
|
386
|
+
backgroundImage.onload = () => {
|
|
387
|
+
updateBackgroundImage(backgroundImage);
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function render() {
|
|
391
|
+
gl.viewport(0, 0, outputWidth, outputHeight);
|
|
392
|
+
gl.useProgram(program);
|
|
393
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
394
|
+
gl.bindTexture(gl.TEXTURE_2D, personMaskTexture);
|
|
395
|
+
if (backgroundTexture !== null) {
|
|
396
|
+
gl.activeTexture(gl.TEXTURE2);
|
|
397
|
+
gl.bindTexture(gl.TEXTURE_2D, backgroundTexture);
|
|
398
|
+
// TODO Handle correctly the background not loaded yet
|
|
399
|
+
gl.uniform1i(backgroundLocation, 2);
|
|
400
|
+
}
|
|
401
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
402
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
403
|
+
}
|
|
404
|
+
function updateBackgroundImage(bgImage) {
|
|
405
|
+
backgroundTexture = createTexture(gl, gl.RGBA8, bgImage.naturalWidth, bgImage.naturalHeight,
|
|
406
|
+
// @ts-expect-error types are incomplete
|
|
407
|
+
gl.LINEAR, gl.LINEAR);
|
|
408
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, bgImage.naturalWidth, bgImage.naturalHeight, gl.RGBA, gl.UNSIGNED_BYTE, bgImage);
|
|
409
|
+
let xOffset = 0;
|
|
410
|
+
let yOffset = 0;
|
|
411
|
+
let backgroundWidth = bgImage.naturalWidth;
|
|
412
|
+
let backgroundHeight = bgImage.naturalHeight;
|
|
413
|
+
const backgroundRatio = backgroundWidth / backgroundHeight;
|
|
414
|
+
if (backgroundRatio < outputRatio) {
|
|
415
|
+
backgroundHeight = backgroundWidth / outputRatio;
|
|
416
|
+
yOffset = (bgImage.naturalHeight - backgroundHeight) / 2;
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
backgroundWidth = backgroundHeight * outputRatio;
|
|
420
|
+
xOffset = (bgImage.naturalWidth - backgroundWidth) / 2;
|
|
421
|
+
}
|
|
422
|
+
const xScale = backgroundWidth / bgImage.naturalWidth;
|
|
423
|
+
const yScale = backgroundHeight / bgImage.naturalHeight;
|
|
424
|
+
xOffset /= bgImage.naturalWidth;
|
|
425
|
+
yOffset /= bgImage.naturalHeight;
|
|
426
|
+
gl.uniform2f(backgroundScaleLocation, xScale, yScale);
|
|
427
|
+
gl.uniform2f(backgroundOffsetLocation, xOffset, yOffset);
|
|
428
|
+
}
|
|
429
|
+
function updateCoverage(coverage) {
|
|
430
|
+
gl.useProgram(program);
|
|
431
|
+
gl.uniform2f(coverageLocation, coverage[0], coverage[1]);
|
|
432
|
+
}
|
|
433
|
+
function updateLightWrapping(lightWrapping) {
|
|
434
|
+
gl.useProgram(program);
|
|
435
|
+
gl.uniform1f(lightWrappingLocation, lightWrapping);
|
|
436
|
+
}
|
|
437
|
+
function updateBlendMode(blendMode) {
|
|
438
|
+
gl.useProgram(program);
|
|
439
|
+
gl.uniform1f(blendModeLocation, blendMode === 'screen' ? 0 : 1);
|
|
440
|
+
}
|
|
441
|
+
function cleanUp() {
|
|
442
|
+
gl.deleteTexture(backgroundTexture);
|
|
443
|
+
gl.deleteProgram(program);
|
|
444
|
+
gl.deleteShader(fragmentShader);
|
|
445
|
+
gl.deleteShader(vertexShader);
|
|
446
|
+
}
|
|
447
|
+
return {
|
|
448
|
+
render,
|
|
449
|
+
updateCoverage,
|
|
450
|
+
updateLightWrapping,
|
|
451
|
+
updateBlendMode,
|
|
452
|
+
cleanUp,
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function buildJointBilateralFilterStage(gl, vertexShader, positionBuffer, texCoordBuffer, inputTexture, outputTexture, canvas, segmentationConfig) {
|
|
457
|
+
const fragmentShaderSource = glsl `#version 300 es
|
|
458
|
+
|
|
459
|
+
precision highp float;
|
|
460
|
+
|
|
461
|
+
uniform sampler2D u_inputFrame;
|
|
462
|
+
uniform sampler2D u_segmentationMask;
|
|
463
|
+
uniform vec2 u_texelSize;
|
|
464
|
+
uniform float u_step;
|
|
465
|
+
uniform float u_radius;
|
|
466
|
+
uniform float u_offset;
|
|
467
|
+
uniform float u_sigmaTexel;
|
|
468
|
+
uniform float u_sigmaColor;
|
|
469
|
+
|
|
470
|
+
in vec2 v_texCoord;
|
|
471
|
+
out vec4 outColor;
|
|
472
|
+
|
|
473
|
+
float gaussian(float x, float sigma) {
|
|
474
|
+
float coeff = -0.5 / (sigma * sigma * 4.0 + 1.0e-6);
|
|
475
|
+
return exp((x * x) * coeff);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
void main() {
|
|
479
|
+
vec2 centerCoord = v_texCoord;
|
|
480
|
+
vec3 centerColor = texture(u_inputFrame, centerCoord).rgb;
|
|
481
|
+
float newVal = 0.0;
|
|
482
|
+
|
|
483
|
+
float spaceWeight = 0.0;
|
|
484
|
+
float colorWeight = 0.0;
|
|
485
|
+
float totalWeight = 0.0;
|
|
486
|
+
|
|
487
|
+
// Subsample kernel space.
|
|
488
|
+
for (float i = -u_radius + u_offset; i <= u_radius; i += u_step) {
|
|
489
|
+
for (float j = -u_radius + u_offset; j <= u_radius; j += u_step) {
|
|
490
|
+
vec2 shift = vec2(j, i) * u_texelSize;
|
|
491
|
+
vec2 coord = vec2(centerCoord + shift);
|
|
492
|
+
vec3 frameColor = texture(u_inputFrame, coord).rgb;
|
|
493
|
+
float outVal = texture(u_segmentationMask, coord).a;
|
|
494
|
+
|
|
495
|
+
spaceWeight = gaussian(distance(centerCoord, coord), u_sigmaTexel);
|
|
496
|
+
colorWeight = gaussian(distance(centerColor, frameColor), u_sigmaColor);
|
|
497
|
+
totalWeight += spaceWeight * colorWeight;
|
|
498
|
+
|
|
499
|
+
newVal += spaceWeight * colorWeight * outVal;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
newVal /= totalWeight;
|
|
503
|
+
|
|
504
|
+
outColor = vec4(vec3(0.0), newVal);
|
|
505
|
+
}
|
|
506
|
+
`;
|
|
507
|
+
const { width: segmentationWidth, height: segmentationHeight } = segmentationConfig;
|
|
508
|
+
const { width: outputWidth, height: outputHeight } = canvas;
|
|
509
|
+
const texelWidth = 1 / outputWidth;
|
|
510
|
+
const texelHeight = 1 / outputHeight;
|
|
511
|
+
const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);
|
|
512
|
+
const program = createPipelineStageProgram(gl, vertexShader, fragmentShader, positionBuffer, texCoordBuffer);
|
|
513
|
+
const inputFrameLocation = gl.getUniformLocation(program, 'u_inputFrame');
|
|
514
|
+
const segmentationMaskLocation = gl.getUniformLocation(program, 'u_segmentationMask');
|
|
515
|
+
const texelSizeLocation = gl.getUniformLocation(program, 'u_texelSize');
|
|
516
|
+
const stepLocation = gl.getUniformLocation(program, 'u_step');
|
|
517
|
+
const radiusLocation = gl.getUniformLocation(program, 'u_radius');
|
|
518
|
+
const offsetLocation = gl.getUniformLocation(program, 'u_offset');
|
|
519
|
+
const sigmaTexelLocation = gl.getUniformLocation(program, 'u_sigmaTexel');
|
|
520
|
+
const sigmaColorLocation = gl.getUniformLocation(program, 'u_sigmaColor');
|
|
521
|
+
const frameBuffer = gl.createFramebuffer();
|
|
522
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
|
|
523
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, outputTexture, 0);
|
|
524
|
+
gl.useProgram(program);
|
|
525
|
+
gl.uniform1i(inputFrameLocation, 0);
|
|
526
|
+
gl.uniform1i(segmentationMaskLocation, 1);
|
|
527
|
+
gl.uniform2f(texelSizeLocation, texelWidth, texelHeight);
|
|
528
|
+
// Ensures default values are configured to prevent infinite
|
|
529
|
+
// loop in fragment shader
|
|
530
|
+
updateSigmaSpace(0);
|
|
531
|
+
updateSigmaColor(0);
|
|
532
|
+
function render() {
|
|
533
|
+
gl.viewport(0, 0, outputWidth, outputHeight);
|
|
534
|
+
gl.useProgram(program);
|
|
535
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
536
|
+
gl.bindTexture(gl.TEXTURE_2D, inputTexture);
|
|
537
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
|
|
538
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
539
|
+
}
|
|
540
|
+
function updateSigmaSpace(sigmaSpace) {
|
|
541
|
+
sigmaSpace *= Math.max(outputWidth / segmentationWidth, outputHeight / segmentationHeight);
|
|
542
|
+
const kSparsityFactor = 0.66; // Higher is sparser.
|
|
543
|
+
const step = Math.max(1, Math.sqrt(sigmaSpace) * kSparsityFactor);
|
|
544
|
+
const radius = sigmaSpace;
|
|
545
|
+
const offset = step > 1 ? step * 0.5 : 0;
|
|
546
|
+
const sigmaTexel = Math.max(texelWidth, texelHeight) * sigmaSpace;
|
|
547
|
+
gl.useProgram(program);
|
|
548
|
+
gl.uniform1f(stepLocation, step);
|
|
549
|
+
gl.uniform1f(radiusLocation, radius);
|
|
550
|
+
gl.uniform1f(offsetLocation, offset);
|
|
551
|
+
gl.uniform1f(sigmaTexelLocation, sigmaTexel);
|
|
552
|
+
}
|
|
553
|
+
function updateSigmaColor(sigmaColor) {
|
|
554
|
+
gl.useProgram(program);
|
|
555
|
+
gl.uniform1f(sigmaColorLocation, sigmaColor);
|
|
556
|
+
}
|
|
557
|
+
function cleanUp() {
|
|
558
|
+
gl.deleteFramebuffer(frameBuffer);
|
|
559
|
+
gl.deleteProgram(program);
|
|
560
|
+
gl.deleteShader(fragmentShader);
|
|
561
|
+
}
|
|
562
|
+
return { render, updateSigmaSpace, updateSigmaColor, cleanUp };
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
function buildResizingStage(gl, vertexShader, positionBuffer, texCoordBuffer, tflite, segmentationConfig) {
|
|
566
|
+
const fragmentShaderSource = glsl `#version 300 es
|
|
567
|
+
|
|
568
|
+
precision highp float;
|
|
569
|
+
uniform sampler2D u_inputFrame;
|
|
570
|
+
in vec2 v_texCoord;
|
|
571
|
+
out vec4 outColor;
|
|
572
|
+
|
|
573
|
+
void main() {
|
|
574
|
+
outColor = texture(u_inputFrame, v_texCoord);
|
|
575
|
+
}
|
|
576
|
+
`;
|
|
577
|
+
// TFLite memory will be accessed as float32
|
|
578
|
+
const tfliteInputMemoryOffset = tflite._getInputMemoryOffset() / 4;
|
|
579
|
+
const { width: outputWidth, height: outputHeight } = segmentationConfig;
|
|
580
|
+
const outputPixelCount = outputWidth * outputHeight;
|
|
581
|
+
const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);
|
|
582
|
+
const program = createPipelineStageProgram(gl, vertexShader, fragmentShader, positionBuffer, texCoordBuffer);
|
|
583
|
+
const inputFrameLocation = gl.getUniformLocation(program, 'u_inputFrame');
|
|
584
|
+
const outputTexture = createTexture(gl, gl.RGBA8, outputWidth, outputHeight);
|
|
585
|
+
const frameBuffer = gl.createFramebuffer();
|
|
586
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
|
|
587
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, outputTexture, 0);
|
|
588
|
+
const outputPixels = new Uint8Array(outputPixelCount * 4);
|
|
589
|
+
gl.useProgram(program);
|
|
590
|
+
gl.uniform1i(inputFrameLocation, 0);
|
|
591
|
+
function render() {
|
|
592
|
+
gl.viewport(0, 0, outputWidth, outputHeight);
|
|
593
|
+
gl.useProgram(program);
|
|
594
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
|
|
595
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
596
|
+
// Downloads pixels asynchronously from GPU while rendering the current frame.
|
|
597
|
+
// The pixels will be available in the next frame render which results
|
|
598
|
+
// in offsets in the segmentation output but increases the frame rate.
|
|
599
|
+
readPixelsAsync(gl, 0, 0, outputWidth, outputHeight, gl.RGBA, gl.UNSIGNED_BYTE, outputPixels);
|
|
600
|
+
for (let i = 0; i < outputPixelCount; i++) {
|
|
601
|
+
const tfliteIndex = tfliteInputMemoryOffset + i * 3;
|
|
602
|
+
const outputIndex = i * 4;
|
|
603
|
+
tflite.HEAPF32[tfliteIndex] = outputPixels[outputIndex] / 255;
|
|
604
|
+
tflite.HEAPF32[tfliteIndex + 1] = outputPixels[outputIndex + 1] / 255;
|
|
605
|
+
tflite.HEAPF32[tfliteIndex + 2] = outputPixels[outputIndex + 2] / 255;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
function cleanUp() {
|
|
609
|
+
gl.deleteFramebuffer(frameBuffer);
|
|
610
|
+
gl.deleteTexture(outputTexture);
|
|
611
|
+
gl.deleteProgram(program);
|
|
612
|
+
gl.deleteShader(fragmentShader);
|
|
613
|
+
}
|
|
614
|
+
return { render, cleanUp };
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function buildSoftmaxStage(gl, vertexShader, positionBuffer, texCoordBuffer, tflite, outputTexture, segmentationConfig) {
|
|
618
|
+
const fragmentShaderSource = glsl `#version 300 es
|
|
619
|
+
|
|
620
|
+
precision highp float;
|
|
621
|
+
|
|
622
|
+
uniform sampler2D u_inputSegmentation;
|
|
623
|
+
in vec2 v_texCoord;
|
|
624
|
+
out vec4 outColor;
|
|
625
|
+
|
|
626
|
+
void main() {
|
|
627
|
+
vec2 segmentation = texture(u_inputSegmentation, v_texCoord).rg;
|
|
628
|
+
float shift = max(segmentation.r, segmentation.g);
|
|
629
|
+
float backgroundExp = exp(segmentation.r - shift);
|
|
630
|
+
float personExp = exp(segmentation.g - shift);
|
|
631
|
+
outColor = vec4(vec3(0.0), personExp / (backgroundExp + personExp));
|
|
632
|
+
}
|
|
633
|
+
`;
|
|
634
|
+
// TFLite memory will be accessed as float32
|
|
635
|
+
const tfliteOutputMemoryOffset = tflite._getOutputMemoryOffset() / 4;
|
|
636
|
+
const { width: segmentationWidth, height: segmentationHeight } = segmentationConfig;
|
|
637
|
+
const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);
|
|
638
|
+
const program = createPipelineStageProgram(gl, vertexShader, fragmentShader, positionBuffer, texCoordBuffer);
|
|
639
|
+
const inputLocation = gl.getUniformLocation(program, 'u_inputSegmentation');
|
|
640
|
+
const inputTexture = createTexture(gl, gl.RG32F, segmentationWidth, segmentationHeight);
|
|
641
|
+
const frameBuffer = gl.createFramebuffer();
|
|
642
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
|
|
643
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, outputTexture, 0);
|
|
644
|
+
gl.useProgram(program);
|
|
645
|
+
gl.uniform1i(inputLocation, 1);
|
|
646
|
+
function render() {
|
|
647
|
+
gl.viewport(0, 0, segmentationWidth, segmentationHeight);
|
|
648
|
+
gl.useProgram(program);
|
|
649
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
650
|
+
gl.bindTexture(gl.TEXTURE_2D, inputTexture);
|
|
651
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, segmentationWidth, segmentationHeight, gl.RG, gl.FLOAT, tflite.HEAPF32, tfliteOutputMemoryOffset);
|
|
652
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
|
|
653
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
654
|
+
}
|
|
655
|
+
function cleanUp() {
|
|
656
|
+
gl.deleteFramebuffer(frameBuffer);
|
|
657
|
+
gl.deleteTexture(inputTexture);
|
|
658
|
+
gl.deleteProgram(program);
|
|
659
|
+
gl.deleteShader(fragmentShader);
|
|
660
|
+
}
|
|
661
|
+
return { render, cleanUp };
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
function buildWebGL2Pipeline(videoSource, backgroundImage, blurLevel, backgroundFilter, canvas, tflite, segmentationConfig) {
|
|
665
|
+
const gl = canvas.getContext('webgl2');
|
|
666
|
+
if (!gl)
|
|
667
|
+
throw new Error('WebGL2 is not supported');
|
|
668
|
+
const { width: frameWidth, height: frameHeight } = videoSource;
|
|
669
|
+
const { width: segmentationWidth, height: segmentationHeight } = segmentationConfig;
|
|
670
|
+
const vertexShaderSource = glsl `#version 300 es
|
|
671
|
+
|
|
672
|
+
in vec2 a_position;
|
|
673
|
+
in vec2 a_texCoord;
|
|
674
|
+
out vec2 v_texCoord;
|
|
675
|
+
|
|
676
|
+
void main() {
|
|
677
|
+
gl_Position = vec4(a_position, 0.0, 1.0);
|
|
678
|
+
v_texCoord = a_texCoord;
|
|
679
|
+
}
|
|
680
|
+
`;
|
|
681
|
+
const vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexShaderSource);
|
|
682
|
+
const vertexArray = gl.createVertexArray();
|
|
683
|
+
gl.bindVertexArray(vertexArray);
|
|
684
|
+
const positionBuffer = gl.createBuffer();
|
|
685
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
|
|
686
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0]), gl.STATIC_DRAW);
|
|
687
|
+
const texCoordBuffer = gl.createBuffer();
|
|
688
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
|
|
689
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0]), gl.STATIC_DRAW);
|
|
690
|
+
// We don't use texStorage2D here because texImage2D seems faster
|
|
691
|
+
// to upload video texture than texSubImage2D even though the latter
|
|
692
|
+
// is supposed to be the recommended way:
|
|
693
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#use_texstorage_to_create_textures
|
|
694
|
+
const inputFrameTexture = gl.createTexture();
|
|
695
|
+
gl.bindTexture(gl.TEXTURE_2D, inputFrameTexture);
|
|
696
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
697
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
698
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
699
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
700
|
+
// TODO Rename segmentation and person mask to be more specific
|
|
701
|
+
const segmentationTexture = createTexture(gl, gl.RGBA8, segmentationWidth, segmentationHeight);
|
|
702
|
+
const personMaskTexture = createTexture(gl, gl.RGBA8, frameWidth, frameHeight);
|
|
703
|
+
const resizingStage = buildResizingStage(gl, vertexShader, positionBuffer, texCoordBuffer, tflite, segmentationConfig);
|
|
704
|
+
const loadSegmentationStage = buildSoftmaxStage(gl, vertexShader, positionBuffer, texCoordBuffer, tflite, segmentationTexture, segmentationConfig);
|
|
705
|
+
const jointBilateralFilterStage = buildJointBilateralFilterStage(gl, vertexShader, positionBuffer, texCoordBuffer, segmentationTexture, personMaskTexture, canvas, segmentationConfig);
|
|
706
|
+
const backgroundStage = backgroundFilter === 'blur'
|
|
707
|
+
? buildBackgroundBlurStage(gl, vertexShader, positionBuffer, texCoordBuffer, personMaskTexture, canvas, blurLevel || 'high')
|
|
708
|
+
: buildBackgroundImageStage(gl, positionBuffer, texCoordBuffer, personMaskTexture, backgroundImage, canvas);
|
|
709
|
+
function render() {
|
|
710
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
711
|
+
gl.bindTexture(gl.TEXTURE_2D, inputFrameTexture);
|
|
712
|
+
// texImage2D seems faster than texSubImage2D to upload
|
|
713
|
+
// video texture
|
|
714
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, videoSource);
|
|
715
|
+
gl.bindVertexArray(vertexArray);
|
|
716
|
+
resizingStage.render();
|
|
717
|
+
tflite._runInference();
|
|
718
|
+
loadSegmentationStage.render();
|
|
719
|
+
jointBilateralFilterStage.render();
|
|
720
|
+
backgroundStage.render();
|
|
721
|
+
}
|
|
722
|
+
function updatePostProcessingConfig() {
|
|
723
|
+
jointBilateralFilterStage.updateSigmaSpace(1);
|
|
724
|
+
jointBilateralFilterStage.updateSigmaColor(0.1);
|
|
725
|
+
if (backgroundFilter === 'image') {
|
|
726
|
+
const backgroundImageStage = backgroundStage;
|
|
727
|
+
backgroundImageStage.updateCoverage([0.5, 0.75]);
|
|
728
|
+
backgroundImageStage.updateLightWrapping(0.3);
|
|
729
|
+
backgroundImageStage.updateBlendMode('screen');
|
|
730
|
+
}
|
|
731
|
+
else if (backgroundFilter === 'blur') {
|
|
732
|
+
const backgroundBlurStage = backgroundStage;
|
|
733
|
+
backgroundBlurStage.updateCoverage([0.5, 0.75]);
|
|
734
|
+
}
|
|
735
|
+
else {
|
|
736
|
+
// TODO Handle no background in a separate pipeline path
|
|
737
|
+
const backgroundImageStage = backgroundStage;
|
|
738
|
+
backgroundImageStage.updateCoverage([0, 0.9999]);
|
|
739
|
+
backgroundImageStage.updateLightWrapping(0);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
function cleanUp() {
|
|
743
|
+
backgroundStage.cleanUp();
|
|
744
|
+
jointBilateralFilterStage.cleanUp();
|
|
745
|
+
loadSegmentationStage.cleanUp();
|
|
746
|
+
resizingStage.cleanUp();
|
|
747
|
+
gl.deleteTexture(personMaskTexture);
|
|
748
|
+
gl.deleteTexture(segmentationTexture);
|
|
749
|
+
gl.deleteTexture(inputFrameTexture);
|
|
750
|
+
gl.deleteBuffer(texCoordBuffer);
|
|
751
|
+
gl.deleteBuffer(positionBuffer);
|
|
752
|
+
gl.deleteVertexArray(vertexArray);
|
|
753
|
+
gl.deleteShader(vertexShader);
|
|
754
|
+
}
|
|
755
|
+
return { render, updatePostProcessingConfig, cleanUp };
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
var SegmentationLevel;
|
|
759
|
+
(function (SegmentationLevel) {
|
|
760
|
+
SegmentationLevel["LOW"] = "low";
|
|
761
|
+
SegmentationLevel["HIGH"] = "high";
|
|
762
|
+
})(SegmentationLevel || (SegmentationLevel = {}));
|
|
763
|
+
const getSegmentationParams = (level) => {
|
|
764
|
+
if (level === SegmentationLevel.HIGH) {
|
|
765
|
+
return { width: 256, height: 144 };
|
|
766
|
+
}
|
|
767
|
+
return { width: 160, height: 96 };
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
function createRenderer(tflite, videoSource, targetCanvas, options) {
|
|
771
|
+
const { backgroundFilter, backgroundImage, backgroundBlurLevel, segmentationLevel = SegmentationLevel.HIGH, fps = 30, } = options;
|
|
772
|
+
if (backgroundFilter === 'image' && !backgroundImage) {
|
|
773
|
+
throw new Error(`backgroundImage element is required when backgroundFilter is image`);
|
|
774
|
+
}
|
|
775
|
+
const pipeline = buildWebGL2Pipeline(videoSource, backgroundImage, backgroundBlurLevel, backgroundFilter, targetCanvas, tflite, getSegmentationParams(segmentationLevel));
|
|
776
|
+
const id = setInterval(() => {
|
|
777
|
+
pipeline.render();
|
|
778
|
+
if (backgroundFilter === 'image') {
|
|
779
|
+
pipeline.updatePostProcessingConfig();
|
|
780
|
+
}
|
|
781
|
+
}, 1000 / (fps <= 0 ? 30 : fps));
|
|
782
|
+
return {
|
|
783
|
+
dispose: () => {
|
|
784
|
+
pipeline.cleanUp();
|
|
785
|
+
clearInterval(id);
|
|
786
|
+
},
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
const createTFLiteSIMDModule = (__Module) => {
|
|
791
|
+
__Module = __Module || {};
|
|
792
|
+
|
|
793
|
+
var _scriptDir =
|
|
794
|
+
typeof document !== 'undefined' && document.currentScript
|
|
795
|
+
? document.currentScript.src
|
|
796
|
+
: undefined;
|
|
797
|
+
|
|
798
|
+
var Module = typeof __Module != 'undefined' ? __Module : {};
|
|
799
|
+
var readyPromiseResolve, readyPromiseReject;
|
|
800
|
+
Module['ready'] = new Promise(function (resolve, reject) {
|
|
801
|
+
readyPromiseResolve = resolve;
|
|
802
|
+
readyPromiseReject = reject;
|
|
803
|
+
});
|
|
804
|
+
var moduleOverrides = Object.assign({}, Module);
|
|
805
|
+
var thisProgram = './this.program';
|
|
806
|
+
var quit_ = (status, toThrow) => {
|
|
807
|
+
throw toThrow;
|
|
808
|
+
};
|
|
809
|
+
var ENVIRONMENT_IS_WEB = true;
|
|
810
|
+
var scriptDirectory = '';
|
|
811
|
+
|
|
812
|
+
function locateFile(path) {
|
|
813
|
+
if (Module['locateFile']) {
|
|
814
|
+
return Module['locateFile'](path, scriptDirectory);
|
|
815
|
+
}
|
|
816
|
+
return scriptDirectory + path;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
var readBinary;
|
|
820
|
+
{
|
|
821
|
+
if (typeof document != 'undefined' && document.currentScript) {
|
|
822
|
+
scriptDirectory = document.currentScript.src;
|
|
823
|
+
}
|
|
824
|
+
if (_scriptDir) {
|
|
825
|
+
scriptDirectory = _scriptDir;
|
|
826
|
+
}
|
|
827
|
+
if (scriptDirectory.indexOf('blob:') !== 0) {
|
|
828
|
+
scriptDirectory = scriptDirectory.substr(
|
|
829
|
+
0,
|
|
830
|
+
scriptDirectory.replace(/[?#].*/, '').lastIndexOf('/') + 1,
|
|
831
|
+
);
|
|
832
|
+
} else {
|
|
833
|
+
scriptDirectory = '';
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
var out = Module['print'] || console.log.bind(console);
|
|
837
|
+
var err = Module['printErr'] || console.warn.bind(console);
|
|
838
|
+
Object.assign(Module, moduleOverrides);
|
|
839
|
+
moduleOverrides = null;
|
|
840
|
+
if (Module['arguments']) Module['arguments'];
|
|
841
|
+
if (Module['thisProgram']) thisProgram = Module['thisProgram'];
|
|
842
|
+
if (Module['quit']) quit_ = Module['quit'];
|
|
843
|
+
var wasmBinary;
|
|
844
|
+
if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
|
|
845
|
+
var noExitRuntime = Module['noExitRuntime'] || true;
|
|
846
|
+
if (typeof WebAssembly != 'object') {
|
|
847
|
+
abort('no native wasm support detected');
|
|
848
|
+
}
|
|
849
|
+
var wasmMemory;
|
|
850
|
+
var ABORT = false;
|
|
851
|
+
|
|
852
|
+
var UTF8Decoder =
|
|
853
|
+
typeof TextDecoder != 'undefined' ? new TextDecoder('utf8') : undefined;
|
|
854
|
+
|
|
855
|
+
function UTF8ArrayToString(heapOrArray, idx, maxBytesToRead) {
|
|
856
|
+
var endIdx = idx + maxBytesToRead;
|
|
857
|
+
var endPtr = idx;
|
|
858
|
+
while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
|
|
859
|
+
if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
|
|
860
|
+
return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
|
|
861
|
+
}
|
|
862
|
+
var str = '';
|
|
863
|
+
while (idx < endPtr) {
|
|
864
|
+
var u0 = heapOrArray[idx++];
|
|
865
|
+
if (!(u0 & 128)) {
|
|
866
|
+
str += String.fromCharCode(u0);
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
var u1 = heapOrArray[idx++] & 63;
|
|
870
|
+
if ((u0 & 224) == 192) {
|
|
871
|
+
str += String.fromCharCode(((u0 & 31) << 6) | u1);
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
874
|
+
var u2 = heapOrArray[idx++] & 63;
|
|
875
|
+
if ((u0 & 240) == 224) {
|
|
876
|
+
u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
|
|
877
|
+
} else {
|
|
878
|
+
u0 =
|
|
879
|
+
((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);
|
|
880
|
+
}
|
|
881
|
+
if (u0 < 65536) {
|
|
882
|
+
str += String.fromCharCode(u0);
|
|
883
|
+
} else {
|
|
884
|
+
var ch = u0 - 65536;
|
|
885
|
+
str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023));
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
return str;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
var buffer, HEAP8, HEAPU8, HEAPU32;
|
|
892
|
+
|
|
893
|
+
function updateGlobalBufferAndViews(buf) {
|
|
894
|
+
buffer = buf;
|
|
895
|
+
Module['HEAP8'] = HEAP8 = new Int8Array(buf);
|
|
896
|
+
Module['HEAP16'] = new Int16Array(buf);
|
|
897
|
+
Module['HEAP32'] = new Int32Array(buf);
|
|
898
|
+
Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf);
|
|
899
|
+
Module['HEAPU16'] = new Uint16Array(buf);
|
|
900
|
+
Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf);
|
|
901
|
+
Module['HEAPF32'] = new Float32Array(buf);
|
|
902
|
+
Module['HEAPF64'] = new Float64Array(buf);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
Module['INITIAL_MEMORY'] || 16777216;
|
|
906
|
+
var __ATPRERUN__ = [];
|
|
907
|
+
var __ATINIT__ = [];
|
|
908
|
+
var __ATPOSTRUN__ = [];
|
|
909
|
+
|
|
910
|
+
function keepRuntimeAlive() {
|
|
911
|
+
return noExitRuntime;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
function preRun() {
|
|
915
|
+
if (Module['preRun']) {
|
|
916
|
+
if (typeof Module['preRun'] == 'function')
|
|
917
|
+
Module['preRun'] = [Module['preRun']];
|
|
918
|
+
while (Module['preRun'].length) {
|
|
919
|
+
addOnPreRun(Module['preRun'].shift());
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
callRuntimeCallbacks(__ATPRERUN__);
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
function initRuntime() {
|
|
926
|
+
callRuntimeCallbacks(__ATINIT__);
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
function postRun() {
|
|
930
|
+
if (Module['postRun']) {
|
|
931
|
+
if (typeof Module['postRun'] == 'function')
|
|
932
|
+
Module['postRun'] = [Module['postRun']];
|
|
933
|
+
while (Module['postRun'].length) {
|
|
934
|
+
addOnPostRun(Module['postRun'].shift());
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
callRuntimeCallbacks(__ATPOSTRUN__);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
function addOnPreRun(cb) {
|
|
941
|
+
__ATPRERUN__.unshift(cb);
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
function addOnInit(cb) {
|
|
945
|
+
__ATINIT__.unshift(cb);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
function addOnPostRun(cb) {
|
|
949
|
+
__ATPOSTRUN__.unshift(cb);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
var runDependencies = 0;
|
|
953
|
+
var dependenciesFulfilled = null;
|
|
954
|
+
|
|
955
|
+
function addRunDependency(id) {
|
|
956
|
+
runDependencies++;
|
|
957
|
+
if (Module['monitorRunDependencies']) {
|
|
958
|
+
Module['monitorRunDependencies'](runDependencies);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
function removeRunDependency(id) {
|
|
963
|
+
runDependencies--;
|
|
964
|
+
if (Module['monitorRunDependencies']) {
|
|
965
|
+
Module['monitorRunDependencies'](runDependencies);
|
|
966
|
+
}
|
|
967
|
+
if (runDependencies == 0) {
|
|
968
|
+
if (dependenciesFulfilled) {
|
|
969
|
+
var callback = dependenciesFulfilled;
|
|
970
|
+
dependenciesFulfilled = null;
|
|
971
|
+
callback();
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
function abort(what) {
|
|
977
|
+
{
|
|
978
|
+
if (Module['onAbort']) {
|
|
979
|
+
Module['onAbort'](what);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
what = 'Aborted(' + what + ')';
|
|
983
|
+
err(what);
|
|
984
|
+
ABORT = true;
|
|
985
|
+
what += '. Build with -sASSERTIONS for more info.';
|
|
986
|
+
var e = new WebAssembly.RuntimeError(what);
|
|
987
|
+
readyPromiseReject(e);
|
|
988
|
+
throw e;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
var dataURIPrefix = 'data:application/octet-stream;base64,';
|
|
992
|
+
|
|
993
|
+
function isDataURI(filename) {
|
|
994
|
+
return filename.startsWith(dataURIPrefix);
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
var wasmBinaryFile;
|
|
998
|
+
wasmBinaryFile = 'tflite-simd.wasm';
|
|
999
|
+
if (!isDataURI(wasmBinaryFile)) {
|
|
1000
|
+
wasmBinaryFile = locateFile(wasmBinaryFile);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
function getBinary(file) {
|
|
1004
|
+
try {
|
|
1005
|
+
if (file == wasmBinaryFile && wasmBinary) {
|
|
1006
|
+
return new Uint8Array(wasmBinary);
|
|
1007
|
+
}
|
|
1008
|
+
if (readBinary) ;
|
|
1009
|
+
throw 'both async and sync fetching of the wasm failed';
|
|
1010
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
1011
|
+
} catch (err) {
|
|
1012
|
+
abort(err);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
function getBinaryPromise() {
|
|
1017
|
+
if (!wasmBinary && (ENVIRONMENT_IS_WEB )) {
|
|
1018
|
+
if (typeof fetch == 'function') {
|
|
1019
|
+
return fetch(wasmBinaryFile, { credentials: 'same-origin' })
|
|
1020
|
+
.then(function (response) {
|
|
1021
|
+
if (!response['ok']) {
|
|
1022
|
+
throw (
|
|
1023
|
+
"failed to load wasm binary file at '" + wasmBinaryFile + "'"
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
return response['arrayBuffer']();
|
|
1027
|
+
})
|
|
1028
|
+
.catch(function () {
|
|
1029
|
+
return getBinary(wasmBinaryFile);
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
return Promise.resolve().then(function () {
|
|
1034
|
+
return getBinary(wasmBinaryFile);
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
function createWasm() {
|
|
1039
|
+
var info = {
|
|
1040
|
+
env: asmLibraryArg,
|
|
1041
|
+
wasi_snapshot_preview1: asmLibraryArg,
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
function receiveInstance(instance, module) {
|
|
1045
|
+
var exports = instance.exports;
|
|
1046
|
+
Module['asm'] = exports;
|
|
1047
|
+
wasmMemory = Module['asm']['memory'];
|
|
1048
|
+
updateGlobalBufferAndViews(wasmMemory.buffer);
|
|
1049
|
+
Module['asm']['__indirect_function_table'];
|
|
1050
|
+
addOnInit(Module['asm']['__wasm_call_ctors']);
|
|
1051
|
+
removeRunDependency();
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
addRunDependency();
|
|
1055
|
+
|
|
1056
|
+
function receiveInstantiationResult(result) {
|
|
1057
|
+
receiveInstance(result['instance']);
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
function instantiateArrayBuffer(receiver) {
|
|
1061
|
+
return getBinaryPromise()
|
|
1062
|
+
.then(function (binary) {
|
|
1063
|
+
return WebAssembly.instantiate(binary, info);
|
|
1064
|
+
})
|
|
1065
|
+
.then(function (instance) {
|
|
1066
|
+
return instance;
|
|
1067
|
+
})
|
|
1068
|
+
.then(receiver, function (reason) {
|
|
1069
|
+
err('failed to asynchronously prepare wasm: ' + reason);
|
|
1070
|
+
abort(reason);
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
function instantiateAsync() {
|
|
1075
|
+
if (
|
|
1076
|
+
!wasmBinary &&
|
|
1077
|
+
typeof WebAssembly.instantiateStreaming == 'function' &&
|
|
1078
|
+
!isDataURI(wasmBinaryFile) &&
|
|
1079
|
+
typeof fetch == 'function'
|
|
1080
|
+
) {
|
|
1081
|
+
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(
|
|
1082
|
+
function (response) {
|
|
1083
|
+
var result = WebAssembly.instantiateStreaming(response, info);
|
|
1084
|
+
return result.then(receiveInstantiationResult, function (reason) {
|
|
1085
|
+
err('wasm streaming compile failed: ' + reason);
|
|
1086
|
+
err('falling back to ArrayBuffer instantiation');
|
|
1087
|
+
return instantiateArrayBuffer(receiveInstantiationResult);
|
|
1088
|
+
});
|
|
1089
|
+
},
|
|
1090
|
+
);
|
|
1091
|
+
} else {
|
|
1092
|
+
return instantiateArrayBuffer(receiveInstantiationResult);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
if (Module['instantiateWasm']) {
|
|
1097
|
+
try {
|
|
1098
|
+
var exports = Module['instantiateWasm'](info, receiveInstance);
|
|
1099
|
+
return exports;
|
|
1100
|
+
} catch (e) {
|
|
1101
|
+
err('Module.instantiateWasm callback failed with error: ' + e);
|
|
1102
|
+
readyPromiseReject(e);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
instantiateAsync().catch(readyPromiseReject);
|
|
1106
|
+
return {};
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
function ExitStatus(status) {
|
|
1110
|
+
this.name = 'ExitStatus';
|
|
1111
|
+
this.message = 'Program terminated with exit(' + status + ')';
|
|
1112
|
+
this.status = status;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
function callRuntimeCallbacks(callbacks) {
|
|
1116
|
+
while (callbacks.length > 0) {
|
|
1117
|
+
callbacks.shift()(Module);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
function __dlinit(main_dso_handle) {}
|
|
1122
|
+
|
|
1123
|
+
var dlopenMissingError =
|
|
1124
|
+
'To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking';
|
|
1125
|
+
|
|
1126
|
+
function __dlopen_js(filename, flag) {
|
|
1127
|
+
abort(dlopenMissingError);
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
function __dlsym_js(handle, symbol) {
|
|
1131
|
+
abort(dlopenMissingError);
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
var nowIsMonotonic = true;
|
|
1135
|
+
|
|
1136
|
+
function __emscripten_get_now_is_monotonic() {
|
|
1137
|
+
return nowIsMonotonic;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
function __mmap_js(len, prot, flags, fd, off, allocated) {
|
|
1141
|
+
return -52;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
function __munmap_js(addr, len, prot, flags, fd, offset) {}
|
|
1145
|
+
|
|
1146
|
+
function _abort() {
|
|
1147
|
+
abort('');
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
function _emscripten_date_now() {
|
|
1151
|
+
return Date.now();
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
function getHeapMax() {
|
|
1155
|
+
return 2147483648;
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
function _emscripten_get_heap_max() {
|
|
1159
|
+
return getHeapMax();
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
var _emscripten_get_now;
|
|
1163
|
+
_emscripten_get_now = () => performance.now();
|
|
1164
|
+
|
|
1165
|
+
function _emscripten_memcpy_big(dest, src, num) {
|
|
1166
|
+
HEAPU8.copyWithin(dest, src, src + num);
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
function emscripten_realloc_buffer(size) {
|
|
1170
|
+
try {
|
|
1171
|
+
wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16);
|
|
1172
|
+
updateGlobalBufferAndViews(wasmMemory.buffer);
|
|
1173
|
+
return 1;
|
|
1174
|
+
} catch (e) {}
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
function _emscripten_resize_heap(requestedSize) {
|
|
1178
|
+
var oldSize = HEAPU8.length;
|
|
1179
|
+
requestedSize = requestedSize >>> 0;
|
|
1180
|
+
var maxHeapSize = getHeapMax();
|
|
1181
|
+
if (requestedSize > maxHeapSize) {
|
|
1182
|
+
return false;
|
|
1183
|
+
}
|
|
1184
|
+
let alignUp = (x, multiple) => x + ((multiple - (x % multiple)) % multiple);
|
|
1185
|
+
for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
|
|
1186
|
+
var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown);
|
|
1187
|
+
overGrownHeapSize = Math.min(
|
|
1188
|
+
overGrownHeapSize,
|
|
1189
|
+
requestedSize + 100663296,
|
|
1190
|
+
);
|
|
1191
|
+
var newSize = Math.min(
|
|
1192
|
+
maxHeapSize,
|
|
1193
|
+
alignUp(Math.max(requestedSize, overGrownHeapSize), 65536),
|
|
1194
|
+
);
|
|
1195
|
+
var replacement = emscripten_realloc_buffer(newSize);
|
|
1196
|
+
if (replacement) {
|
|
1197
|
+
return true;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
return false;
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
var ENV = {};
|
|
1204
|
+
|
|
1205
|
+
function getExecutableName() {
|
|
1206
|
+
return thisProgram || './this.program';
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
function getEnvStrings() {
|
|
1210
|
+
if (!getEnvStrings.strings) {
|
|
1211
|
+
var lang =
|
|
1212
|
+
(
|
|
1213
|
+
(typeof navigator == 'object' &&
|
|
1214
|
+
navigator.languages &&
|
|
1215
|
+
navigator.languages[0]) ||
|
|
1216
|
+
'C'
|
|
1217
|
+
).replace('-', '_') + '.UTF-8';
|
|
1218
|
+
var env = {
|
|
1219
|
+
USER: 'web_user',
|
|
1220
|
+
LOGNAME: 'web_user',
|
|
1221
|
+
PATH: '/',
|
|
1222
|
+
PWD: '/',
|
|
1223
|
+
HOME: '/home/web_user',
|
|
1224
|
+
LANG: lang,
|
|
1225
|
+
_: getExecutableName(),
|
|
1226
|
+
};
|
|
1227
|
+
for (var x in ENV) {
|
|
1228
|
+
if (ENV[x] === undefined) delete env[x];
|
|
1229
|
+
else env[x] = ENV[x];
|
|
1230
|
+
}
|
|
1231
|
+
var strings = [];
|
|
1232
|
+
for (var x in env) {
|
|
1233
|
+
strings.push(x + '=' + env[x]);
|
|
1234
|
+
}
|
|
1235
|
+
getEnvStrings.strings = strings;
|
|
1236
|
+
}
|
|
1237
|
+
return getEnvStrings.strings;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
1241
|
+
function writeAsciiToMemory(str, buffer, dontAddNull) {
|
|
1242
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1243
|
+
HEAP8[buffer++ >> 0] = str.charCodeAt(i);
|
|
1244
|
+
}
|
|
1245
|
+
if (!dontAddNull) HEAP8[buffer >> 0] = 0;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
function _environ_get(__environ, environ_buf) {
|
|
1249
|
+
var bufSize = 0;
|
|
1250
|
+
getEnvStrings().forEach(function (string, i) {
|
|
1251
|
+
var ptr = environ_buf + bufSize;
|
|
1252
|
+
HEAPU32[(__environ + i * 4) >> 2] = ptr;
|
|
1253
|
+
writeAsciiToMemory(string, ptr);
|
|
1254
|
+
bufSize += string.length + 1;
|
|
1255
|
+
});
|
|
1256
|
+
return 0;
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
function _environ_sizes_get(penviron_count, penviron_buf_size) {
|
|
1260
|
+
var strings = getEnvStrings();
|
|
1261
|
+
HEAPU32[penviron_count >> 2] = strings.length;
|
|
1262
|
+
var bufSize = 0;
|
|
1263
|
+
strings.forEach(function (string) {
|
|
1264
|
+
bufSize += string.length + 1;
|
|
1265
|
+
});
|
|
1266
|
+
HEAPU32[penviron_buf_size >> 2] = bufSize;
|
|
1267
|
+
return 0;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
function _proc_exit(code) {
|
|
1271
|
+
if (!keepRuntimeAlive()) {
|
|
1272
|
+
if (Module['onExit']) Module['onExit'](code);
|
|
1273
|
+
ABORT = true;
|
|
1274
|
+
}
|
|
1275
|
+
quit_(code, new ExitStatus(code));
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
function exitJS(status, implicit) {
|
|
1279
|
+
_proc_exit(status);
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
var _exit = exitJS;
|
|
1283
|
+
|
|
1284
|
+
function _fd_close(fd) {
|
|
1285
|
+
return 52;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
function _fd_seek(fd, offset_low, offset_high, whence, newOffset) {
|
|
1289
|
+
return 70;
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
var printCharBuffers = [null, [], []];
|
|
1293
|
+
|
|
1294
|
+
function printChar(stream, curr) {
|
|
1295
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
1296
|
+
var buffer = printCharBuffers[stream];
|
|
1297
|
+
if (curr === 0 || curr === 10) {
|
|
1298
|
+
(stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0));
|
|
1299
|
+
buffer.length = 0;
|
|
1300
|
+
} else {
|
|
1301
|
+
buffer.push(curr);
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
function _fd_write(fd, iov, iovcnt, pnum) {
|
|
1306
|
+
var num = 0;
|
|
1307
|
+
for (var i = 0; i < iovcnt; i++) {
|
|
1308
|
+
var ptr = HEAPU32[iov >> 2];
|
|
1309
|
+
var len = HEAPU32[(iov + 4) >> 2];
|
|
1310
|
+
iov += 8;
|
|
1311
|
+
for (var j = 0; j < len; j++) {
|
|
1312
|
+
printChar(fd, HEAPU8[ptr + j]);
|
|
1313
|
+
}
|
|
1314
|
+
num += len;
|
|
1315
|
+
}
|
|
1316
|
+
HEAPU32[pnum >> 2] = num;
|
|
1317
|
+
return 0;
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
function getRandomDevice() {
|
|
1321
|
+
if (
|
|
1322
|
+
typeof crypto == 'object' &&
|
|
1323
|
+
typeof crypto['getRandomValues'] == 'function'
|
|
1324
|
+
) {
|
|
1325
|
+
var randomBuffer = new Uint8Array(1);
|
|
1326
|
+
return () => {
|
|
1327
|
+
crypto.getRandomValues(randomBuffer);
|
|
1328
|
+
return randomBuffer[0];
|
|
1329
|
+
};
|
|
1330
|
+
} else return () => abort('randomDevice');
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
1334
|
+
function _getentropy(buffer, size) {
|
|
1335
|
+
if (!_getentropy.randomDevice) {
|
|
1336
|
+
_getentropy.randomDevice = getRandomDevice();
|
|
1337
|
+
}
|
|
1338
|
+
for (var i = 0; i < size; i++) {
|
|
1339
|
+
HEAP8[(buffer + i) >> 0] = _getentropy.randomDevice();
|
|
1340
|
+
}
|
|
1341
|
+
return 0;
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
var asmLibraryArg = {
|
|
1345
|
+
_dlinit: __dlinit,
|
|
1346
|
+
_dlopen_js: __dlopen_js,
|
|
1347
|
+
_dlsym_js: __dlsym_js,
|
|
1348
|
+
_emscripten_get_now_is_monotonic: __emscripten_get_now_is_monotonic,
|
|
1349
|
+
_mmap_js: __mmap_js,
|
|
1350
|
+
_munmap_js: __munmap_js,
|
|
1351
|
+
abort: _abort,
|
|
1352
|
+
emscripten_date_now: _emscripten_date_now,
|
|
1353
|
+
emscripten_get_heap_max: _emscripten_get_heap_max,
|
|
1354
|
+
emscripten_get_now: _emscripten_get_now,
|
|
1355
|
+
emscripten_memcpy_big: _emscripten_memcpy_big,
|
|
1356
|
+
emscripten_resize_heap: _emscripten_resize_heap,
|
|
1357
|
+
environ_get: _environ_get,
|
|
1358
|
+
environ_sizes_get: _environ_sizes_get,
|
|
1359
|
+
exit: _exit,
|
|
1360
|
+
fd_close: _fd_close,
|
|
1361
|
+
fd_seek: _fd_seek,
|
|
1362
|
+
fd_write: _fd_write,
|
|
1363
|
+
getentropy: _getentropy,
|
|
1364
|
+
};
|
|
1365
|
+
createWasm();
|
|
1366
|
+
(Module['___wasm_call_ctors'] = function () {
|
|
1367
|
+
return (Module['___wasm_call_ctors'] =
|
|
1368
|
+
Module['asm']['__wasm_call_ctors']).apply(null, arguments);
|
|
1369
|
+
});
|
|
1370
|
+
(Module['_getModelBufferMemoryOffset'] =
|
|
1371
|
+
function () {
|
|
1372
|
+
return (Module[
|
|
1373
|
+
'_getModelBufferMemoryOffset'
|
|
1374
|
+
] =
|
|
1375
|
+
Module['asm']['getModelBufferMemoryOffset']).apply(null, arguments);
|
|
1376
|
+
});
|
|
1377
|
+
(Module['_getInputMemoryOffset'] = function () {
|
|
1378
|
+
return (Module['_getInputMemoryOffset'] =
|
|
1379
|
+
Module['asm']['getInputMemoryOffset']).apply(null, arguments);
|
|
1380
|
+
});
|
|
1381
|
+
(Module['_getInputHeight'] = function () {
|
|
1382
|
+
return (Module['_getInputHeight'] =
|
|
1383
|
+
Module['asm']['getInputHeight']).apply(null, arguments);
|
|
1384
|
+
});
|
|
1385
|
+
(Module['_getInputWidth'] = function () {
|
|
1386
|
+
return (Module['_getInputWidth'] =
|
|
1387
|
+
Module['asm']['getInputWidth']).apply(null, arguments);
|
|
1388
|
+
});
|
|
1389
|
+
(Module['_getInputChannelCount'] = function () {
|
|
1390
|
+
return (Module['_getInputChannelCount'] =
|
|
1391
|
+
Module['asm']['getInputChannelCount']).apply(null, arguments);
|
|
1392
|
+
});
|
|
1393
|
+
(Module['_getOutputMemoryOffset'] = function () {
|
|
1394
|
+
return (Module['_getOutputMemoryOffset'] =
|
|
1395
|
+
Module['asm']['getOutputMemoryOffset']).apply(null, arguments);
|
|
1396
|
+
});
|
|
1397
|
+
(Module['_getOutputHeight'] = function () {
|
|
1398
|
+
return (Module['_getOutputHeight'] =
|
|
1399
|
+
Module['asm']['getOutputHeight']).apply(null, arguments);
|
|
1400
|
+
});
|
|
1401
|
+
(Module['_getOutputWidth'] = function () {
|
|
1402
|
+
return (Module['_getOutputWidth'] =
|
|
1403
|
+
Module['asm']['getOutputWidth']).apply(null, arguments);
|
|
1404
|
+
});
|
|
1405
|
+
(Module['_getOutputChannelCount'] = function () {
|
|
1406
|
+
return (Module['_getOutputChannelCount'] =
|
|
1407
|
+
Module['asm']['getOutputChannelCount']).apply(null, arguments);
|
|
1408
|
+
});
|
|
1409
|
+
(Module['_loadModel'] = function () {
|
|
1410
|
+
return (Module['_loadModel'] =
|
|
1411
|
+
Module['asm']['loadModel']).apply(null, arguments);
|
|
1412
|
+
});
|
|
1413
|
+
(Module['_runInference'] = function () {
|
|
1414
|
+
return (Module['_runInference'] =
|
|
1415
|
+
Module['asm']['runInference']).apply(null, arguments);
|
|
1416
|
+
});
|
|
1417
|
+
(Module['_malloc'] = function () {
|
|
1418
|
+
return (Module['_malloc'] = Module['asm']['malloc']).apply(
|
|
1419
|
+
null,
|
|
1420
|
+
arguments,
|
|
1421
|
+
);
|
|
1422
|
+
});
|
|
1423
|
+
(Module['___errno_location'] = function () {
|
|
1424
|
+
return (Module['___errno_location'] =
|
|
1425
|
+
Module['asm']['__errno_location']).apply(null, arguments);
|
|
1426
|
+
});
|
|
1427
|
+
(Module['___dl_seterr'] = function () {
|
|
1428
|
+
return (Module['___dl_seterr'] =
|
|
1429
|
+
Module['asm']['__dl_seterr']).apply(null, arguments);
|
|
1430
|
+
});
|
|
1431
|
+
(Module['stackSave'] = function () {
|
|
1432
|
+
return (Module['stackSave'] = Module['asm']['stackSave']).apply(
|
|
1433
|
+
null,
|
|
1434
|
+
arguments,
|
|
1435
|
+
);
|
|
1436
|
+
});
|
|
1437
|
+
(Module['stackRestore'] = function () {
|
|
1438
|
+
return (Module['stackRestore'] =
|
|
1439
|
+
Module['asm']['stackRestore']).apply(null, arguments);
|
|
1440
|
+
});
|
|
1441
|
+
(Module['stackAlloc'] = function () {
|
|
1442
|
+
return (Module['stackAlloc'] =
|
|
1443
|
+
Module['asm']['stackAlloc']).apply(null, arguments);
|
|
1444
|
+
});
|
|
1445
|
+
(Module['dynCall_jjj'] = function () {
|
|
1446
|
+
return (Module['dynCall_jjj'] =
|
|
1447
|
+
Module['asm']['dynCall_jjj']).apply(null, arguments);
|
|
1448
|
+
});
|
|
1449
|
+
(Module['dynCall_jiii'] = function () {
|
|
1450
|
+
return (Module['dynCall_jiii'] =
|
|
1451
|
+
Module['asm']['dynCall_jiii']).apply(null, arguments);
|
|
1452
|
+
});
|
|
1453
|
+
(Module['dynCall_iiiijj'] = function () {
|
|
1454
|
+
return (Module['dynCall_iiiijj'] =
|
|
1455
|
+
Module['asm']['dynCall_iiiijj']).apply(null, arguments);
|
|
1456
|
+
});
|
|
1457
|
+
(Module['dynCall_viijj'] = function () {
|
|
1458
|
+
return (Module['dynCall_viijj'] =
|
|
1459
|
+
Module['asm']['dynCall_viijj']).apply(null, arguments);
|
|
1460
|
+
});
|
|
1461
|
+
(Module['dynCall_viiijjj'] = function () {
|
|
1462
|
+
return (Module['dynCall_viiijjj'] =
|
|
1463
|
+
Module['asm']['dynCall_viiijjj']).apply(null, arguments);
|
|
1464
|
+
});
|
|
1465
|
+
(Module['dynCall_iijjiiii'] = function () {
|
|
1466
|
+
return (Module['dynCall_iijjiiii'] =
|
|
1467
|
+
Module['asm']['dynCall_iijjiiii']).apply(null, arguments);
|
|
1468
|
+
});
|
|
1469
|
+
(Module['dynCall_jiji'] = function () {
|
|
1470
|
+
return (Module['dynCall_jiji'] =
|
|
1471
|
+
Module['asm']['dynCall_jiji']).apply(null, arguments);
|
|
1472
|
+
});
|
|
1473
|
+
var calledRun;
|
|
1474
|
+
dependenciesFulfilled = function runCaller() {
|
|
1475
|
+
if (!calledRun) run();
|
|
1476
|
+
if (!calledRun) dependenciesFulfilled = runCaller;
|
|
1477
|
+
};
|
|
1478
|
+
|
|
1479
|
+
function run(args) {
|
|
1480
|
+
if (runDependencies > 0) {
|
|
1481
|
+
return;
|
|
1482
|
+
}
|
|
1483
|
+
preRun();
|
|
1484
|
+
if (runDependencies > 0) {
|
|
1485
|
+
return;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
function doRun() {
|
|
1489
|
+
if (calledRun) return;
|
|
1490
|
+
calledRun = true;
|
|
1491
|
+
Module['calledRun'] = true;
|
|
1492
|
+
if (ABORT) return;
|
|
1493
|
+
initRuntime();
|
|
1494
|
+
readyPromiseResolve(Module);
|
|
1495
|
+
if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']();
|
|
1496
|
+
postRun();
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
if (Module['setStatus']) {
|
|
1500
|
+
Module['setStatus']('Running...');
|
|
1501
|
+
setTimeout(function () {
|
|
1502
|
+
setTimeout(function () {
|
|
1503
|
+
Module['setStatus']('');
|
|
1504
|
+
}, 1);
|
|
1505
|
+
doRun();
|
|
1506
|
+
}, 1);
|
|
1507
|
+
} else {
|
|
1508
|
+
doRun();
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
if (Module['preInit']) {
|
|
1513
|
+
if (typeof Module['preInit'] == 'function')
|
|
1514
|
+
Module['preInit'] = [Module['preInit']];
|
|
1515
|
+
while (Module['preInit'].length > 0) {
|
|
1516
|
+
Module['preInit'].pop()();
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
run();
|
|
1520
|
+
|
|
1521
|
+
return __Module.ready;
|
|
1522
|
+
};
|
|
1523
|
+
|
|
1524
|
+
const version = "0.1.0" ;
|
|
1525
|
+
const packageName = "@stream-io/video-filters-web" ;
|
|
1526
|
+
|
|
1527
|
+
// @ts-expect-error - module is not declared
|
|
1528
|
+
// This is a WebAssembly module compiled from the TensorFlow Lite C++ library.
|
|
1529
|
+
const createTFLite = createTFLiteSIMDModule;
|
|
1530
|
+
const loadTFLite = async (options = {}) => {
|
|
1531
|
+
const { basePath = `https://unpkg.com/${packageName}@${version}/tf`, tfFilePath = `${basePath}/tflite/tflite-simd.wasm`, modelFilePath = `${basePath}/models/segm_full_v679.tflite`, } = options;
|
|
1532
|
+
const [tfLite, model] = await Promise.all([
|
|
1533
|
+
createTFLite({ locateFile: () => tfFilePath }),
|
|
1534
|
+
fetchModel(modelFilePath),
|
|
1535
|
+
]);
|
|
1536
|
+
const modelBufferOffset = tfLite._getModelBufferMemoryOffset();
|
|
1537
|
+
tfLite.HEAPU8.set(new Uint8Array(model), modelBufferOffset);
|
|
1538
|
+
tfLite._loadModel(model.byteLength);
|
|
1539
|
+
return tfLite;
|
|
1540
|
+
};
|
|
1541
|
+
let lastModelFilePath = '';
|
|
1542
|
+
let modelFileCache;
|
|
1543
|
+
const fetchModel = async (modelFilePath) => {
|
|
1544
|
+
const model = modelFilePath === lastModelFilePath && modelFileCache
|
|
1545
|
+
? modelFileCache
|
|
1546
|
+
: await fetch(modelFilePath).then((r) => r.arrayBuffer());
|
|
1547
|
+
// Cache the model file for future use.
|
|
1548
|
+
modelFileCache = model;
|
|
1549
|
+
lastModelFilePath = modelFilePath;
|
|
1550
|
+
return model;
|
|
1551
|
+
};
|
|
1552
|
+
|
|
1553
|
+
export { SegmentationLevel, createRenderer, isPlatformSupported, loadTFLite };
|
|
1554
|
+
//# sourceMappingURL=index.es.js.map
|