How to capture a photo with a Tensorflow Camera in React native? - tfjs

TensorFlow.js version

"@tensorflow/tfjs": "^1.5.2",
"@tensorflow/tfjs-react-native": "^0.2.3",

Browser version

"expo": "^37.0.0",
Platform: Android 10
Device: One Plus 8

Describe the problem or feature request

I have a Tensorflow Camera component where I'm running a model every n frames using the onReady = {this.handleCameraStream} type workflow shown in the tensorflow Camera documentation.

I'd like to save a frame of the camera stream as a JPEG depending on the result of the model. Does anybody know the easiest way to do this?

I've tried using Expo-Camera's takePictureAsync function but found that it stops working when you wrap the camera with the cameraWithTensors

Any help would be appreciated!

Asked Oct 02 '21 18:10
avatar NickRance

4 Answer:

Hi, yes this is an unfortunate limitation, as far as we know, once we grab the camera stream texture from expo it seems to interfere with other expo-camera methods. One approach would be to directly encode the tensor values into a jpeg in JS. To do image decoding we use jpeg-js which does have an encode method as well.

Answered Sep 08 '20 at 20:57
avatar  of tafsiri

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 dyas if no further activity occurs. Thank you.

Answered Oct 01 '20 at 18:34
avatar  of google-ml-butler[bot]

Closing as stale. Please @mention us if this needs more attention.

Answered Oct 08 '20 at 19:01
avatar  of google-ml-butler[bot]

@tafsiri Hi, thanks for addressing this issue, as I was running into as well. I was working to access the live frames as jpg for OCR purposes, but after decode the tensor into a jpg, found the image quality to be dramatically reduced. My partner had created a stack overflow question detailing this:

Answered Feb 25 '21 at 05:49
avatar  of JJwilkin