question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Save tensors from react-native cameraWithTensors api to jpeg

See original GitHub issue

Please make sure that this is a feature request. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:feature_template

System information

Describe the feature and the current behavior/state.

Currently when using the cameraWithTensor HOC one can handle directly the underlying tensor to make e.g. real-time prediction. It would be nice to be able to store the stream of tensors as jpeg or video for instance for later use or visualization.

I have created a repo to showcase my currently unsuccessful attempts: https://github.com/ClementWalter/tfjs-expo-example

Will this change the current api? How?

Who will benefit with this feature?

Any Other info.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ClementWaltercommented, Oct 12, 2020

yes! actually if you go to https://github.com/ClementWalter/tfjs-expo-example/blob/master/utils.js the function does the job. I will try to push it as a contrib to tfjs-react-native very soon. However, as I have said above, I don’t really understand the magic numbers used for width and height in the cameraWithTensor module.

0reactions
0xoricommented, Oct 14, 2020

I’m assuming it depends on the device. you can actually get the device available picture sizes. take a look at expo-camera docs. when I’m changing the dimensions according to the results, I’m getting better capture proportions.

 <TensorCamera
                        // Standard Camera props
                        ref={(ref) => this.camera = ref}
                        style={{ position: 'absolute',
                            left: 0,
                            top: 0,
                            width: 152,
                            height: 200,
                            zIndex: 0,}}
                        type={Camera.Constants.Type.front}
                        // Tensor related props
                        cameraTextureHeight={textureDims.height}
                        cameraTextureWidth={textureDims.width}
                        resizeHeight={200}
                        resizeWidth={152}
                        resizeDepth={3}
                        onReady={this.handleCameraStream}
                        autorender={true}
                    />
 handleCameraStream = async (images, updatePreview, gl)  =>{
      if(this.camera){
          console.log("camera ref")
          const ratios = await this.camera.camera.getSupportedRatiosAsync()
          console.log("ratios", ratios)
          const sizes = await this.camera.camera.getAvailablePictureSizesAsync("4:3");
          console.log("sizes", sizes)
      }

    const loop = async () => {
      let next = images.next();
      const nextImageTensor = next.value

      //
      // do something with tensor here
      //

      // if autorender is false you need the following two lines.
      // updatePreview();
      // gl.endFrameEXP();

    }
    loop();
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

tfjs-react-native from tensor to jpeg - Stack Overflow
How to write a tensor into a local jpeg file then? I have tried to look at the code and "inverse" the function,...
Read more >
tf.io.RequestDetails - TensorFlow.js React Native API
For each model's saved artifacts, three items are saved to async storage. ... Decode a JPEG-encoded image to a 3D Tensor of dtype...
Read more >
Image Classification on React Native with TensorFlow.js and ...
The image is going to be read from a source, so the path to that image source has to be saved in the...
Read more >
Real Time Image Classification with TensorFlow and React ...
It uses the cameraWithTensors high order component from the react-native tensorflow API which converts the simple Camera expo component to a ...
Read more >
how to load large images faster in react native - You.com
How To Load Images Quickly With React Native Faster Image? ... import { cameraWithTensors } from '@tensorflow/tfjs-react-native'; import SoundPlayer from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found