Skip to content

使用方法

注意

组件只能在nvue页面中使用,不支持vue页面

组件使用

在需要使用插件的页面加载以下代码

vue
<leven-uts-baiduFace-GateFace ref="refLevenGateFace" style="flex:1; height: 500px;" :config="config" @onResultFail="onResultFail"
  @onResultSuccess="onResultSuccess" @onError="onError" @onInit="onInit">
</leven-uts-baiduFace-GateFace>

页面示例代码

vue
<template>
  <view>
    <uni-card title="安卓百度人脸识别UTS原生插件-闸机模式人脸识别">
      <view style="flex:1; height: 500px; position: relative;">
        <leven-uts-baiduFace-GateFace ref="refLevenGateFace" style="flex:1; height: 500px;" :config="config" @onResultFail="onResultFail"
          @onResultSuccess="onResultSuccess" @onError="onError" @onInit="onInit">
        </leven-uts-baiduFace-GateFace>
        <!-- 组件内部自定义内容 -->
        <cover-view v-if="imageBase64" style="position: absolute; right: 0; bottom: 0;">
          <image :src="imageBase64" style="width: 170px; height: 170px;" mode="scaleToFill"></image>
        </cover-view>
      </view>
    </uni-card>
    <uni-card class="uni-card-box" title="日志">
      <view><text style="font-size: 14px; flex-wrap: wrap;">{{logStr}}</text></view>
    </uni-card>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        //日志
        logStr: "",
        //组件配置
        config: {
          //默认为80px。可传入大于30px的数值,小于此大小的人脸不予检测
          minFaceSize: 50,
          //人脸置信度用于表征被检测到的物体是人脸的概率,该阈值设置越高检测越严格,建议在0.3-0.8区间内调整阈值,默认:0.5
          faceThreshold: 0.5,
          //是否开启属性检测,默认:false
          attribute: false,
          //是否设置质量检测,默认:true
          qualityControl: false,
          //质量检测参数设置,qualityControl为true时有效
          qualityConfig: {
            // 模糊度设置,默认0.8。取值范围[0~1],0是最清晰,1是最模糊
            blur: 0.8,
            // 光照设置,默认0.8.取值范围[0~1], 数值越大,光线越强
            illum: 0.8,
            //姿态阈值,默认:15
            gesture: 15,
            // 左眼被遮挡的阈值,默认0.8
            leftEye: 0.8,
            // 右眼被遮挡的阈值,默认0.8
            rightEye: 0.8,
            // 鼻子被遮挡的阈值,默认0.8
            nose: 0.8,
            // 嘴巴被遮挡的阈值,默认0.8
            mouth: 0.8,
            // 左脸颊被遮挡的阈值,默认0.8
            leftCheek: 0.8,
            // 右脸颊被遮挡的阈值,默认0.8
            rightCheek: 0.8,
            // 下巴被遮挡阈值,默认为0.8
            chinContour: 0.8
          },
          //识别阈值,0-1,默认为0.8
          liveScoreThreshold: 0.6,
          //摄像头旋转角度,默认:0,可传入0、90、180、270四个选项
          videoDirection: 90,
          //人脸检测角度,默认:0,可传入0、90、180、270四个选项。
          rgbDetectDirection: 90,
          //是否开启最优人脸检测,默认:false
          usingBestImage: false,
          //RGB预览Y轴转向falese为0,true为180
          rgbRevert: false,
          //摄像头显示位置,-1:usb,0.后置,1.前置,默认:1
          rbgCameraId: 1,
          //是否开启openGL渲染,默认:false
          isOpenGl: false,
          //识别成功后延迟识别的时间:单位:秒,默认:5
          successContinueTime: 5
        },
        //当前识别的人脸图片
        imageBase64: ""
      }
    },
    methods: {
      //错误事件
      onError(e) {
        this.writeLog(JSON.stringify(e))
      },
      //初始化事件
      onInit(e) {
        this.writeLog(JSON.stringify(e))
      },
      //识别成功
      onResultSuccess(e) {
        let detail = e.detail;
        if (detail.recognitionImageBase64) {
          this.imageBase64 = "data:image/jpeg;base64," + detail.recognitionImageBase64
        }
        //这里不能打印日志,因为base64的原因程序容易挂掉
        // this.writeLog(JSON.stringify(e))
      },
      //识别失败
      onResultFail(e) {
        this.writeLog(JSON.stringify(e))
      },
    }
  }
</script>

<style>

</style>