gpt4 book ai didi

javascript - Expo/RN - 获取人脸特征点

转载 作者:行者123 更新时间:2023-12-03 00:49:27 26 4
gpt4 key购买 nike

我有一个基于官方文档中的简单示例的工作代码: https://docs.expo.io/versions/latest/sdk/camerahttps://docs.expo.io/versions/latest/sdk/facedetector .

据说“在检测人脸时,FaceDetector 会发出以下形状的对象事件......

但我不明白如何访问这些对象的值。尝试了所有可能的组合 - 没有成功。我做错了什么?有人可以帮忙吗?

当检测到人脸但无法访问数据时,会调用函数“handleFacesDetected”。

这是代码:

import React from 'react';
import { Text, View, TouchableOpacity } from 'react-native';
import { Camera, Permissions, FaceDetector } from 'expo';

export default class CameraExample extends React.Component {
state = {
hasCameraPermission: null,
type: Camera.Constants.Type.back,
};

async componentWillMount() {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
this.setState({ hasCameraPermission: status === 'granted' });
}

handleFacesDetected(){
// it gets here while the face is detected. how to access the data?
}

render() {
const { hasCameraPermission } = this.state;
if (hasCameraPermission === null) {
return <View />;
} else if (hasCameraPermission === false) {
return <Text>No access to camera</Text>;
} else {
return (
<View style={{ flex: 1 }}>
<Camera
style={{ flex: 1 }}
type={this.state.type}
onFacesDetected={this.handleFacesDetected}
faceDetectorSettings={{
mode: FaceDetector.Constants.Mode.accurate,
detectLandmarks: FaceDetector.Constants.Mode.all,
runClassifications: FaceDetector.Constants.Mode.all,
}}
>
<View
style={{
flex: 1,
backgroundColor: 'transparent',
flexDirection: 'row',
}}>
<TouchableOpacity
style={{
flex: 0.1,
alignSelf: 'flex-end',
alignItems: 'center',
}}
onPress={() => {
this.setState({
type: this.state.type === Camera.Constants.Type.back
? Camera.Constants.Type.front
: Camera.Constants.Type.back,
});
}}>
<Text
style={{ fontSize: 18, marginBottom: 10, color: 'white' }}>
{' '}Flip{' '}
</Text>
</TouchableOpacity>
</View>
</Camera>
</View>
);
}
}
}

最佳答案

使用这个

handleFacesDetected  = async ({ faces }) => {
if(faces.length === 1){
this.setState({ face: true });
}
}

关于javascript - Expo/RN - 获取人脸特征点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53117597/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com