国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

使用uniapp開發(fā)微信小程序的人臉采集功能/人臉識別功能

這篇具有很好參考價值的文章主要介紹了使用uniapp開發(fā)微信小程序的人臉采集功能/人臉識別功能。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

使用uniapp開發(fā)微信小程序的人臉采集功能/人臉識別功能

?作者簡介:大家好我是瓜子三百克,勵志成為全棧工程師的一枚程序猿,也是喜歡在學(xué)習(xí)和開發(fā)中記錄筆記的小白博主!
??個人主頁:瓜子三百克的主頁
??系列專欄:uniapp前端
??如果覺得博主的文章還不錯的話,請點贊??+收藏??+留言??支持一下博主哦??

使用uniapp開發(fā)微信小程序的人臉采集功能/人臉識別功能
本篇文章是借助微信小程序平臺,添加人臉采集的功能,你看上面的漂亮姐姐有什么理由不去采集一下她的人臉呢。????

開發(fā)環(huán)境:
開發(fā)框架:uniapp
開發(fā)平臺:微信小程序


標簽和樣式先上:
標簽:

<template>
	<view class="page-content">
		<view class="containerV">

			<view class="headerV">
				<view class="top-tips1">
					<view>請將正對手機,頭部匹配攝像區(qū)域</view>
				</view>
				<view class="top-tips2">
					為了捍衛(wèi)你的不要臉,請拍攝本人頭像
				</view>
			</view>

			<view class="contentV">
				<view class="mark"></view>
				<image v-if="tempImg" mode="widthFix" :src="tempImg" />
				<camera v-if='isAuthCamera' :device-position="devicePosition ?'front': 'back'" class="camera"
					flash="off" resolution='high' />
				<view v-show="!tempImg && tipsText" class="tipV">{{ tipsText }}</view>
			</view>

			<view class="footerV">
				<view style="width: 100%;">
					<view v-if="!tempImg" style="width: 100%;">
						<view class="privacyV">
							<view class="icon"></view>
							<view class="text">
								照片隱私<text @click="handleJumpSecurityClick">安全保障</text>中…
							</view>
						</view>
						<view class="bottom-tips-2">該照片作為你不要臉的鐵證</view>
						<view class="take-photo-bgV">
							<!-- 圖片上傳 -->
							<view v-show="true" class="btn-change-upload" @click="handleChooseImage" />
							<!--拍照-->
							<view class="btn-take-photo" @click="handleTakePhotoClick" />
							<!-- 切換鏡頭 -->
							<view class="btn-change-camera" @click="handleChangeCameraClick" />
						</view>
					</view>
					<view class="confirmV" v-else>
						<view class="btn-cancel" @click="handleCancelClick">
							取消
						</view>
						<view class="btn-ok" @click="handleOkClick">
							確定
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

樣式:

<style lang="scss" scoped>
	.page-content {
		width: 100%;
		height: 100%;

		.containerV {
			width: 100%;
			height: 100%;

			.headerV {
				.top-tips1 {
					margin-top: 60rpx;
					color: #1C1C1C;
					font-size: 36rpx;
					text-align: center;
				}

				.top-tips2 {
					margin-top: 20rpx;
					color: #00AAFF;
					font-size: 28rpx;
					text-align: center;

				}
			}

			.contentV {
				position: relative;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				height: 661rpx;
				margin-top: 30rpx;

				.tipV {
					bottom: 30rpx;
					position: absolute;
					line-height: 90rpx;
					padding-left: 24rpx;
					padding-right: 24rpx;
					max-width: calc(100vw - 50rpx * 2);
					text-align: center;
					font-size: 30rpx;
					background: #000000;
					opacity: 0.75;
					color: #FFFFFF;
					border-radius: 16rpx;

					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					z-index: 5;
				}

				.camera {
					width: 100%;
					height: 100%;
				}

				.mark {
					position: absolute;
					left: 0;
					top: 0;
					z-index: 2;
					width: 750rpx;
					height: 100%;
					background: url("@/static/face/view_face_background.png") no-repeat center bottom;
					background-size: 750rpx 661rpx;
				}

				image {
					position: absolute;
					width: 100%;
					height: 100%;
					z-index: 3;
				}
			}

			.footerV {
				width: 100%;

				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: center;


				.privacyV {
					padding-top: 30rpx;

					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: center;

					.text {
						font-size: 30rpx;
						color: #1C1C1C;
						text-align: center;
						line-height: 42rpx;
						margin-left: 15rpx;

						text {
							font-size: 30rpx;
							color: #00AAFF;
							text-align: center;
							line-height: 42rpx;
						}
					}

					.icon {
						width: 40rpx;
						height: 47rpx;
						background: url("@/static/face/icon_face_security.png") no-repeat;
						background-size: 100% auto;
					}

				}

				.bottom-tips-2 {
					margin-top: 20rpx;
					color: #999999;
					text-align: center;
					font-size: 26rpx;
				}

				.take-photo-bgV {
					width: 100%;
					margin-top: 30rpx;

					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: center;


					.btn-take-photo {
						// 由于左邊沒有按鈕,所以左邊要便宜更大,以便是拍照按鈕居中
						margin: 0rpx 80rpx 0rpx 80rpx;
						width: 196rpx;
						height: 196rpx;
						background: url("https://pro-file-qn.ztjy61.com/1003020211103145058685NNR9vlTm.png") no-repeat;
						background-size: 100% auto;
					}

					.btn-change-upload {
						left: 130rpx;
						width: 80rpx;
						height: 80rpx;
						background: url("@/static/face/icon_face_upload_picture.png") no-repeat;
						background-size: 100% auto;
					}

					.btn-change-camera {
						right: 130rpx;
						width: 80rpx;
						height: 80rpx;
						background: url("@/static/face/icon_face_switch_cameras.png") no-repeat;
						background-size: 100% auto;
					}
				}

				.confirmV {
					margin: 200rpx 100rpx 0rpx 100rpx;
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: space-between;

					.btn-cancel {
						font-size: 32rpx;
						color: #1C1C1C;
					}

					.btn-ok {
						font-size: 32rpx;
						color: #00AAFF;
					}
				}
			}
		}
	}
</style>

js邏輯:
關(guān)鍵點代碼中已經(jīng)注釋


<script>
	export default {
		name: 'index',
		components: {

		},
		data() {
			return {
				tipsText: '', // 錯誤文案提示
				tempImg: '', // 本地圖片路徑

				cameraEngine: null, // 相機引擎
				devicePosition: false, // 攝像頭朝向
				isAuthCamera: true, // 是否擁有相機權(quán)限
			}
		},

		onLoad(options) {
			this.initData()
		},

		methods: {
			// 初始化相機引擎
			initData() {
				// #ifdef MP-WEIXIN

				// 1、初始化人臉識別
				wx.initFaceDetect()
				// 2、創(chuàng)建 camera 上下文 CameraContext 對象
				this.cameraEngine = wx.createCameraContext()
				// 3、獲取 Camera 實時幀數(shù)據(jù)
				const listener = this.cameraEngine.onCameraFrame((frame) => {
					if (this.tempImg) {
						return;
					}
					// 4、人臉識別,使用前需要通過 wx.initFaceDetect 進行一次初始化,推薦使用相機接口返回的幀數(shù)據(jù)
					wx.faceDetect({
						frameBuffer: frame.data,
						width: frame.width,
						height: frame.height,
						enablePoint: true,
						enableConf: true,
						enableAngle: true,
						enableMultiFace: true,
						success: (faceData) => {
							let face = faceData.faceInfo[0]
							if (faceData.x == -1 || faceData.y == -1) {
								this.tipsText = '檢測不到人'
							}
							if (faceData.faceInfo.length > 1) {
								this.tipsText = '請保證只有一個人'
							} else {
								const {
									pitch,
									roll,
									yaw
								} = face.angleArray;
								const standard = 0.5
								if (Math.abs(pitch) >= standard || Math.abs(roll) >= standard ||
									Math.abs(yaw) >= standard) {
									this.tipsText = '請平視攝像頭'
								} else if (face.confArray.global <= 0.8 || face.confArray.leftEye <=
									0.8 || face.confArray.mouth <= 0.8 || face.confArray.nose <= 0.8 ||
									face.confArray.rightEye <= 0.8) {
									this.tipsText = '請勿遮擋五官'
								} else {
									this.tipsText = '請拍照'
									// 這里可以寫自己的邏輯了
								}
							}
						},
						fail: (err) => {
							if (err.x == -1 || err.y == -1) {
								this.tipsText = '檢測不到人'
							} else {
								this.tipsText = err.errMsg || '網(wǎng)絡(luò)錯誤,請退出頁面重試'
							}
						},
					})
				})
				// 5、開始監(jiān)聽幀數(shù)據(jù)
				listener.start()
				// #endif
			},

			// 切換設(shè)備鏡頭
			handleChangeCameraClick() {
				this.devicePosition = !this.devicePosition;
			},

			// 圖片上傳
			handleChooseImage() {
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album'],
					success: (res) => {
						if (res.errMsg === 'chooseImage:ok') {
							uni.showLoading({
								title: '照片上傳中...'
							})
							console.log("===========:", res.tempFilePaths[0])
							this.handleOkClick()
						}
					},
					fail: (res) => {

					},
				});
			},

			// 拍照點擊
			handleTakePhotoClick() {
				if (this.tipsText != "" && this.tipsText != "請拍照") {
					return;
				}

				uni.getSetting({
					success: (res) => {
						if (!res.authSetting['scope.camera']) {
							this.isAuthCamera = false
							uni.openSetting({
								success: (res) => {
									if (res.authSetting['scope.camera']) {
										this.isAuthCamera = true;
									}
								}
							})
						}
					}
				})
				this.cameraEngine.takePhoto({
					quality: "high",
					success: ({
						tempImagePath
					}) => {
						this.tempImg = tempImagePath
						console.log("=======tempImg:", this.tempImg)
					}
				})
			},

			// 點擊確定上傳
			handleOkClick() {
				uni.showLoading({
					mask: true,
					title: '校驗中...'
				})
				// 更新人臉識別圖片請求協(xié)議:傳七牛圖片鏈接				
				setTimeout(function() {
					uni.hideLoading()
					uni.showToast({
						icon: "none",
						title: "假裝圖片上傳成功",
						duration: 2000,
					})
				}, 3000);
			},

			// 點擊 - 取消上傳
			handleCancelClick() {
				this.tempImg = ''
			},

			// 點擊 - 人臉安全保障按鈕
			handleJumpSecurityClick() {
				uni.showToast({
					icon: "none",
					title: "假裝跳轉(zhuǎn)人臉安全保障",
					duration: 2000,
				})
			},

		}
	}
</script>

拓展:
可以將圖片上傳至服務(wù)器,由服務(wù)器做人臉識別,這樣功能就齊全了。

視頻為上:

人臉采集

demo:
1、gitee:https://gitee.com/chenzm_186/face-detect-mini
2、csdn:https://download.csdn.net/download/weixin_38633659/85385944


**??結(jié)束語?? **

最后如果覺得我寫的文章對您有幫助的話,歡迎點贊?,收藏?,加關(guān)注?哦,謝謝謝謝!!

使用uniapp開發(fā)微信小程序的人臉采集功能/人臉識別功能文章來源地址http://www.zghlxwxcb.cn/news/detail-503823.html

到了這里,關(guān)于使用uniapp開發(fā)微信小程序的人臉采集功能/人臉識別功能的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包