@@ -62,8 +62,8 @@ const App = () => {
62
62
const [ modelKey , setModelKey ] = useState ( Object . keys ( models ) [ 0 ] )
63
63
const [ interpolationTypeKey , setInterpolationTypeKey ] = useState ( Object . keys ( interpolationTypes ) [ 0 ] )
64
64
const [ useSIMD , setUseSIMD ] = useState ( false )
65
- const [ useTensorflowJS , setUseTensorflowJS ] = useState ( false )
66
- const [ inputSize , setInputSize ] = useState ( 64 )
65
+ const [ useTensorflowJS , setUseTensorflowJS ] = useState ( true )
66
+ const [ inputSize , setInputSize ] = useState ( 240 )
67
67
const [ onLocal , setOnLocal ] = useState ( true )
68
68
69
69
const [ inputMedia , setInputMedia ] = useState < InputMedia > ( { mediaType : "IMAGE" , media : "img/yuka_kawamura.jpg" } )
@@ -154,6 +154,7 @@ const App = () => {
154
154
//////////////
155
155
const setLayout = ( ) => {
156
156
const outputElem = document . getElementById ( "output" ) as HTMLCanvasElement
157
+ const outputCanvasElem = document . getElementById ( "output-canvas" ) as HTMLCanvasElement
157
158
const scaleFactor = scaleFactors [ modelKey ]
158
159
if ( inputMedia . mediaType === "IMAGE" ) {
159
160
const inputElem = document . getElementById ( "input_img" ) as HTMLImageElement
@@ -162,6 +163,8 @@ const App = () => {
162
163
inputElem . height = inputElem . naturalHeight * ratio
163
164
outputElem . width = inputElem . width * scaleFactor
164
165
outputElem . height = inputElem . height * scaleFactor
166
+ outputCanvasElem . width = inputElem . width * scaleFactor
167
+ outputCanvasElem . height = inputElem . height * scaleFactor
165
168
166
169
} else {
167
170
const inputElem = document . getElementById ( "input_video" ) as HTMLVideoElement
@@ -170,6 +173,8 @@ const App = () => {
170
173
inputElem . height = inputElem . videoHeight * ratio
171
174
outputElem . width = inputElem . width * scaleFactor
172
175
outputElem . height = inputElem . height * scaleFactor
176
+ outputCanvasElem . width = inputElem . width * scaleFactor
177
+ outputCanvasElem . height = inputElem . height * scaleFactor
173
178
}
174
179
}
175
180
//////////////////
@@ -183,8 +188,10 @@ const App = () => {
183
188
184
189
const src = document . getElementById ( "input_img" ) as HTMLImageElement || document . getElementById ( "input_video" ) as HTMLVideoElement
185
190
const dst = document . getElementById ( "output" ) as HTMLCanvasElement
191
+ const dstCanvas = document . getElementById ( "output-canvas" ) as HTMLCanvasElement
186
192
const tmp = document . getElementById ( "tmp" ) as HTMLCanvasElement
187
193
const dstCtx = dst . getContext ( "2d" ) !
194
+ const dstCanvasCtx = dstCanvas . getContext ( "2d" ) !
188
195
const tmpCtx = tmp . getContext ( "2d" ) !
189
196
190
197
setLayout ( )
@@ -212,8 +219,10 @@ const App = () => {
212
219
workerProps . params . inputHeight = src . height
213
220
const prediction = await workerProps . manager . predict ( tmp ! , workerProps . params )
214
221
const inference_end = performance . now ( )
222
+
215
223
const info = document . getElementById ( "info" ) as HTMLCanvasElement
216
224
info . innerText = `processing time: ${ inference_end - inference_start } `
225
+
217
226
if ( ! prediction ) {
218
227
if ( GlobalLoopID === LOOP_ID ) {
219
228
renderRequestId = requestAnimationFrame ( render )
@@ -226,6 +235,7 @@ const App = () => {
226
235
} catch ( exception ) {
227
236
console . log ( exception )
228
237
}
238
+ dstCanvasCtx . drawImage ( tmp , 0 , 0 , dst . width , dst . height )
229
239
}
230
240
231
241
if ( GlobalLoopID === LOOP_ID ) {
@@ -258,7 +268,7 @@ const App = () => {
258
268
< DropDown title = "type" current = { interpolationTypeKey } onchange = { setInterpolationTypeKey } options = { interpolationTypes } />
259
269
260
270
< Toggle title = "onLocal" current = { onLocal } onchange = { setOnLocal } />
261
- < SingleValueSlider title = "inputSize(w)" current = { inputSize } onchange = { setInputSize } min = { 64 } max = { 256 } step = { 16 } />
271
+ < SingleValueSlider title = "inputSize(w)" current = { inputSize } onchange = { setInputSize } min = { 96 } max = { 264 } step = { 24 } />
262
272
< Toggle title = "SIMD" current = { useSIMD } onchange = { setUseSIMD } />
263
273
< Toggle title = "TensorflowJS" current = { useTensorflowJS } onchange = { setUseTensorflowJS } />
264
274
@@ -267,12 +277,42 @@ const App = () => {
267
277
</ div >
268
278
</ div >
269
279
< div style = { { display : "flex" , alignItems : "flex-start" } } >
270
- { inputMedia . mediaType === "IMAGE" ?
271
- < img className = { classes . inputView } id = "input_img" alt = "" > </ img >
272
- :
273
- < video className = { classes . inputView } id = "input_video" > </ video >
274
- }
275
- < canvas className = { classes . inputView } id = "output" > </ canvas >
280
+ < div style = { { display :"flex" , flexDirection :"column" } } >
281
+ < div >
282
+ (1) Input image
283
+ </ div >
284
+ < div >
285
+ { inputMedia . mediaType === "IMAGE" ?
286
+ < img className = { classes . inputView } id = "input_img" alt = "" > </ img >
287
+ :
288
+ < video className = { classes . inputView } id = "input_video" > </ video >
289
+ }
290
+ </ div >
291
+ </ div >
292
+
293
+ < div style = { { width :"10px" } } />
294
+
295
+ < div style = { { display :"flex" , flexDirection :"column" } } >
296
+ < div >
297
+ (2) Output image
298
+ </ div >
299
+ < div >
300
+ < canvas className = { classes . inputView } id = "output" > </ canvas >
301
+ </ div >
302
+ </ div >
303
+
304
+ < div style = { { width :"10px" } } />
305
+
306
+ < div style = { { display :"flex" , flexDirection :"column" } } >
307
+ < div >
308
+ (x) drawImage function
309
+ </ div >
310
+ < div >
311
+ < canvas className = { classes . inputView } id = "output-canvas" > </ canvas >
312
+ </ div >
313
+ </ div >
314
+
315
+
276
316
</ div >
277
317
</ div >
278
318
0 commit comments