feat(face): 添加人脸识别距离检测和环境切换时的人脸数据重置功能
- 在FaceHelper中添加人脸宽度小于200像素时的过滤逻辑,避免远距离识别人脸 - 注释掉LoginByFaceActivity中的重复识别状态判断逻辑 - 在PlcSettingActivity中添加协程支持用于异步处理人脸数据清除操作 - 实现环境切换时清空所有人脸数据并重新获取用户人脸缓存的功能 - 修改UserViewModel中回调逻辑,当第一页无数据时返回false而非true
This commit is contained in:
@@ -772,13 +772,13 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
lifecycleScope = lifecycleScope,
|
||||
onTick = { remaining ->
|
||||
loadLogInfo("resetRecognizeState剩余时间:$remaining 秒")
|
||||
if (judgeRecognizeState()) return@startCountDown
|
||||
// if (judgeRecognizeState()) return@startCountDown
|
||||
loadLogInfo("initCountTime onTick = $remaining")
|
||||
binding.tvToInit.text = "$remaining"
|
||||
},
|
||||
onFinish = {
|
||||
loadLogInfo("resetRecognizeState倒计时结束")
|
||||
if (judgeRecognizeState()) return@startCountDown
|
||||
// if (judgeRecognizeState()) return@startCountDown
|
||||
if (facePreviewInfoList.isNullOrEmpty()) {
|
||||
goInitActivity()
|
||||
} else {
|
||||
@@ -802,20 +802,20 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
// recognizeViewModel.onPreviewFrame(emptyFrame, true)
|
||||
}
|
||||
|
||||
private fun judgeRecognizeState(): Boolean {
|
||||
val rectColor = binding.dualCameraFaceRectView.rectColor
|
||||
if (rectColor == RecognizeColor.COLOR_SUCCESS && currentUserId.isNullOrBlank()
|
||||
.not() && facePreviewInfoList.isNullOrEmpty().not()
|
||||
) {
|
||||
//人未离开,再次识别
|
||||
loadLogInfo("userId=$currentUserId")
|
||||
openPlateDebouncer.debounce {
|
||||
openPlate(currentUserId)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
// private fun judgeRecognizeState(): Boolean {
|
||||
// val rectColor = binding.dualCameraFaceRectView.rectColor
|
||||
// if (rectColor == RecognizeColor.COLOR_SUCCESS && currentUserId.isNullOrBlank()
|
||||
// .not() && facePreviewInfoList.isNullOrEmpty().not()
|
||||
// ) {
|
||||
// //人未离开,再次识别
|
||||
// loadLogInfo("userId=$currentUserId")
|
||||
// openPlateDebouncer.debounce {
|
||||
// openPlate(currentUserId)
|
||||
// }
|
||||
// return true
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
|
||||
fun goInitActivity() {
|
||||
val intent = Intent(context, InitActivity::class.java)
|
||||
|
||||
@@ -3,7 +3,9 @@ package com.sw.platecabinet.activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
import com.sw.plate.utils.arcface.faceserver.FaceServer
|
||||
import com.sw.platecabinet.databinding.ActivityPlcSettingBinding
|
||||
import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
||||
import com.sw.platecabinet.dialog.EnvSwitchDialog
|
||||
@@ -11,6 +13,9 @@ import com.sw.platecabinet.ext.clickWithDebounce
|
||||
import com.sw.platecabinet.utils.mego.PlcCallback
|
||||
import com.sw.platecabinet.utils.mego.PlcHelper
|
||||
import com.sw.platecabinet.utils.mego.PlcStatus
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
* PLC 控制设置界面
|
||||
@@ -43,7 +48,22 @@ class PlcSettingActivity : BaseActivity<ActivityPlcSettingBinding>() {
|
||||
initParamButtons()
|
||||
initStatusButton()
|
||||
binding.btnSwitchEnv.setOnClickListener {
|
||||
EnvSwitchDialog(this).show()
|
||||
EnvSwitchDialog(context = this, onEnvChanged = {
|
||||
showWaitingDialog("重置人脸数据中……")
|
||||
lifecycleScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
FaceServer.getInstance().clearAllFaces()
|
||||
}
|
||||
}
|
||||
userViewModel.getUserFaceCache(pageNo = 1, callback = { state, errMsg ->
|
||||
hideWaitingDialog()
|
||||
if (state) {
|
||||
ToastUtils.showToast("人脸数据已更新")
|
||||
} else {
|
||||
ToastUtils.showToast(errMsg)
|
||||
}
|
||||
})
|
||||
}).show()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class UserViewModel : BaseViewModel() {
|
||||
SPUtil.getInstance().put(GlobalKey.KEY_FIRST_RUN, true)
|
||||
val list: List<UserFaceModel> = response.data ?: emptyList()
|
||||
if (pageNo == 1 && list.isEmpty()) {
|
||||
callback(true, "暂无数据")
|
||||
callback(false, "暂无数据")
|
||||
return@launchWithLoading
|
||||
}
|
||||
val faceEntityList = list.map {
|
||||
|
||||
@@ -343,6 +343,14 @@ public class FaceHelper implements FaceListener {
|
||||
refreshTrackId(faceInfoList);
|
||||
if (faceInfoList.isEmpty()) {
|
||||
return facePreviewInfoList;
|
||||
} else {
|
||||
FaceInfo currentFaceInfo = faceInfoList.get(0);
|
||||
// L.e("currentFaceInfo width=" + currentFaceInfo.getRect().width() +
|
||||
// "---height" + currentFaceInfo.getRect().height());
|
||||
if (currentFaceInfo.getRect().width() < 200) {//距离远(人脸小),不识别
|
||||
clearLeftFace(facePreviewInfoList);
|
||||
return facePreviewInfoList;
|
||||
}
|
||||
}
|
||||
if (!onlyDetectLiveness) {
|
||||
code = ftEngine.process(rgbNv21, previewSize.width, previewSize.height, FaceEngine.CP_PAF_NV21, faceInfoList,
|
||||
|
||||
Reference in New Issue
Block a user