人脸识别优化

This commit is contained in:
binbin_pan 2024-09-18 17:15:31 +08:00
parent ad60298cdd
commit d2bb0079e6
4 changed files with 146 additions and 80 deletions

View File

@ -171,7 +171,8 @@ export default {
fileUrl: config.fileUrl, fileUrl: config.fileUrl,
score: 0, score: 0,
passScore: 0, passScore: 0,
isHide: false isHide: false,
failCount: 3
} }
}, },
onLoad(opt) { onLoad(opt) {
@ -241,7 +242,7 @@ export default {
console.log('🚀 ~ getList ~ this.time:', this.time) console.log('🚀 ~ getList ~ this.time:', this.time)
console.log('🚀 ~ getList ~ this.questionList:', this.questionList) console.log('🚀 ~ getList ~ this.questionList:', this.questionList)
this.random1 = (data.answerTime / 3) * 60 + Math.ceil(Math.random() * 20) + 20 this.random1 = (data.answerTime / 3) * 60 + Math.ceil(Math.random() * 20) + 20
this.random2 = (data.answerTime / 2) * 60 + Math.ceil(Math.random() * 30) + 30 this.random2 = (data.answerTime / 1.5) * 60 + Math.ceil(Math.random() * 30) + 30
console.log('🚀 ~ getList ~ this.random1:', this.random1, this.random2) console.log('🚀 ~ getList ~ this.random1:', this.random1, this.random2)
if (this.questionList.length > 0) { if (this.questionList.length > 0) {
this.questionList.forEach((item, index) => { this.questionList.forEach((item, index) => {
@ -468,25 +469,28 @@ export default {
// //
openPhotograph() { openPhotograph() {
this.isHide = true this.isHide = true
uni.chooseImage({ setTimeout(() => {
count: 1, this.$refs.countDown.pause()
sizeType: ['compressed'], uni.chooseImage({
sourceType: ['camera'], count: 1,
success: res => { sizeType: ['compressed'],
this.isHide = false sourceType: ['camera'],
let url = '' success: res => {
console.log('🚀 ~ res-拍照:', res) this.isHide = false
this.imgToBase64(res.tempFilePaths[0]).then(base64 => { let url = ''
url = base64 console.log('🚀 ~ res-拍照:', res)
console.log('🚀 ~ this.imgToBase64 ~ base64:', url) this.imgToBase64(res.tempFilePaths[0]).then(base64 => {
this.getFaceRecognition({ userId: uni.getStorageSync('userId'), img: url }) url = base64
}) console.log('🚀 ~ this.imgToBase64 ~ base64:', url)
}, this.getFaceRecognition({ userId: uni.getStorageSync('userId'), img: url })
fail: err => { })
this.isHide = false },
console.log('🚀 ~ err:', err) fail: err => {
} this.isHide = false
}) console.log('🚀 ~ err:', err)
}
})
}, 10)
}, },
imgToBase64(data) { imgToBase64(data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -521,14 +525,28 @@ export default {
message: '人脸识别成功', message: '人脸识别成功',
duration: 1000 duration: 1000
}) })
this.failCount = 3
//
this.$refs.countDown.start()
} else { } else {
this.$refs.uToast.show({ this.failCount--
message: '人脸识别失败, 即将结束考试', if (this.failCount == 0) {
duration: 1000 this.$refs.uToast.show({
}) message: '人脸识别失败, 即将结束考试',
setTimeout(() => { duration: 1500
this.handleConfirmSubmit() })
}, 1000) setTimeout(() => {
this.handleConfirmSubmit()
}, 1000)
} else {
this.$refs.uToast.show({
message: '人脸识别失败, 请重新录入, 剩余次数: ' + this.failCount + '次',
duration: 1500
})
setTimeout(() => {
this.openPhotograph()
}, 1700)
}
} }
}, },
fail(err) { fail(err) {
@ -561,7 +579,7 @@ export default {
console.log(err) console.log(err)
} }
}) })
}, }
}, },
onBackPress(options) { onBackPress(options) {
console.log(options) console.log(options)

View File

@ -61,7 +61,9 @@ export default {
isHide: false, isHide: false,
oldTime: 0, oldTime: 0,
random1: 0, random1: 0,
random2: 0 random2: 0,
//
failCount: 3
} }
}, },
onLoad(opt) { onLoad(opt) {
@ -193,30 +195,32 @@ export default {
// //
openPhotograph() { openPhotograph() {
this.isHide = true this.isHide = true
uni.chooseImage({ setTimeout(() => {
count: 1, uni.chooseImage({
sizeType: ['compressed'], count: 1,
sourceType: ['camera'], sizeType: ['compressed'],
success: res => { sourceType: ['camera'],
let url = '' success: res => {
console.log('🚀 ~ res-拍照:', res) let url = ''
this.imgToBase64(res.tempFilePaths[0]).then(base64 => { console.log('🚀 ~ res-拍照:', res)
url = base64 this.imgToBase64(res.tempFilePaths[0]).then(base64 => {
console.log('🚀 ~ this.imgToBase64 ~ base64:', url) url = base64
this.getFaceRecognition({ userId: uni.getStorageSync('userId'), img: url }) console.log('🚀 ~ this.imgToBase64 ~ base64:', url)
}) this.getFaceRecognition({ userId: uni.getStorageSync('userId'), img: url })
}, })
fail(err) { },
console.log('🚀 ~ openFaceScan ~ 人脸识别失败', err) fail(err) {
uni.showToast({ console.log('🚀 ~ openFaceScan ~ 人脸识别失败', err)
title: '人脸识别失败', uni.showToast({
icon: '' title: '人脸识别失败',
}) icon: ''
setTimeout(() => { })
this.handleEnd() setTimeout(() => {
}, 1000) this.handleEnd()
} }, 1000)
}) }
})
}, 100)
}, },
imgToBase64(data) { imgToBase64(data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -250,18 +254,33 @@ export default {
// //
uni.showToast({ uni.showToast({
title: '人脸识别成功', title: '人脸识别成功',
icon: '' icon: '',
duration: 1500
}) })
this.failCount = 3 //
this.isHide = false this.isHide = false
this.video.play() this.video.play()
} else { } else {
uni.showToast({ this.failCount--
title: '人脸识别失败', if (this.failCount == 0) {
icon: '' uni.showToast({
}) title: '人脸识别失败, 即将结束学习',
setTimeout(() => { icon: 'none',
this.handleEnd() duration: 1500
}, 1000) })
setTimeout(() => {
this.handleEnd()
}, 1500)
} else {
uni.showToast({
title: '人脸识别失败, 请重新录入, 剩余次数: ' + this.failCount + '次',
icon: 'none',
duration: 1500
})
setTimeout(() => {
this.openPhotograph()
}, 1500)
}
} }
}, },
fail(err) { fail(err) {

View File

@ -24,7 +24,9 @@ export default {
time: '', time: '',
isHide: false, isHide: false,
allStudyDuration: 0, allStudyDuration: 0,
random: 0 random: 0,
//
failCount: 3
} }
}, },
onLoad(opt) { onLoad(opt) {
@ -248,13 +250,26 @@ export default {
this.isShow = true this.isShow = true
this.countDown() this.countDown()
} else { } else {
uni.showToast({ this.failCount--
title: '人脸识别失败', if (this.failCount == 0) {
icon: '' uni.showToast({
}) title: '人脸识别失败, 即将结束学习',
setTimeout(() => { icon: 'none',
this.updStudyDuration() duration: 1500
}, 1000) })
setTimeout(() => {
this.updStudyDuration()
}, 1500)
} else {
uni.showToast({
title: '人脸识别失败, 请重新录入, 剩余次数: ' + this.failCount + '次',
icon: 'none',
duration: 1500
})
setTimeout(() => {
this.openPhotograph()
}, 1500)
}
} }
}, },
fail(err) { fail(err) {

View File

@ -24,7 +24,9 @@ export default {
isHide: false, isHide: false,
allStudyDuration: 0, allStudyDuration: 0,
random1: 0, random1: 0,
random2: 0 random2: 0,
//
failCount: 3
} }
}, },
onLoad(opt) { onLoad(opt) {
@ -211,9 +213,9 @@ export default {
if (res.code == 200) { if (res.code == 200) {
// //
uni.showToast({ uni.showToast({
title: '人脸识别成功', title: '人脸识别成功'
icon: ''
}) })
this.failCount = 3
this.isHide = false this.isHide = false
// this.surplusTime // this.surplusTime
this.surplusTime = this.allStudyDuration this.surplusTime = this.allStudyDuration
@ -225,13 +227,25 @@ export default {
this.isShow = true this.isShow = true
this.countDown() this.countDown()
} else { } else {
uni.showToast({ this.failCount--
title: '人脸识别失败', if (this.failCount == 0) {
icon: '' uni.showToast({
}) title: '人脸识别失败, 即将结束学习',
setTimeout(() => { icon: 'none'
this.updStudyDuration() })
}, 1000) setTimeout(() => {
this.updStudyDuration()
}, 1000)
} else {
uni.showToast({
title: '人脸识别失败, 请重新录入, 剩余次数: ' + this.failCount + '次',
icon: 'none',
duration: 1500
})
setTimeout(() => {
this.openPhotograph()
}, 1500)
}
} }
}, },
fail(err) { fail(err) {