当前位置: 首页 > news >正文

uni-app简单模拟人脸识别

uni-app使用live-pusher简单模拟人脸识别页面样式

    • 实现想法
    • 调起手机摄像头
    • 设置圆形

实现想法

公司的需求是模拟一个人脸识别,不用第三发插件,简单模拟样式即可。
基本思路是调起手机前置摄像头,再设置一个圆形的样式来达到一个基本样式

调起手机摄像头

看了官方的媒体组件,只有camera和live-pusher比较合适
camera不支持App,并且需要触发调用,不合符需求
在这里插入图片描述
所以只剩下live-pusher一个选择
引入组件,并基础设置后

<live-pusher id="pusherId" ref="pusherRef" class="livePusher" aspect="1:1"    // 宽高比例:whiteness="1"  // 美白:beauty="1"     // 美颜/>

我们在页面上可以看见效果
在这里插入图片描述

不过这里需要注意一下,如果你是 nvue 页面,还需要手动调起一下摄像头

onMounted(() => {const instance = getCurrentInstance() as ComponentInternalInstance;const pusherContext = uni.createLivePusherContext("pusherId", instance.ctx)pusherContext.startPreview() 
})

官方文档中写默认摄像头为前置,但此时显示的是后置摄像头,并且设置的默认前置也是不生效的,需要手动翻转一下

onMounted(() => {// 获取当前组件实例const instance = getCurrentInstance() as ComponentInternalInstance;// 获取live-pusher上下文对象const pusherContext = uni.createLivePusherContext("pusherId", instance.ctx)// 翻转摄像头pusherContext.switchCamera()
})

设置圆形

这是一个令人头疼的问题
组件设置宽高为正方形后,设置了圆角属性不生效
尝试了nvue页面在父级元素画圆后设置溢出隐藏,也无济于事
最后添加了cover-img标签,用一张圆形的图片盖住四角达到的效果

  <template><div class="face"><view>拿起手机,眨眨眼</view><div class="pushContent"><live-pusher id="pusherId" ref="pusherRef" class="livePusher" aspect="1:1" :whiteness="1" :beauty="1" device-position="front"/><cover-image class="pusherImg" src="/static/images/faceRadio.png" alt=""></cover-image></div></div></template><script lang="ts" setup>import { onMounted, ref, getCurrentInstance, type ComponentInternalInstance } from 'vue';const pusherRef = ref({} as UniHelper.LivePusherInstance)onMounted(() => {const instance = getCurrentInstance() as ComponentInternalInstance;const pusherContext = uni.createLivePusherContext("pusherId", instance.ctx)pusherContext.switchCamera()// pusherContext.startPreview({}) // nvue 页面吊起摄像头})   </script> <style>page{background-color: #FFF !important;}</style><style lang="scss"  scoped>.face{padding: 46rpx 45rpx;text-align: center;display: flex;justify-content: center;flex-direction: column;align-items: center;.pushContent{position: relative;width: 300rpx;height: 300rpx;border-radius: 250rpx;overflow: hidden;margin: 50rpx auto;.livePusher{width: 300rpx;height: 300rpx;border-radius: 50%;}.pusherImg{position: absolute;top: 0;left: 0;bottom: 0;right: 0;width: 300rpx;height: 300rpx;}}}</style>

看下最终效果,先这样吧。
有别的好的方法,请路过留言,万分感谢!
在这里插入图片描述

http://www.lryc.cn/news/468286.html

相关文章:

  • 华为HCIE-OpenEuler认证详解
  • 从零开始的Go语言之旅(2 Go by Example: Values)
  • XShell 中实现免密登录 Linux 服务器的详细流程
  • 跨界创新|使用自定义YOLOv11和Ollama(Llama 3)增强OCR文本识别
  • 一些关于 WinCC Comfort 和 WinCC Advanced 脚本编程语言 VBS 的实用技巧
  • Java|乐观锁和悲观锁在自旋的时候分别有什么表现?
  • Linux定时器定时任务清理log日志文件
  • 美国大学生数学建模竞赛(MCM/ICM)介绍
  • 【独家:AI编程助手Cursor如何revolutionize Java设计模式学习】
  • 数据仓库宽表概述
  • 在数据库中编程 vs 在应用程序中编程
  • 【设计模式系列】装饰器模式
  • 你真的知道TCP协议中的序列号确认、上层协议及记录标识问题吗?
  • 一家生物技术企业终止,科创属性可能不足,报告期内专利数猛增
  • 使用 Python 的 BeautifulSoup(bs4)解析复杂 HTML
  • Spring Cache Caffeine 高性能缓存库
  • Python3入门--数据类型
  • 开发运维警示录-20241024
  • Linux运维_搭建smb服务
  • vue3移动端可同时上传照片和视频的组件
  • PyQt入门指南二十七 QTableView表格视图组件
  • AI学习指南深度学习篇-自注意力机制(Self-Attention Mechanism)
  • 【JAVA毕业设计】基于Vue和SpringBoot的校园管理系统
  • 你对MySQL的having关键字了解多少?
  • 【STM32编码器】【STM32】
  • Python轴承故障诊断 (13)基于故障信号特征提取的超强机器学习识别模型
  • VScode分文件编写C++报错 | 如何进行VScode分文件编写C++ | 不懂也能轻松解决版
  • 洞察前沿趋势!2024深圳国际金融科技大赛——西丽湖金融科技大学生挑战赛技术公开课指南
  • Unity3D学习FPS游戏(4)重力模拟和角色跳跃
  • C#基础知识-枚举