reactjs - 无法从 React Native 上的 Tensorflow.js Tensorcamera 读取图像
问题描述
我正在尝试在 React Native 上使用 Tensorflow.jsposenet,但我无法获得“图像”。
目前世博相机工作正常,但图像未定义,并且还显示
找不到变量:反应
请告知如何迭代从 TensorCamera 获取图像。
谢谢
import * as React from 'react';
import { Text, View, StyleSheet, Image, Platform } from 'react-native';
import { Camera } from 'expo-camera';
import { cameraWithTensors } from '@tensorflow/tfjs-react-native';
import * as posenet from '@tensorflow-models/posenet';
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);
}
async estimatePoseOnImage(imageElement) {
const net = await posenet.load();
const pose = await net.estimateSinglePose(imageElement, {
flipHorizontal: false,
});
this.setState({ pose: pose });
return pose;
}
handleCameraStream( images ) {
const loop = async () => {
const nextImageTensor = await images.next().value;
await this.estimatePoseOnImage(nextImageTensor);
requestAnimationFrame(loop);
};
loop();
}
render() {
return (
<View>
<TensorCamera
type={Camera.Constants.Type.front}
onReady={this.handleCameraStream}
autorender={true}
/>
</View>
);
}
}
解决方案
<TensorCamera
ref={(ref) => { this.camera = ref }}
type={Camera.Constants.Type.front}
resizeHeight={64}
resizeWidth={64}
resizeDepth={3}
onReady={this.handleCameraStream}
style={{width: width, height: height}}
/>
您必须通过 resizeHeight、resizeWidth、resizeDepth 来获取张量。它对我有用。
推荐阅读
- apache - 将所有 example.com/page 链接解析为 page.html 文件
- mysql - Mysql2::Error: 带有外语 msql 表的未知列
- java - 写入文件时的换行问题
- matlab - 打开窗口错误 - MATLAB 中的 psychtoolbox
- python - 如何在 Python 的子目录中找到文件?
- sql - 来自多个数据集和子报告的 SSRS 求和值
- mysql - 在 mysql 数据库中保存反应图标
- python - 使用 CSS 更改 QDocketWidget 悬停标题栏颜色
- reactjs - 如何从 ReactJS 中的外部函数重定向到路由
- java - Apache POI Excel 图表在 Mac 上消失,但在 Windows/Linux 上没有