MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / handleCameraStream

Function handleCameraStream

react-native/pose-detection/App.tsx:125–159  ·  view source on GitHub ↗
(
    images: IterableIterator<tf.Tensor3D>,
    updatePreview: () => void,
    gl: ExpoWebGLRenderingContext
  )

Source from the content-addressed store, hash-verified

123 }, []);
124
125 const handleCameraStream = async (
126 images: IterableIterator<tf.Tensor3D>,
127 updatePreview: () => void,
128 gl: ExpoWebGLRenderingContext
129 ) => {
130 const loop = async () => {
131 // Get the tensor and run pose detection.
132 const imageTensor = images.next().value as tf.Tensor3D;
133
134 const startTs = Date.now();
135 const poses = await model!.estimatePoses(
136 imageTensor,
137 undefined,
138 Date.now()
139 );
140 const latency = Date.now() - startTs;
141 setFps(Math.floor(1000 / latency));
142 setPoses(poses);
143 tf.dispose([imageTensor]);
144
145 if (rafId.current === 0) {
146 return;
147 }
148
149 // Render camera preview manually when autorender=false.
150 if (!AUTO_RENDER) {
151 updatePreview();
152 gl.endFrameEXP();
153 }
154
155 rafId.current = requestAnimationFrame(loop);
156 };
157
158 loop();
159 };
160
161 const renderPose = () => {
162 if (poses != null && poses.length > 0) {

Callers

nothing calls this directly

Calls 1

loopFunction · 0.85

Tested by

no test coverage detected