采集优化
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.sw.platecabinet.activity
|
package com.sw.platecabinet.activity
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Point
|
import android.graphics.Point
|
||||||
import android.hardware.Camera
|
import android.hardware.Camera
|
||||||
@@ -157,7 +158,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
val permissionHelper =
|
val permissionHelper =
|
||||||
PermissionHelper.with(this, REQUIRED_PERMISSIONS, CAMERA_PERMISSION_REQUEST_CODE)
|
PermissionHelper.with(this, REQUIRED_PERMISSIONS, CAMERA_PERMISSION_REQUEST_CODE)
|
||||||
.onGranted {
|
.onGranted {
|
||||||
Timber.d("checkCameraPermission 权限已允许")
|
loadLogInfo("checkCameraPermission 权限已允许")
|
||||||
// 权限已授予
|
// 权限已授予
|
||||||
recognizeViewModel.init()
|
recognizeViewModel.init()
|
||||||
initRgbCamera()
|
initRgbCamera()
|
||||||
@@ -189,7 +190,6 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
recognizeViewModel.setLiveType(livenessType)
|
recognizeViewModel.setLiveType(livenessType)
|
||||||
recognizeViewModel.prepareRegister()
|
recognizeViewModel.prepareRegister()
|
||||||
recognizeViewModel.setOnRegisterFinishedCallback { facePreviewInfo, userFaceInfo ->
|
recognizeViewModel.setOnRegisterFinishedCallback { facePreviewInfo, userFaceInfo ->
|
||||||
//Log.d(TAG, "initArcViewModel: userFaceInfo == null : ${userFaceInfo == null}")
|
|
||||||
if (!isCollectFace) {
|
if (!isCollectFace) {
|
||||||
return@setOnRegisterFinishedCallback
|
return@setOnRegisterFinishedCallback
|
||||||
}
|
}
|
||||||
@@ -197,6 +197,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
recognizeViewModel.updateRegisterStatus(RecognizeViewModel.REGISTER_STATUS_DONE)
|
recognizeViewModel.updateRegisterStatus(RecognizeViewModel.REGISTER_STATUS_DONE)
|
||||||
this.userFaceInfo = userFaceInfo
|
this.userFaceInfo = userFaceInfo
|
||||||
getFaceDataBlock { faceData ->
|
getFaceDataBlock { faceData ->
|
||||||
|
isCollectFace = false
|
||||||
Thread {
|
Thread {
|
||||||
saveFaceInfo(faceData)
|
saveFaceInfo(faceData)
|
||||||
}.start()
|
}.start()
|
||||||
@@ -245,23 +246,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
|
|
||||||
recognizeViewModel.recognizeUserId.observe(this, Observer { result: CompareResult? ->
|
recognizeViewModel.recognizeUserId.observe(this, Observer { result: CompareResult? ->
|
||||||
Timber.i("recognizeUserId observe userId = ${result?.faceEntity?.userName}")
|
Timber.i("recognizeUserId observe userId = ${result?.faceEntity?.userName}")
|
||||||
// if (result?.faceEntity == null) {
|
|
||||||
// collectFace()
|
|
||||||
// return@Observer
|
|
||||||
// }
|
|
||||||
currentUserId = result?.faceEntity?.userName
|
currentUserId = result?.faceEntity?.userName
|
||||||
plateEnable = true
|
plateEnable = true
|
||||||
// checkFaceJob?.cancel()
|
|
||||||
// getFaceJob?.cancel()
|
|
||||||
// viewModel.getUserInfoById(memberId = userId)
|
|
||||||
// ToastUtils.showToast(currentUserId)
|
|
||||||
// if (!currentUserId.isNullOrBlank()) {
|
|
||||||
//// ToastUtils.showToast("您已采集过人脸信息")
|
|
||||||
// return@Observer
|
|
||||||
// }
|
|
||||||
// if (currentPlateInfo?.faceId == currentUserId) {
|
|
||||||
// return@Observer
|
|
||||||
// }
|
|
||||||
openPlate(currentUserId)
|
openPlate(currentUserId)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -270,8 +256,6 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// private val settingViewModel by viewModels<SettingViewModel>()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询餐盘数据
|
* 查询餐盘数据
|
||||||
*/
|
*/
|
||||||
@@ -279,14 +263,9 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
MyApp.plateList?.let {
|
MyApp.plateList?.let {
|
||||||
block(it)
|
block(it)
|
||||||
}
|
}
|
||||||
// settingViewModel.getEquipmentList { items ->
|
|
||||||
// block(items)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var currentPlateInfo: EquipmentUserInfo? = null
|
private var currentPlateInfo: EquipmentUserInfo? = null
|
||||||
|
|
||||||
// private var debouncer = Debouncer(5000)
|
|
||||||
private var plateEnable = true
|
private var plateEnable = true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -294,21 +273,20 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
*/
|
*/
|
||||||
private fun openPlate(userId: String?) {
|
private fun openPlate(userId: String?) {
|
||||||
if (plateEnable.not()) return
|
if (plateEnable.not()) return
|
||||||
// debouncer.debounce {
|
loadLogInfo("collectFace,openPlate: userId=$userId")
|
||||||
Log.d(TAG, "openPlate: userId=$userId")
|
|
||||||
getPlateData { items ->
|
getPlateData { items ->
|
||||||
Log.d(TAG, "openPlate: items:${Gson().toJson(items)}")
|
loadLogInfo("collectFace,openPlate: items:${Gson().toJson(items)}")
|
||||||
// 未查询到当前用户,查询第一个未绑定的餐盘
|
// 未查询到当前用户,查询第一个未绑定的餐盘
|
||||||
val item = items.firstOrNull { it.plateNumber.isNullOrEmpty().not() }
|
val item = items.firstOrNull { it.plateNumber.isNullOrEmpty().not() }
|
||||||
Log.d(TAG, "openPlate: item2:${item}")
|
loadLogInfo("collectFace,openPlate: item2:${item}")
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
//暂无餐盘
|
//暂无餐盘
|
||||||
Log.d(TAG, "collectFace,openPlate: 暂无餐盘,请联系管理人员,isCollectFace=$isCollectFace")
|
loadLogInfo("collectFace,openPlate: 暂无餐盘,请联系管理人员,isCollectFace=$isCollectFace")
|
||||||
ToastUtils.showToast("暂无餐盘,请联系管理人员!")
|
ToastUtils.showToast("暂无餐盘,请联系管理人员!")
|
||||||
goInitActivity()
|
goInitActivity()
|
||||||
return@getPlateData
|
return@getPlateData
|
||||||
}
|
}
|
||||||
Log.d(TAG, "openPlate: item3:${item}")
|
loadLogInfo("collectFace,openPlate: item3:${item}")
|
||||||
item.faceId = userId
|
item.faceId = userId
|
||||||
item.updateTime = DateTimeUtils.getDateTimeString()
|
item.updateTime = DateTimeUtils.getDateTimeString()
|
||||||
item.plateNumber = null
|
item.plateNumber = null
|
||||||
@@ -318,28 +296,9 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
currentPlateInfo = item
|
currentPlateInfo = item
|
||||||
MyApp.plateList = items
|
MyApp.plateList = items
|
||||||
SpTool.savePlateData(items)
|
SpTool.savePlateData(items)
|
||||||
|
|
||||||
// debouncer.reset()
|
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 绑定餐盘
|
|
||||||
// */
|
|
||||||
// private fun bindPlate(item: EquipmentUserInfo) {
|
|
||||||
// val bindParam = BindParam(
|
|
||||||
// equipmentId = item.equipmentId,
|
|
||||||
// equipmentCode = item.equipmentCode,
|
|
||||||
// equipmentBoxCode = item.equipmentBoxCode,
|
|
||||||
// faceId = item.faceId,
|
|
||||||
// plateNumber = item.plateNumber
|
|
||||||
// )
|
|
||||||
// settingViewModel.bindPlate(bindParam) { pair ->
|
|
||||||
// Log.d(TAG, "openPlate: state:${pair.first},msg:${pair.second.code},${pair.second.msg}")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private fun initArcView() {
|
private fun initArcView() {
|
||||||
//在布局结束后才做初始化操作
|
//在布局结束后才做初始化操作
|
||||||
binding.dualCameraTexturePreviewRgb.getViewTreeObserver().addOnGlobalLayoutListener(this)
|
binding.dualCameraTexturePreviewRgb.getViewTreeObserver().addOnGlobalLayoutListener(this)
|
||||||
@@ -347,7 +306,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
Timber.d("onDestroy")
|
loadLogInfo("onDestroy")
|
||||||
instance = null
|
instance = null
|
||||||
if (rgbCameraHelper != null) {
|
if (rgbCameraHelper != null) {
|
||||||
rgbCameraHelper!!.release()
|
rgbCameraHelper!!.release()
|
||||||
@@ -357,8 +316,6 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
recognizeViewModel.destroy()
|
recognizeViewModel.destroy()
|
||||||
|
|
||||||
EventBus.getDefault().unregister(this)
|
EventBus.getDefault().unregister(this)
|
||||||
// countDownJob?.cancel()
|
|
||||||
// checkFaceJob?.cancel()
|
|
||||||
// getFaceScheduler?.shutdown()
|
// getFaceScheduler?.shutdown()
|
||||||
checkFaceScheduler?.shutdown()
|
checkFaceScheduler?.shutdown()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
@@ -434,7 +391,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
displayOrientation: Int,
|
displayOrientation: Int,
|
||||||
isMirror: Boolean
|
isMirror: Boolean
|
||||||
) {
|
) {
|
||||||
Timber.d("initRgbCamera Rgb onCameraOpened: cameraId = $cameraId, displayOrientation = $displayOrientation")
|
loadLogInfo("initRgbCamera Rgb onCameraOpened: cameraId = $cameraId, displayOrientation = $displayOrientation")
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
val previewSizeRgb = camera.getParameters().getPreviewSize()
|
val previewSizeRgb = camera.getParameters().getPreviewSize()
|
||||||
val layoutParams = adjustPreviewViewSize(
|
val layoutParams = adjustPreviewViewSize(
|
||||||
@@ -442,9 +399,9 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
binding.dualCameraTexturePreviewRgb, binding.dualCameraFaceRectView,
|
binding.dualCameraTexturePreviewRgb, binding.dualCameraFaceRectView,
|
||||||
previewSizeRgb, displayOrientation, 0.6f
|
previewSizeRgb, displayOrientation, 0.6f
|
||||||
)
|
)
|
||||||
Timber.d("initRgbCamera previewSizeRgb = ${previewSizeRgb.width}-${previewSizeRgb.height}")
|
loadLogInfo("initRgbCamera previewSizeRgb = ${previewSizeRgb.width}-${previewSizeRgb.height}")
|
||||||
Timber.d("initRgbCamera layoutParams = ${layoutParams.width}-${layoutParams.height}")
|
loadLogInfo("initRgbCamera layoutParams = ${layoutParams.width}-${layoutParams.height}")
|
||||||
Timber.d(
|
loadLogInfo(
|
||||||
"initRgbCamera isMirror = ${isMirror}, isDrawRgbRectHorizontalMirror = ${
|
"initRgbCamera isMirror = ${isMirror}, isDrawRgbRectHorizontalMirror = ${
|
||||||
ConfigUtil.isDrawRgbRectHorizontalMirror(
|
ConfigUtil.isDrawRgbRectHorizontalMirror(
|
||||||
context
|
context
|
||||||
@@ -486,8 +443,6 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
currentPlateInfo = null
|
currentPlateInfo = null
|
||||||
currentUserId = null
|
currentUserId = null
|
||||||
userFaceInfo = null
|
userFaceInfo = null
|
||||||
// checkFaceJob?.cancel()
|
|
||||||
// getFaceJob?.cancel()
|
|
||||||
}
|
}
|
||||||
recognizeViewModel.clearLeftFace(facePreviewInfoList)
|
recognizeViewModel.clearLeftFace(facePreviewInfoList)
|
||||||
}
|
}
|
||||||
@@ -552,7 +507,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
|
|
||||||
|
|
||||||
override fun onGlobalLayout() {
|
override fun onGlobalLayout() {
|
||||||
Timber.d("onGlobalLayout")
|
loadLogInfo("onGlobalLayout")
|
||||||
binding.dualCameraTexturePreviewRgb.getViewTreeObserver().removeOnGlobalLayoutListener(this)
|
binding.dualCameraTexturePreviewRgb.getViewTreeObserver().removeOnGlobalLayoutListener(this)
|
||||||
// 请求权限
|
// 请求权限
|
||||||
checkCameraPermission()
|
checkCameraPermission()
|
||||||
@@ -561,7 +516,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
private fun resumeCamera() {
|
private fun resumeCamera() {
|
||||||
isRecognition = true
|
isRecognition = true
|
||||||
if (rgbCameraHelper != null && rgbCameraHelper!!.isStopped) {
|
if (rgbCameraHelper != null && rgbCameraHelper!!.isStopped) {
|
||||||
Log.d(TAG, "collectFace,resumeCamera: ")
|
loadLogInfo("collectFace,resumeCamera: ")
|
||||||
rgbCameraHelper!!.start()
|
rgbCameraHelper!!.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -620,7 +575,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
fun initCountTime() {
|
fun initCountTime() {
|
||||||
countDownTimer = object : CountDownTimer(totalTimeInMillis, 1000) {
|
countDownTimer = object : CountDownTimer(totalTimeInMillis, 1000) {
|
||||||
override fun onTick(millisUntilFinished: Long) {
|
override fun onTick(millisUntilFinished: Long) {
|
||||||
Timber.d("initCountTime onTick = ${(millisUntilFinished / 1000).toInt()}")
|
loadLogInfo("initCountTime onTick = ${(millisUntilFinished / 1000).toInt()}")
|
||||||
binding.tvToInit.text = "${(millisUntilFinished / 1000).toInt() + 1}"
|
binding.tvToInit.text = "${(millisUntilFinished / 1000).toInt() + 1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -639,40 +594,15 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
loadLogInfo("collectFace: -----------1,开始采集人脸,开始时间:${DateTimeUtils.getDateTimeString()}----------")
|
loadLogInfo("collectFace: -----------1,开始采集人脸,开始时间:${DateTimeUtils.getDateTimeString()}----------")
|
||||||
if (isFirstOpen) return
|
if (isFirstOpen) return
|
||||||
loadLogInfo("collectFace: ----------2,isFirstOpen=false-----------")
|
loadLogInfo("collectFace: ----------2,isFirstOpen=false-----------")
|
||||||
// if (facePreviewInfoList.isNullOrEmpty()) {
|
|
||||||
// loadLogInfo("collectFace: ----------3,未检测到人脸信息-----------")
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
loadLogInfo("collectFace: ----------4,检测到人脸信息-----------")
|
loadLogInfo("collectFace: ----------4,检测到人脸信息-----------")
|
||||||
currentUserId = null
|
currentUserId = null
|
||||||
userFaceInfo = null
|
userFaceInfo = null
|
||||||
recognizeViewModel.updateRegisterStatus(REGISTER_STATUS_READY)
|
recognizeViewModel.updateRegisterStatus(REGISTER_STATUS_READY)
|
||||||
loadLogInfo("collectFace: ----------5,人脸采集中-----------")
|
loadLogInfo("collectFace: ----------5,人脸采集中-----------")
|
||||||
// getFaceData { faceData ->
|
|
||||||
// if (faceDataList.isNotEmpty()) {
|
|
||||||
// return@getFaceData
|
|
||||||
// }
|
|
||||||
// faceDataList.add(faceData)
|
|
||||||
//
|
|
||||||
// checkFaceScheduler?.shutdown()
|
|
||||||
// getFaceScheduler?.shutdown()
|
|
||||||
// recognizeViewModel.updateRegisterStatus(RecognizeViewModel.REGISTER_STATUS_DONE)
|
|
||||||
// Thread {
|
|
||||||
//// val faceDao = FaceDatabase.getInstance(App.getContext()).faceDao()
|
|
||||||
//// val entity = faceDao.queryByUserName(tempUserId)
|
|
||||||
//// if (entity != null) {
|
|
||||||
//// //已存在用户
|
|
||||||
//// loadLogInfo("collectFace,saveFaceInfo: ----------9,数据库已存在该人脸数据-----------")
|
|
||||||
//// return@Thread
|
|
||||||
//// }
|
|
||||||
// saveFaceInfo(faceData)
|
|
||||||
// }.start()
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendFaceData(faceData: String) {
|
private fun sendFaceData(faceData: String) {
|
||||||
loadLogInfo("collectFace,sendFaceData: ----------11,发生人脸数据-----------")
|
loadLogInfo("collectFace,sendFaceData: ----------11,发送人脸数据-----------")
|
||||||
Log.d(TAG, "collectFace,sendFaceData: ---------------------------")
|
|
||||||
// 给某个客户端发送
|
// 给某个客户端发送
|
||||||
val jsonObject = JSONObject().also {
|
val jsonObject = JSONObject().also {
|
||||||
it.put("type", "faceFeature")
|
it.put("type", "faceFeature")
|
||||||
@@ -689,22 +619,6 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
checkFaceScheduler = Executors.newScheduledThreadPool(1)
|
checkFaceScheduler = Executors.newScheduledThreadPool(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun getFaceData(block: (String) -> Unit) {
|
|
||||||
// getFaceScheduler?.scheduleWithFixedDelay(
|
|
||||||
// {
|
|
||||||
// getFaceDataBlock(block)
|
|
||||||
// }, 5L, 5L, TimeUnit.MILLISECONDS
|
|
||||||
// )
|
|
||||||
// runBlocking {
|
|
||||||
// getFaceJob = executor.startIntervalTask(5) {
|
|
||||||
|
|
||||||
// getFaceJob?.cancel()
|
|
||||||
// checkFaceJob?.cancel()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getFaceDataBlock(block: (String) -> Unit) {
|
private fun getFaceDataBlock(block: (String) -> Unit) {
|
||||||
if (userFaceInfo == null || userFaceInfo?.faceFeature?.featureData == null) {
|
if (userFaceInfo == null || userFaceInfo?.faceFeature?.featureData == null) {
|
||||||
return
|
return
|
||||||
@@ -713,49 +627,23 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
if (faceData.isNullOrBlank()) {
|
if (faceData.isNullOrBlank()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
loadLogInfo("collectFace,getFaceData: ----------7,拿到人脸取特征数据-----------")
|
loadLogInfo("collectFace,getFaceData: ----------7,拿到人脸提取特征数据-----------")
|
||||||
block(faceData)
|
block(faceData)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var faceDataList: MutableList<String> = mutableListOf()
|
private var faceDataList: MutableList<String> = mutableListOf()
|
||||||
|
|
||||||
private fun loadLogInfo(msg: String) {
|
private fun loadLogInfo(msg: String) {
|
||||||
Log.d(TAG, msg)
|
Timber.tag(TAG).d( msg)
|
||||||
// logAdapter.addData(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var facePreviewInfoList: MutableList<FacePreviewInfo>? = null
|
private var facePreviewInfoList: MutableList<FacePreviewInfo>? = null
|
||||||
private var userFaceInfo: UserFaceInfo? = null
|
private var userFaceInfo: UserFaceInfo? = null
|
||||||
private var countDownJob: Job? = null
|
|
||||||
|
|
||||||
// private var getFaceJob: Job? = null
|
|
||||||
val executor = IntervalExecutor()
|
|
||||||
private var currentUserId: String? = null
|
private var currentUserId: String? = null
|
||||||
private fun countDown() {
|
|
||||||
// countDownJob = countDownByFlow(
|
|
||||||
// total = 3,
|
|
||||||
// scope = lifecycleScope,
|
|
||||||
// onStart = {
|
|
||||||
// binding.tvCollectState.text = "采集完成(3s)"
|
|
||||||
// },
|
|
||||||
// onTick = { seconds ->
|
|
||||||
// binding.tvCollectState.text = "采集完成(${seconds}s)"
|
|
||||||
// },
|
|
||||||
// onFinish = {
|
|
||||||
// //binding.tvCollectState.text = "采集完成"
|
|
||||||
// currentUserId = null
|
|
||||||
// binding.layoutState.invisible()
|
|
||||||
//// binding.tvFaceTip.visible()
|
|
||||||
// binding.btnCollectFace.visible()
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun saveFaceInfo(faceData: String) {
|
private fun saveFaceInfo(faceData: String) {
|
||||||
try {
|
try {
|
||||||
// getFaceJob?.cancel()
|
|
||||||
// checkFaceJob?.cancel()
|
|
||||||
|
|
||||||
sendFaceData(faceData)
|
sendFaceData(faceData)
|
||||||
loadLogInfo("collectFace,saveFaceInfo: ----------12,人脸数据发送完成时间:${DateTimeUtils.getDateTimeString()}-----------")
|
loadLogInfo("collectFace,saveFaceInfo: ----------12,人脸数据发送完成时间:${DateTimeUtils.getDateTimeString()}-----------")
|
||||||
|
|
||||||
@@ -782,12 +670,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
loadLogInfo("collectFace,saveFaceInfo: ----------13,人脸采集异常:${e.message}-----------")
|
loadLogInfo("collectFace,saveFaceInfo: ----------13,人脸采集异常:${e.message}-----------")
|
||||||
collectCount++
|
collectCount++
|
||||||
// if (collectCount <= 5) {
|
|
||||||
// collectFace()
|
|
||||||
// } else {
|
|
||||||
loadLogInfo("collectFace,saveFaceInfo: ----------14,${collectCount}次人脸采集异常:${e.message}-----------")
|
loadLogInfo("collectFace,saveFaceInfo: ----------14,${collectCount}次人脸采集异常:${e.message}-----------")
|
||||||
ToastUtils.showToast("人脸采集异常:${e.message}")
|
ToastUtils.showToast("人脸采集异常:${e.message}")
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -796,8 +680,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
private var tcpClient: TcpClient? = null
|
private var tcpClient: TcpClient? = null
|
||||||
|
|
||||||
private fun addSocketListener() {
|
private fun addSocketListener() {
|
||||||
//val ipAddress = NetworkUtils.getIPAddress(true)
|
// val ipAddress = NetworkUtils.getIPAddress(true)
|
||||||
//Log.d(TAG, "addSocketListener,ipAddress: $ipAddress");
|
// loadLogInfo( "addSocketListener,ipAddress: $ipAddress");
|
||||||
tcpClient = TcpClient(
|
tcpClient = TcpClient(
|
||||||
"192.168.1.95",
|
"192.168.1.95",
|
||||||
5000,
|
5000,
|
||||||
@@ -810,25 +694,25 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
tcpClient?.setListener(object : TcpClientListenerImpl() {
|
tcpClient?.setListener(object : TcpClientListenerImpl() {
|
||||||
override fun onSendSuccess(json: JSONObject?) {
|
override fun onSendSuccess(json: JSONObject?) {
|
||||||
super.onSendSuccess(json)
|
super.onSendSuccess(json)
|
||||||
loadLogInfo("TcpClientListener发送成功:$json")
|
loadLogInfo("collectFace,TcpClientListener发送成功:$json")
|
||||||
// toast("发送成功")
|
// toast("发送成功")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSendFailed(json: JSONObject?, e: java.lang.Exception?) {
|
override fun onSendFailed(json: JSONObject?, e: java.lang.Exception?) {
|
||||||
super.onSendFailed(json, e)
|
super.onSendFailed(json, e)
|
||||||
ToastUtils.showToast("发送失败${e?.message}")
|
ToastUtils.showToast("发送失败${e?.message}")
|
||||||
loadLogInfo("TcpClientListener人脸数据发送失败:${e?.message}")
|
loadLogInfo("collectFace,TcpClientListener人脸数据发送失败:${e?.message}")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMessage(json: JSONObject?) {
|
override fun onMessage(json: JSONObject?) {
|
||||||
super.onMessage(json)
|
super.onMessage(json)
|
||||||
loadLogInfo("TcpClientListener收到消息:$json")
|
loadLogInfo("collectFace,TcpClientListener收到消息:$json")
|
||||||
val type = json?.getInt("type")
|
val type = json?.getInt("type")
|
||||||
// 根据服务端消息类型处理删除新增临时用户人脸数据---------------------
|
// 根据服务端消息类型处理删除新增临时用户人脸数据---------------------
|
||||||
when (type) {
|
when (type) {
|
||||||
LanServer.TYPE_ADD_FACE_DATA -> {
|
LanServer.TYPE_ADD_FACE_DATA -> {
|
||||||
//采集设备id自己生成,不接收服务端的,在本地只判断是否存在同一人脸数据
|
//采集设备id自己生成,不接收服务端的,在本地只判断是否存在同一人脸数据
|
||||||
loadLogInfo("TcpClientListener收到消息,新增用户:采集设备id自己生成,不接收服务端的,在本地只判断是否存在同一人脸数据")
|
loadLogInfo("collectFace,TcpClientListener收到消息,新增用户:采集设备id自己生成,不接收服务端的,在本地只判断是否存在同一人脸数据")
|
||||||
}
|
}
|
||||||
|
|
||||||
LanServer.TYPE_CLEAR_FACE_DATA -> {
|
LanServer.TYPE_CLEAR_FACE_DATA -> {
|
||||||
@@ -839,7 +723,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
tcpClient?.start();
|
tcpClient?.start()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LanServer.getInstance().let {
|
LanServer.getInstance().let {
|
||||||
@@ -861,14 +745,13 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
||||||
faceDao.deleteTempUserFaceData()
|
faceDao.deleteTempUserFaceData()
|
||||||
recognizeViewModel.refreshFaceList()
|
recognizeViewModel.refreshFaceList()
|
||||||
loadLogInfo("TcpClientListener收到消息,已删除并刷新人脸数据")
|
loadLogInfo("collectFace,TcpClientListener收到消息,已删除并刷新人脸数据")
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val WAITING_TIME = 3 * 1000L
|
private val WAITING_TIME = 3 * 1000L
|
||||||
private var checkStartTime = 0L
|
private var checkStartTime = 0L
|
||||||
|
|
||||||
// private var checkFaceJob: Job? = null
|
|
||||||
private fun checkFaceState() {
|
private fun checkFaceState() {
|
||||||
checkStartTime = System.currentTimeMillis()
|
checkStartTime = System.currentTimeMillis()
|
||||||
|
|
||||||
@@ -877,16 +760,11 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
checkFaceBlock()
|
checkFaceBlock()
|
||||||
}, 5L, 5L, TimeUnit.MILLISECONDS
|
}, 5L, 5L, TimeUnit.MILLISECONDS
|
||||||
)
|
)
|
||||||
|
|
||||||
// checkFaceJob = executor.startIntervalTask(5) {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
private var isCollectFace = false
|
private var isCollectFace = false
|
||||||
private fun checkFaceBlock() {
|
private fun checkFaceBlock() {
|
||||||
Log.d("Login", "collectFace,currentUserId=${currentUserId}")
|
loadLogInfo("collectFace,currentUserId=${currentUserId}")
|
||||||
if (currentUserId.isNullOrBlank().not()) {
|
if (currentUserId.isNullOrBlank().not()) {
|
||||||
// checkFaceJob?.cancel()
|
|
||||||
isCollectFace = false
|
isCollectFace = false
|
||||||
|
|
||||||
checkFaceScheduler?.shutdown()
|
checkFaceScheduler?.shutdown()
|
||||||
|
|||||||
@@ -660,6 +660,7 @@ public class FaceHelper implements FaceListener {
|
|||||||
}
|
}
|
||||||
compareResult.setTrackId(trackId);
|
compareResult.setTrackId(trackId);
|
||||||
boolean pass = compareResult.getSimilar() > recognizeConfiguration.getSimilarThreshold();
|
boolean pass = compareResult.getSimilar() > recognizeConfiguration.getSimilarThreshold();
|
||||||
|
Log.d(TAG, "collectFace,searchFace: pass="+pass+",similar="+compareResult.getSimilar()+",threshold="+recognizeConfiguration.getSimilarThreshold());
|
||||||
recognizeCallback.onRecognized(compareResult, getRecognizeInfo(recognizeInfoMap, trackId).getLiveness(), pass);
|
recognizeCallback.onRecognized(compareResult, getRecognizeInfo(recognizeInfoMap, trackId).getLiveness(), pass);
|
||||||
if (pass) {
|
if (pass) {
|
||||||
setName(trackId, "识别通过");
|
setName(trackId, "识别通过");
|
||||||
|
|||||||
+10
-2
@@ -469,10 +469,18 @@ public class RecognizeViewModel extends ViewModel implements RecognizeCallback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getUserId(CompareResult result){
|
||||||
|
if (result != null && result.getFaceEntity() != null) {
|
||||||
|
return result.getFaceEntity().getUserName();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRecognized(CompareResult compareResult, Integer live, boolean similarPass) {
|
public void onRecognized(CompareResult compareResult, Integer live, boolean similarPass) {
|
||||||
Disposable disposable = Observable.just(true).observeOn(AndroidSchedulers.mainThread()).subscribe(aBoolean -> {
|
// TODO: 2026/1/21 测试使用 Observable.just(similarPass)代替Observable.just(true)---
|
||||||
Log.d(TAG, "onRecognized: similarPass="+similarPass);
|
Observable.just(similarPass).observeOn(AndroidSchedulers.mainThread()).subscribe(aBoolean -> {
|
||||||
|
Log.d(TAG, "collectFace,onRecognized: similarPass="+similarPass+",live="+live+",userId="+getUserId(compareResult));
|
||||||
if (similarPass) {
|
if (similarPass) {
|
||||||
recognizeUserId.postValue(compareResult);
|
recognizeUserId.postValue(compareResult);
|
||||||
boolean isAdded = false;
|
boolean isAdded = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user