带有 Expo Camera 的 TensorFlow.js 不处理 React Native 中的帧

问题描述 投票:0回答:1

我有以下React Native App.js 文件,我试图在其中打印收到的

nextImageTensor
,但流程不会进入loop() 内部。事实上,循环甚至没有被调用

应用程序.js

import * as React from "react";
import { Text, View, StyleSheet, Image, Platform } from "react-native";
import { Camera } from "expo-camera/legacy";
import { cameraWithTensors } from "@tensorflow/tfjs-react-native";
import * as tf from "@tensorflow/tfjs";

const TensorCamera = cameraWithTensors(Camera);

export default class MyComponent extends React.Component {
  constructor(props) {
    super(props);
    this.handleCameraStream = this.handleCameraStream.bind(this);
  }

  handleCameraStream(images) {
    const loop = async () => {
      const nextImageTensor = await images.next().value;
      console.log("Hreee:", nextImageTensor);
      requestAnimationFrame(loop);
    };
    loop();
  }

  render() {
    return (
      <View>
        <TensorCamera
          ref={(ref) => {
            this.camera = ref;
          }}
          type={Camera.Constants.Type.front}
          cameraTextureHeight={500}
          cameraTextureWidth={500}
          resizeHeight={64}
          resizeWidth={64}
          resizeDepth={3}
          onReady={this.handleCameraStream}
          style={{ width: "100%", height: "100%" }}
          autorender={true}
        />
      </View>
    );
  }
}

package.json 包含以下依赖项

{
    "@mediapipe/face_detection": "^0.4.1646425229",
    "@react-native-async-storage/async-storage": "1.23.1",
    "@react-navigation/native": "^6.1.18",
    "@react-navigation/stack": "^6.4.1",
    "@tensorflow-models/face-detection": "^1.0.2",
    "@tensorflow-models/handpose": "^0.1.0",
    "@tensorflow-models/mobilenet": "^2.1.0",
    "@tensorflow/tfjs": "^3.10.0",
    "@tensorflow/tfjs-backend-wasm": "^4.20.0",
    "@tensorflow/tfjs-react-native": "^1.0.0",
    "expo": "^51.0.24",
    "expo-av": "~14.0.6",
    "expo-camera": "~15.0.14",
    "expo-gl": "~14.0.2",
    "expo-module-scripts": "^3.5.2",
    "expo-status-bar": "~1.12.1",
    "expo-updates": "~0.25.21",
    "fingerpose": "^0.1.0",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.74.3",
    "react-native-fs": "^2.16.6",
    "react-native-gesture-handler": "~2.16.1",
    "react-native-linear-gradient": "^2.8.3",
    "react-native-safe-area-context": "4.10.5",
    "react-native-screens": "3.31.1",
    "react-native-web": "~0.19.6",
    "react-native-webview": "13.8.6",
  }
  • 世博SDK:51.0.24
  • 世博相机:14.0.15
  • Tfjs:3.10.0
  • Tfjs-react-native:1.0.0
react-native expo tensorflow.js expo-camera
1个回答
0
投票

您找到解决方案了吗?我面临着同样的问题。如果我将自动渲染设置为true,则handleCameraStream函数可以正常工作,但相机图像不刷新...

© www.soinside.com 2019 - 2024. All rights reserved.