MCPcopy Index your code
hub / github.com/tensorflow/tfjs / handleClickTrigger

Function handleClickTrigger

tfjs-tflite/demo/src/script.ts:89–113  ·  view source on GitHub ↗
(
    trigger: HTMLElement, tfliteModel: tflite.TFLiteModel)

Source from the content-addressed store, hash-verified

87}
88
89function handleClickTrigger(
90 trigger: HTMLElement, tfliteModel: tflite.TFLiteModel) {
91 // Get the source media (either a picture or the cam video).
92 const imageContainer = trigger.closest('.img-container')!;
93 let srcMedia: HTMLImageElement|HTMLVideoElement =
94 imageContainer.querySelector('img')!;
95 if (!srcMedia) {
96 srcMedia = imageContainer.querySelector('video')!;
97 removeClass('.take-pic', 'hide');
98 }
99
100 // Run inference and draw the result on the corresponding canvas.
101 const canvas = imageContainer.querySelector('canvas')!;
102 const ctx = canvas.getContext('2d')!;
103 const inferenceStart = Date.now();
104 const imageData = cartoonize(tfliteModel, srcMedia);
105 const latency = Date.now() - inferenceStart;
106 ctx.putImageData(imageData, 0, 0);
107 canvas.classList.add('show');
108
109 // Show latency stat.
110 const stats = trigger.closest('.img-container')!.querySelector('.stats')!;
111 stats.classList.add('show');
112 stats.innerHTML = latency.toFixed(1) + ' ms';
113}
114
115function cartoonize(
116 tfliteModel: tflite.TFLiteModel,

Callers 1

startFunction · 0.85

Calls 5

removeClassFunction · 0.85
cartoonizeFunction · 0.85
nowMethod · 0.65
addMethod · 0.65
getContextMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…