Skip to content

Commit 7fd5bb9

Browse files
Add support for OffscreenCanvas (#242)
Tensorflow will accept "canvas like" objects, including OffscreenCanvas. https://github.com/tensorflow/tfjs/blob/2644bd0d6cea677f80e44ed4a44bea5e04aabeb3/tfjs-core/src/ops/browser.ts#L98 I tested if this with the ml5 image classifier example and it does work!
1 parent c0fe6b9 commit 7fd5bb9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/utils/handleArguments.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as tf from "@tensorflow/tfjs";
77
/**
88
* Standard input accepted by most TensorFlow models.
99
* @typedef InputImage
10-
* @type {ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | tf.Tensor3D}
10+
* @type {ImageData | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | HTMLVideoElement | tf.Tensor3D}
1111
*/
1212

1313
/**
@@ -40,13 +40,13 @@ export const isAudio = (img) => {
4040
};
4141

4242
/**
43-
* Check if a variable is an HTMLCanvasElement.
43+
* Check if a variable is an HTMLCanvasElement or OffscreenCanvas
4444
* @param {any} img
4545
* @returns {img is HTMLCanvasElement}
4646
*/
4747
export const isCanvas = (img) => {
4848
return (
49-
typeof HTMLCanvasElement !== "undefined" && img instanceof HTMLCanvasElement
49+
typeof HTMLCanvasElement !== "undefined" && (img instanceof HTMLCanvasElement || img instanceof OffscreenCanvas)
5050
);
5151
};
5252

0 commit comments

Comments
 (0)