@@ -27,6 +27,15 @@ describe('imageClassifier', () => {
27
27
return img ;
28
28
}
29
29
30
+ async function getCanvas ( ) {
31
+ const img = await getImage ( ) ;
32
+ const canvas = document . createElement ( 'canvas' ) ;
33
+ canvas . width = img . width ;
34
+ canvas . height = img . height ;
35
+ canvas . getContext ( '2d' ) . drawImage ( img , 0 , 0 ) ;
36
+ return canvas ;
37
+ }
38
+
30
39
beforeEach ( async ( ) => {
31
40
jasmine . DEFAULT_TIMEOUT_INTERVAL = 5000 ;
32
41
classifier = await imageClassifier ( 'MobileNet' , undefined , { } ) ;
@@ -45,6 +54,29 @@ describe('imageClassifier', () => {
45
54
await classifier . predict ( img )
46
55
. then ( results => expect ( results [ 0 ] . className ) . toBe ( 'robin, American robin, Turdus migratorius' ) ) ;
47
56
} ) ;
57
+
58
+ it ( 'Should support p5 elements with an image on .elt' , async ( ) => {
59
+ const img = await getImage ( ) ;
60
+ await classifier . predict ( { elt : img } )
61
+ . then ( results => expect ( results [ 0 ] . className ) . toBe ( 'robin, American robin, Turdus migratorius' ) ) ;
62
+ } ) ;
63
+
64
+ it ( 'Should support HTMLCanvasElement' , async ( ) => {
65
+ const canvas = await getCanvas ( ) ;
66
+ await classifier . predict ( canvas )
67
+ . then ( results => expect ( results [ 0 ] . className ) . toBe ( 'robin, American robin, Turdus migratorius' ) ) ;
68
+ } ) ;
69
+
70
+ it ( 'Should support p5 elements with canvas on .canvas' , async ( ) => {
71
+ const canvas = await getCanvas ( ) ;
72
+ await classifier . predict ( { canvas } )
73
+ . then ( results => expect ( results [ 0 ] . className ) . toBe ( 'robin, American robin, Turdus migratorius' ) ) ;
74
+ } ) ;
75
+
76
+ it ( 'Should support p5 elements with canvas on .elt' , async ( ) => {
77
+ const canvas = await getCanvas ( ) ;
78
+ await classifier . predict ( { elt : canvas } )
79
+ . then ( results => expect ( results [ 0 ] . className ) . toBe ( 'robin, American robin, Turdus migratorius' ) ) ;
80
+ } ) ;
48
81
} ) ;
49
82
} ) ;
50
-
0 commit comments