【问题标题】:Expo / RN - Get face landmarksExpo / RN - 获取面部标志
【发布时间】:2019-04-06 15:22:33
【问题描述】:

我有一个基于官方文档中简单示例的工作代码: 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>
      );
    }
  }
}

【问题讨论】:

    标签: javascript node.js react-native expo


    【解决方案1】:

    使用这个

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-24
      • 2015-08-25
      • 1970-01-01
      • 2018-04-17
      • 2019-11-05
      • 2017-06-07
      相关资源
      最近更新 更多