Javascript 世博会/注册护士-获得面部地标
我有一个基于官方文档中简单示例的工作代码: 和 据说“在检测人脸时,FaceDetector将发射以下形状的对象事件…” 但我不明白我如何才能访问这些对象的值。尝试了所有可能的组合-没有成功。我做错了什么?有人能帮忙吗 当检测到人脸但无法访问数据时,会调用函数“handleFacesDetected” 代码如下:Javascript 世博会/注册护士-获得面部地标,javascript,node.js,react-native,expo,Javascript,Node.js,React Native,Expo,我有一个基于官方文档中简单示例的工作代码: 和 据说“在检测人脸时,FaceDetector将发射以下形状的对象事件…” 但我不明白我如何才能访问这些对象的值。尝试了所有可能的组合-没有成功。我做错了什么?有人能帮忙吗 当检测到人脸但无法访问数据时,会调用函数“handleFacesDetected” 代码如下: import React from 'react'; import { Text, View, TouchableOpacity } from 'react-native'; impo
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>
);
}
}
}
从“React”导入React;
从“react native”导入{Text,View,TouchableOpacity};
从“expo”导入{Camera,Permissions,FaceDetector};
导出默认类CameraExample扩展React.Component{
状态={
hasCameraPermission:null,
类型:Camera.Constants.type.back,
};
异步组件willmount(){
const{status}=wait Permissions.askAsync(Permissions.CAMERA);
this.setState({hasCameraPermission:status=='grated'});
}
handleFacesDetected(){
//它在检测到人脸时到达这里。如何访问数据?
}
render(){
const{hasCameraPermission}=this.state;
if(hasCameraPermission===null){
返回;
}else if(hasCameraPermission===false){
不允许进入摄像机;
}否则{
返回(
{
这是我的国家({
类型:this.state.type==Camera.Constants.type.back
?摄像头.常数.类型.前部
:Camera.Constants.Type.back,
});
}}>
{'}翻转{'}
);
}
}
}
使用此
handleFacesDetected=async({faces})=>{
如果(faces.length==1){
this.setState({face:true});
}
}