uni-app 人脸识别分析及实现(前端) + nvue开发源码

uni-app 人脸识别分析及实现(前端) + nvue开发源码1 app 开发一个人脸识别 实现刷脸功能首先要考虑的是实现流程 1 打开摄像头 自动读取照片 传输给后端 后端交由第三发或自主开发来识别 返回结果 相识度比 2 打开摄像头 自动读取视频 传输给后端 后端通过解析视频 截取图片交由第三发或自主开发来识别 返回结果 相识度比 那么通过分析 我们只需要做两步骤 打开摄像头和自动读取视频或照片 2 打开摄像头分步骤分析 打开摄像头 并展示视频效果在 html 上 目前有两种方式 2 1 使用 camera 组件进行 借用 createCa

1、前言和思路

那么通过分析,我们只需要做两步骤:打开摄像头和自动读取视频或照片

2、打开摄像头

分步骤分析:打开摄像头,并展示视频效果在html上,目前有两种方式:

2.1、使用camera组件进行,借用.createCameraContext()对象来打开摄像头

2.2、通过livePusher对象(直播推流技术)实现视频预览和截屏

在这里插入图片描述

下面我主要是以nvue进行开发,毕竟组件简单明了是吧,然后就遇到了很多坑…

3、使用nvue来开发人脸识别

3.1、效果图

在这里插入图片描述

3.2、代码

话不多说,直接上代码

html部分

<template> <view> <div class="custom" :style="{height: CustomBar+'px'}"> <view class="navcontent" :style="[{top:statusBar + 'px'}]"> <text style="color: #FFFFFF;font-size: 16px;line-height: 45px;" class="iconfont icon-xiangzuo" @click="BackPage">返回 
     text> <text style="color: #FFFFFF;font-size: 16px;line-height: 45px;">人脸识别 
      text> <text> 
       text>  
        view>  
         div> <div class="livefater"> <div style="width: 350px;height: 350px;border-radius: 350px;overflow: hidden;background-color: #CCCCCC;"> <live-pusher id='livePusher' ref="livePusher" class="livePusher" url="" mode="SD" :muted="true" :enable-camera="true" :auto-focus="true" :beauty="1" whiteness="2" aspect="1:1" @statechange="statechange" @netstatus="netstatus" @error = "error" > 
          live-pusher>  
           div> <cover-image src="../static/image/gai.png" class="gaiimg"> 
            cover-image>  
             div> <button class="btn" @click="startPreview">打开摄像头进行人脸识别 
              button>  
               view>  
                template> 

js部分

 export default { 
    data: { 
    fil: true, imgList:[""], statusBar:'', CustomBar: 0 }, onLoad(){ 
    // this.startPreview() }, onReady() { 
    // 注意:需要在onReady中 或 onLoad 延时 this.context = uni.createLivePusherContext("livePusher", this); var that = this uni.getSystemInfo({ 
    success:function(e){ 
    // 计算导航栏高度 that.statusBar = e.statusBarHeight // #ifndef MP  if(e.platform == 'android') { 
    that.CustomBar = e.statusBarHeight + 50 }else { 
    that.CustomBar = e.statusBarHeight + 45 } console.log(that.statusBar) // #endif  // #ifdef MP-WEIXIN  let custom = wx.getMenuButtonBoundingClientRect() that.CustomBar = custom.bottom + custom.top - e.statusBarHeight // #endif  // #ifdef MP-ALIPAY  that.CustomBar = e.statusBarHeight + e.titleBarHeight // #endif  } }) }, methods: { 
    Timer(){ 
   }, statechange(e) { 
    console.log("statechange:" + JSON.stringify(e)); }, netstatus(e) { 
    console.log("netstatus:" + JSON.stringify(e)); }, error(e) { 
    console.log("error:" + JSON.stringify(e)); }, start: function() { 
    this.context.start({ 
    success: (a) => { 
    console.log("livePusher.start:" + JSON.stringify(a)); } }); }, close: function() { 
    this.context.close({ 
    success: (a) => { 
    console.log("livePusher.close:" + JSON.stringify(a)); } }); }, // 拍照事件 snapshot: function() { 
    var that = this this.context.snapshot({ 
    success: (e) => { 
    console.log(JSON.stringify(e)); that.getMinImage(e.message.tempImagePath) } }); }, // 开启摄像头 startPreview() { 
    console.log("1") var that = this this.context.startPreview({ 
    success: (a) => { 
    console.log("livePusher.startPreview:" + JSON.stringify(a)); that.Timer = setInterval(function(){ 
    that.snapshot() if(that.imgList.length>3){ 
    console.log("3") clearInterval(that.Timer) } },2000) } }); }, // 使用plus.zip.compressImage压缩图片并转换成base64 getMinImage(imgPath) { 
    plus.zip.compressImage( { 
    src: imgPath, dst: imgPath, overwrite: true, quality: 40 }, zipRes => { 
    setTimeout(() => { 
    var reader = new plus.io.FileReader(); reader.onloadend = res => { 
    var speech = res.target.result; //base64图片 console.log(speech); this.imgList.push(speech); }; //一定要使用plus.io.convertLocalFileSystemURL将target地址转换为本地文件地址,否则readAsDataURL会找不到文件 reader.readAsDataURL(plus.io.convertLocalFileSystemURL(zipRes.target)); }, 1000); }, function(error) { 
    console.log('Compress error!', error); } ); }, BackPage() { 
    uni.navigateBack({ 
    delta: 1 }); } } } 

css部分

.custom{ 
    background-color: #2C65F7; } .navcontent{ 
    height: 45px; display: -ms-flex; display: -webkit-flex; display: flex; justify-content:space-around; flex-direction:row; color:#FFFFFF; } .livePusher{ 
    width: 350px; height: 350px; } .livefater{ 
    display: -ms-flex; display: -webkit-flex; display: flex; justify-content:center; flex-direction:column; align-items:center; margin-top: 50rpx; margin-bottom: 50rpx; height: 350px; } .gaiimg{ 
    width: 350px; height: 350px; margin-top: -350px; } 

4、使用微信小程序开发人脸识别

分两种,一种自主开发,一种借用第三方插件

4.1、自主开发

4.2、E证通

无需证书小程序接入人脸识别—E证通


5 nvue的背景图片

在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/205667.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月19日 下午5:29
下一篇 2026年3月19日 下午5:29


相关推荐

  • 递归数列求极限的方法证明_归纳法证明数列极限

    递归数列求极限的方法证明_归纳法证明数列极限高等数学是理工科考研都需要考的科目之一,不管是数一、数二、数三都是考纲中的内容。而极限又是高数中的基础,是微分学的基础。所以,我们一定要打好基础,才能在考试中拿到高分。冷月总结了递归数列极限的求法和证明,希望能够帮助到各位小伙伴。本文为李正元数一全书为参考。

    2025年10月31日
    3
  • 腾讯元宝AI助手解析[代码]

    腾讯元宝AI助手解析[代码]

    2026年3月13日
    2
  • 自定义控件知识储备-LayoutParams的那些事

    自定义控件知识储备-LayoutParams的那些事后来呀 我遇到了 LayoutParams 它说 layout width 是它的属性而非 View 的 并且不只是针对这一个 而是所有以 layout 开头的属性都与它有关 所以 它的东西当然要打上自己的标识 layout 呵呵 嚣张个啥 到头来你自己还不是属于 View 的一部分

    2026年3月18日
    2
  • SFM原理简介「建议收藏」

    SFM原理简介「建议收藏」StructureFromMotionSFM简介通过相机的移动来确定目标的空间和几何关系,是三维重建的一种常见方法。它与Kinect这种3D摄像头最大的不同在于,它只需要普通的RGB摄像头即可,因此成本更低廉,且受环境约束较小,在室内和室外均能使用。SFM基本原理小孔相机模型在计算机视觉中,最常用的相机模型就是小孔成像模型,它将相机的透镜组简化为一个小孔…

    2022年6月20日
    32
  • 互联网金融风控模型

    互联网金融风控模型一、市场调研目前市面主流的风控模型1、互联网金融前10名排行榜(数据截止日期2017-09-12)互联网金融公司排名分别是蚂蚁金服、陆金所、京东金融、苏宁金融、百度金融、腾讯理财通、宜信、钱大掌柜、万达金融和网易理财。1.1蚂蚁金服1.1.1大数据技术对接第三方征信公司芝麻信用分,通过用户信用历史、行为偏好、履约能力、身份特质、人脉关系五个维度对…

    2022年6月14日
    25
  • Ubuntu更新命令

    Ubuntu更新命令apt cachesearchp 搜索包 apt cacheshowpac 获取包的相关信息 如说明 大小 版本等 sudoapt getinstallpa 安装包 sudoapt getinstallpa 重新安装包 sudoapt get finstall 修复安装 f

    2026年3月17日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号