File tree Expand file tree Collapse file tree 2 files changed +6
-20
lines changed Expand file tree Collapse file tree 2 files changed +6
-20
lines changed Original file line number Diff line number Diff line change 6
6
import * as tf from "@tensorflow/tfjs" ;
7
7
import getTopKClasses from "../utils/gettopkclasses" ;
8
8
import DARKNET_CLASSES from "./DARKNET_CLASSES" ;
9
+ import { isInstanceOfSupportedElement } from "../utils/imageUtilities" ;
9
10
10
11
const DEFAULTS = {
11
12
DARKNET_URL :
@@ -19,19 +20,11 @@ const DEFAULTS = {
19
20
function preProcess ( img , size ) {
20
21
let image ;
21
22
if ( ! ( img instanceof tf . Tensor ) ) {
22
- if (
23
- img instanceof HTMLImageElement ||
24
- img instanceof HTMLVideoElement ||
25
- img instanceof HTMLCanvasElement ||
26
- img instanceof ImageData
27
- ) {
23
+ if ( isInstanceOfSupportedElement ( img ) ) {
28
24
image = tf . browser . fromPixels ( img ) ;
29
25
} else if (
30
26
typeof img === "object" &&
31
- ( img . elt instanceof HTMLImageElement ||
32
- img . elt instanceof HTMLVideoElement ||
33
- img . elt instanceof HTMLCanvasElement ||
34
- img . elt instanceof ImageData )
27
+ isInstanceOfSupportedElement ( img . elt )
35
28
) {
36
29
image = tf . browser . fromPixels ( img . elt ) ; // Handle p5.js image and video.
37
30
}
Original file line number Diff line number Diff line change 6
6
import * as tf from "@tensorflow/tfjs" ;
7
7
import getTopKClasses from "../utils/gettopkclasses" ;
8
8
import DOODLENET_CLASSES from "./DOODLENET_CLASSES" ;
9
+ import { isInstanceOfSupportedElement } from "../utils/imageUtilities" ;
9
10
10
11
const DEFAULTS = {
11
12
DOODLENET_URL :
@@ -16,19 +17,11 @@ const DEFAULTS = {
16
17
function preProcess ( img , size ) {
17
18
let image ;
18
19
if ( ! ( img instanceof tf . Tensor ) ) {
19
- if (
20
- img instanceof HTMLImageElement ||
21
- img instanceof HTMLVideoElement ||
22
- img instanceof HTMLCanvasElement ||
23
- img instanceof ImageData
24
- ) {
20
+ if ( isInstanceOfSupportedElement ( img ) ) {
25
21
image = tf . browser . fromPixels ( img ) ;
26
22
} else if (
27
23
typeof img === "object" &&
28
- ( img . elt instanceof HTMLImageElement ||
29
- img . elt instanceof HTMLVideoElement ||
30
- img . elt instanceof HTMLCanvasElement ||
31
- img . elt instanceof ImageData )
24
+ isInstanceOfSupportedElement ( img . elt )
32
25
) {
33
26
image = tf . browser . fromPixels ( img . elt ) ; // Handle p5.js image, video and canvas.
34
27
}
You can’t perform that action at this time.
0 commit comments