Skip to content

使用方法

注意

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

组件使用

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

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

页面示例代码

vue
<template>
  <view>
    <uni-card title="安卓百度人脸识别UTS原生插件-金融活检模式人脸识别">
      <view style="flex:1; height: 500px; position: relative;">
        <leven-uts-baiduFace-Finance ref="refLevenFinance" style="flex:1; height: 500px;" :config="config" @onOverTime="onOverTime"
          @onResultFail="onResultFail" @onResultSuccess="onResultSuccess" @onError="onError" @onInit="onInit">
        </leven-uts-baiduFace-Finance>
        <!-- 组件内部自定义内容 -->
        <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>
      <view>
        <button type="primary" @click="checkRecognitionStatus">当前是否可进行人脸识别</button>
        <button type="primary" @click="openRecognition">开启人脸识别</button>
        <button type="primary" @click="closeRecognition">关闭人脸识别</button>
      </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,
          //识别框下方默认文本,默认:请保持面部在取景框内
          defaultText: "请保持面部在取景框内",
          //识别成功后是否显示识别文本内容,默认:true
          isShowSuccessText: true,
          //识别成功后识别文本返回默认文本的延迟时间,单位:秒,默认:3
          successTextToDefaultTime: 5,
          //摄像头旋转角度,默认:0,可传入0、90、180、270四个选项
          videoDirection: 90,
          //人脸检测角度,默认:0,可传入0、90、180、270四个选项。
          rgbDetectDirection: 90,
          //是否开启最优人脸检测,默认:false
          usingBestImage: false,
          //识别成功后是否可以继续识别,默认:false
          successContinue: false,
          //RGB预览Y轴转向falese为0,true为180
          rgbRevert: false,
          //摄像头显示位置,-1:usb,0.后置,1.前置,默认:1
          rbgCameraId: 1,
          //是否开启openGL渲染,默认:false
          isOpenGl: false
        },
        //当前识别的人脸图片
        imageBase64: ""
      }
    },
    methods: {
      //关闭人脸识别
      closeRecognition() {
        if (this.$refs.refLevenFinance) {
          this.$refs.refLevenFinance.closeRecognition(res => {
            this.writeLog(JSON.stringify(res))
          })
        }
      },
      //开启人脸识别
      openRecognition() {
        if (this.$refs.refLevenFinance) {
          this.imageBase64 = "";
          this.$refs.refLevenFinance.openRecognition(res => {
            this.writeLog(JSON.stringify(res))
          })
        }
      },
      //当前是否可进行人脸识别状态
      checkRecognitionStatus() {
        if (this.$refs.refLevenFinance) {
          this.$refs.refLevenFinance.checkRecognitionStatus(res => {
            this.writeLog(JSON.stringify(res))
          })
        }
      },
      //错误事件
      onError(e) {
        this.writeLog(JSON.stringify(e))
      },
      //初始化事件
      onInit(e) {
        this.writeLog(JSON.stringify(e))
      },
      //识别成功
      onResultSuccess(e) {
        console.log("识别成功")
        let detail = e.detail;
        if (detail.recognitionImageBase64) {
          this.imageBase64 = "data:image/jpeg;base64," + detail.recognitionImageBase64
        }
        // this.writeLog(JSON.stringify(e))
      },
      //识别失败
      onResultFail(e) {
        this.writeLog(JSON.stringify(e))
      },
      //识别超时
      onOverTime(e) {
        this.writeLog(JSON.stringify(e))
      },
      // 写日志
      writeLog(str) {
        console.log(str)
        let logStr = uni.$lv.date.format(null, "yyyy-mm-dd hh:MM:ss") + " " + str + "\n";
        // let logStr = str + "\n";
        this.logStr = logStr + this.logStr;
      }
    }
  }
</script>

<style>

</style>