From 17266dfc45405c00a8d4159d636fdbe65ce5568d Mon Sep 17 00:00:00 2001 From: huliyong <2783385703@qq.com> Date: Thu, 14 Nov 2024 20:32:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages.json | 6 + pages/index/index.vue | 6 +- pages/subPack/face/face.vue | 419 ++++++++++++++++++++++++++++++++++++++++++ pages/subPack/human/human.vue | 147 ++++++++++++++- utils/oss-upload/oss/index.js | 10 - utils/oss-upload/oss/web.js | 2 +- 6 files changed, 572 insertions(+), 18 deletions(-) create mode 100644 pages/subPack/face/face.vue diff --git a/pages.json b/pages.json index 05d3380..0a02813 100644 --- a/pages.json +++ b/pages.json @@ -57,6 +57,12 @@ "navigationBarTitleText": "人脸识别" } }, + { + "path": "face/face", + "style": { + "navigationBarTitleText": "人脸验证" + } + }, { "path": "team/team", "style": { diff --git a/pages/index/index.vue b/pages/index/index.vue index 74b719e..94d323e 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -16,7 +16,10 @@ - + @@ -166,6 +169,7 @@ //打卡(跳转人脸识别) callCard(){ uni.navigateTo({ + // url: "/pages/subPack/face/face" url: "/pages/subPack/human/human" }) } diff --git a/pages/subPack/face/face.vue b/pages/subPack/face/face.vue new file mode 100644 index 0000000..22c61e8 --- /dev/null +++ b/pages/subPack/face/face.vue @@ -0,0 +1,419 @@ + + + + + + + + diff --git a/pages/subPack/human/human.vue b/pages/subPack/human/human.vue index 2469992..c2750ec 100644 --- a/pages/subPack/human/human.vue +++ b/pages/subPack/human/human.vue @@ -13,12 +13,29 @@ + + + + + - + 人脸认证仅能由{{ userInfo.auth.name }}本人完成验证时,请将镜头对准您的脸部 + + + {{ tipsText }}{{ tempImg }} + @@ -40,7 +57,9 @@ -
+
+ @@ -70,12 +90,23 @@ form : { pic : '', }, - isLocationSubmit : false, + isLocationSubmit : false,//定位完成时提交 + + + tipsText: '', // 错误文案提示 + tempImg: '', // 本地图片路径 + + cameraEngine: null, // 相机引擎 + devicePosition: true, // 摄像头朝向 + isAuthCamera: true, // 是否拥有相机权限 } }, computed: { ...mapState(['teamList', 'userInfo']), }, + onLoad() { + this.initData() + }, onShow() { let self = this position.getLocationDetail() @@ -139,7 +170,7 @@ } }); }, - submit(){ + async submit(){ if (this.$utils.verificationAll(this.form, { lat : '经纬度缺失,请打开GPS', lon : '经纬度缺失,请打开GPS', @@ -161,6 +192,105 @@ } }) }, + // 初始化相机引擎 + initData() { + // #ifdef MP-WEIXIN + + + // 1、初始化人脸识别 + wx.initFaceDetect() + // 2、创建 camera 上下文 CameraContext 对象 + this.cameraEngine = wx.createCameraContext() + // 3、获取 Camera 实时帧数据 + const listener = this.cameraEngine.onCameraFrame((frame) => { + if (this.tempImg) { + return; + } + // 4、人脸识别,使用前需要通过 wx.initFaceDetect 进行一次初始化,推荐使用相机接口返回的帧数据 + 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 = '请拍照' + // 这里可以写自己的逻辑了 + // this.handleTakePhotoClick() + } + } + }, + fail: (err) => { + if (err.x == -1 || err.y == -1) { + this.tipsText = '检测不到人' + } else { + this.tipsText = err.errMsg || '网络错误,请退出页面重试' + } + }, + }) + }) + // 5、开始监听帧数据 + listener.start() + + this.isPhoto = true + // #endif + }, + + // 拍照 + handleTakePhotoClick() { + if (this.tipsText != "" + && this.tipsText != "请拍照" + && !this.tempImg) { + 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) + } + }) + }, } } @@ -182,9 +312,14 @@ .human-face-img { display: flex; justify-content: center; - image { - width: 70%; + width: 500rpx; + border-radius: 50%; + } + .camera{ + width: 500rpx; + height: 500rpx; + border-radius: 50%; } } diff --git a/utils/oss-upload/oss/index.js b/utils/oss-upload/oss/index.js index 024eb80..91b7093 100644 --- a/utils/oss-upload/oss/index.js +++ b/utils/oss-upload/oss/index.js @@ -2,10 +2,6 @@ * 阿里云OSS工具类 */ import OSSConfig from "@/utils/oss-upload/oss/OSSConfig.js" -//支持web端 -import { - uploadFileToOSS -} from '@/utils/oss-upload/oss/web.js' import ossConfig from '@/config.js' /** @@ -93,9 +89,6 @@ export function ossUploadImage({ count: 1, sizeType, success(res) { - // #ifdef H5 - return uploadFileToOSS(res.tempFiles[0]).then(success).catch(fail) - // #endif ossUpload(res.tempFilePaths[0], key, folder).then(success).catch(fail) }, fail @@ -123,9 +116,6 @@ export function ossUploadVideo({ maxDuration, camera, success(res) { - // #ifdef H5 - return uploadFileToOSS(res.tempFile).then(success).catch(fail) - // #endif ossUpload(res.tempFilePath, key, folder).then(success).catch(fail) }, fail diff --git a/utils/oss-upload/oss/web.js b/utils/oss-upload/oss/web.js index dfaab6e..9b419ae 100644 --- a/utils/oss-upload/oss/web.js +++ b/utils/oss-upload/oss/web.js @@ -1,5 +1,5 @@ // 此方法适用于web -import OSS from "ali-oss" +// import OSS from "ali-oss" import config from '@/config.js' /**