Skip to content

Commit 79de247

Browse files
committed
update
1 parent ea96805 commit 79de247

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed
Binary file not shown.
Binary file not shown.

013demo_super-resolution-worker-js-demo/src/App.tsx

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ const App = () => {
6262
const [modelKey, setModelKey] = useState(Object.keys(models)[0])
6363
const [interpolationTypeKey, setInterpolationTypeKey] = useState(Object.keys(interpolationTypes)[0])
6464
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)
6767
const [onLocal, setOnLocal] = useState(true)
6868

6969
const [inputMedia, setInputMedia] = useState<InputMedia>({ mediaType: "IMAGE", media: "img/yuka_kawamura.jpg" })
@@ -154,6 +154,7 @@ const App = () => {
154154
//////////////
155155
const setLayout = () => {
156156
const outputElem = document.getElementById("output") as HTMLCanvasElement
157+
const outputCanvasElem = document.getElementById("output-canvas") as HTMLCanvasElement
157158
const scaleFactor = scaleFactors[modelKey]
158159
if (inputMedia.mediaType === "IMAGE") {
159160
const inputElem = document.getElementById("input_img") as HTMLImageElement
@@ -162,6 +163,8 @@ const App = () => {
162163
inputElem.height = inputElem.naturalHeight * ratio
163164
outputElem.width = inputElem.width * scaleFactor
164165
outputElem.height = inputElem.height * scaleFactor
166+
outputCanvasElem .width = inputElem.width * scaleFactor
167+
outputCanvasElem .height = inputElem.height * scaleFactor
165168

166169
} else {
167170
const inputElem = document.getElementById("input_video") as HTMLVideoElement
@@ -170,6 +173,8 @@ const App = () => {
170173
inputElem.height = inputElem.videoHeight * ratio
171174
outputElem.width = inputElem.width * scaleFactor
172175
outputElem.height = inputElem.height * scaleFactor
176+
outputCanvasElem .width = inputElem.width * scaleFactor
177+
outputCanvasElem .height = inputElem.height * scaleFactor
173178
}
174179
}
175180
//////////////////
@@ -183,8 +188,10 @@ const App = () => {
183188

184189
const src = document.getElementById("input_img") as HTMLImageElement || document.getElementById("input_video") as HTMLVideoElement
185190
const dst = document.getElementById("output") as HTMLCanvasElement
191+
const dstCanvas = document.getElementById("output-canvas") as HTMLCanvasElement
186192
const tmp = document.getElementById("tmp") as HTMLCanvasElement
187193
const dstCtx = dst.getContext("2d")!
194+
const dstCanvasCtx = dstCanvas.getContext("2d")!
188195
const tmpCtx = tmp.getContext("2d")!
189196

190197
setLayout()
@@ -212,8 +219,10 @@ const App = () => {
212219
workerProps.params.inputHeight = src.height
213220
const prediction = await workerProps.manager.predict(tmp!, workerProps.params)
214221
const inference_end = performance.now()
222+
215223
const info = document.getElementById("info") as HTMLCanvasElement
216224
info.innerText = `processing time: ${inference_end - inference_start}`
225+
217226
if (!prediction) {
218227
if (GlobalLoopID === LOOP_ID) {
219228
renderRequestId = requestAnimationFrame(render)
@@ -226,6 +235,7 @@ const App = () => {
226235
}catch(exception){
227236
console.log(exception)
228237
}
238+
dstCanvasCtx.drawImage(tmp, 0, 0, dst.width, dst.height)
229239
}
230240

231241
if (GlobalLoopID === LOOP_ID) {
@@ -258,7 +268,7 @@ const App = () => {
258268
<DropDown title="type" current={interpolationTypeKey} onchange={setInterpolationTypeKey} options={interpolationTypes} />
259269

260270
<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} />
262272
<Toggle title="SIMD" current={useSIMD} onchange={setUseSIMD} />
263273
<Toggle title="TensorflowJS" current={useTensorflowJS} onchange={setUseTensorflowJS} />
264274

@@ -267,12 +277,42 @@ const App = () => {
267277
</div>
268278
</div>
269279
<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+
276316
</div>
277317
</div>
278318

0 commit comments

Comments
 (0)