小编cag*_*glu的帖子

使用 React Native 和 Tensorflow.js 对实时视频源进行预测

我已经设置了我的 React Native 应用程序,所有 unimodules 和包的安装和配置都按预期工作。没有依赖性等问题。

现在我想实现一个我从谷歌的可教机器上训练的张量流模型,但我无法理解如何将它与相机一起使用,因为我想实时处理帧,就像张量流反应本机API文档所说的那样。这是我在网上找到的代码,我将用我的模型更改它,但问题是它仅在用户拍照时检测模型。我希望我的相机能够实时理解模型,就像人脸检测、条形码扫描仪一样。

Main.js

import React, {useRef, useEffect, useState} from 'react';
import {View, StyleSheet, Dimensions} from 'react-native';

import {
  getModel,
  convertBase64ToTensor,
  startPrediction,
} from '../../helpers/tensor-helper';

import {Camera} from 'expo-camera';

import * as tf from '@tensorflow/tfjs';
import '@tensorflow/tfjs-react-native';
import {
  cameraWithTensors,
  bundleResourceIO,
} from '@tensorflow/tfjs-react-native';

const TensorCamera = cameraWithTensors(Camera);

const Main = () => {
  const [model, setModel] = useState();
  const [prediction, setPredictions] = useState();
  const cameraRef = useRef(null);

  let requestAnimationFrameId = 0;
  let frameCount = 0; …
Run Code Online (Sandbox Code Playgroud)

react-native tensorflow tensorflow.js

4
推荐指数
1
解决办法
3278
查看次数

标签 统计

react-native ×1

tensorflow ×1

tensorflow.js ×1