uniapp app人脸识别功能怎么实现

发布时间:2022-05-12 15:31:47 作者:iii
来源:亿速云 阅读:1795

这篇文章主要介绍“uniapp app人脸识别功能怎么实现”,在日常操作中,相信很多人在uniapp app人脸识别功能怎么实现问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”uniapp app人脸识别功能怎么实现”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

由于 小程序端 有camera组件 直接就可以调起摄像头 但是 app端是不支持这个标签的 所以只能用其他的方法 使用 nvue 中 live-pusher 组件

子组件 

<template>
	<div>
		<div class="livefater">
			<div >
				<!-- orientation="horizontal" //设置垂直水平方向 -->
				<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/gai1.png" class="gaiimg"></cover-image>
		</div>
		<view class="message" >
			<text class="info">{{message}}</text>
		</view>
	</div>
</template>
 
<script>
	export default {
		props: {
			time: {
				default: 5000,
				type: Number
			},
			message: {
				default: '识别中,请稍后...',
				type: String
			}
		},
		data() {
			return {}
		},
		mounted() {
 
			// 注意:需要在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  
				}
			})
			setTimeout(() => {
				this.startPreview()
			})
		},
		methods: {
			// 拍照事件
			snapshot: function() {
				var that = this
				this.context.snapshot({
					success: (e) => {
						console.log(e.message, '拍照信息');
						this.$emit('faceImg', e.message)
					}
				});
			},
			// 开启摄像头
			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()
						}, that.time)
					},
					fail(err) {
						console.log(err);
					}
				});
			},
		},
	}
</script>
 
<style>
	<style lang="less">page {
		background: #0c8cf9;
	}
 
	.u-navbar__content__left {
		display: flex !important;
		align-items: center;
	}
 
	.u_nav_slot {
		display: flex;
		align-items: center;
		flex-direction: row;
		color: rgba(0, 0, 0, 0.9);
		font-size: 14.4rpx;
		font-weight: 700;
 
	}
 
	.text {
		margin-left: 1rpx;
		color: #fff;
		font-size: 16rpx;
	}
 
	.box {
		z-index: 99;
		position: absolute;
		left: 35%;
		top: 25%;
		width: 250rpx;
		height: 250rpx;
		background: pink;
	}
 
	.message {
		flex: 1;
		justify-content: center;
		align-items: center;
		font-weight: 700;
	}
 
	.info {
		color: #fff !important;
		font-size: 20rpx;
	}
 
	.livePusher {
		width: 300px;
		height: 300px;
	}
 
	.livefater {
		display: -ms-flex;
		display: -webkit-flex;
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;
		margin-top: 10rpx;
		margin-bottom: 50rpx;
		height: 350px;
	}
 
	.gaiimg {
		width: 300px;
		height: 300px;
		margin-top: -300px;
	}
</style>
</style>

由于 人脸一般是 原型 样式 但是默认的live-pusher 是正方形 而且层级是比较高的 其他普通元素标签是无法压住他的  但是 cover-imgae的图片是可以压上去的 

父组件

<TestingFace :time="5000" @faceImg="faceImg" :message="message"></TestingFace>

faceImg 就是子组件传过来的 图片 message 是传过去的内容  time是倒计时的拍照时间,具体内容可以根据内容去加逻辑   注意 子父组件都是 nvue

uniapp app人脸识别功能怎么实现

到此,关于“uniapp app人脸识别功能怎么实现”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. 基于vue+uniapp直播项目实现uni-app仿抖音/陌陌直播室功能
  2. python调用OpenCV实现人脸识别功能

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

uniapp app

上一篇:php7.3新特性有哪些

下一篇:php中如何把数组转为字符串

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》