优化
This commit is contained in:
@@ -245,9 +245,15 @@ 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}")
|
loadLogInfo("collectFace,recognizeUserId observe userId = ${result?.faceEntity?.userName}")
|
||||||
|
if (result?.faceEntity == null) {
|
||||||
|
loadLogInfo("collectFace,recognizeUserId 未识别到人脸信息,开始采集")
|
||||||
|
isCollectFace = true
|
||||||
|
collectFace()
|
||||||
|
return@Observer
|
||||||
|
}
|
||||||
currentUserId = result?.faceEntity?.userName
|
currentUserId = result?.faceEntity?.userName
|
||||||
plateEnable = true
|
// plateEnable = true
|
||||||
openPlate(currentUserId)
|
openPlate(currentUserId)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -266,7 +272,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var currentPlateInfo: EquipmentUserInfo? = null
|
private var currentPlateInfo: EquipmentUserInfo? = null
|
||||||
private var plateEnable = true
|
private var plateEnable = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打开餐盘柜
|
* 打开餐盘柜
|
||||||
@@ -290,15 +296,19 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
item.faceId = userId
|
item.faceId = userId
|
||||||
item.updateTime = DateTimeUtils.getDateTimeString()
|
item.updateTime = DateTimeUtils.getDateTimeString()
|
||||||
item.plateNumber = null
|
item.plateNumber = null
|
||||||
|
plateEnable = false
|
||||||
|
debouncer.debounce {
|
||||||
//打开柜子
|
//打开柜子
|
||||||
PlateUtils.open(this, item.equipmentBoxCode, false)
|
PlateUtils.open(this, item.equipmentBoxCode, false)
|
||||||
plateEnable = false
|
}
|
||||||
currentPlateInfo = item
|
currentPlateInfo = item
|
||||||
MyApp.plateList = items
|
MyApp.plateList = items
|
||||||
SpTool.savePlateData(items)
|
SpTool.savePlateData(items)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val debouncer by lazy { Debouncer(3000) }
|
||||||
|
|
||||||
private fun initArcView() {
|
private fun initArcView() {
|
||||||
//在布局结束后才做初始化操作
|
//在布局结束后才做初始化操作
|
||||||
binding.dualCameraTexturePreviewRgb.getViewTreeObserver().addOnGlobalLayoutListener(this)
|
binding.dualCameraTexturePreviewRgb.getViewTreeObserver().addOnGlobalLayoutListener(this)
|
||||||
@@ -317,7 +327,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
|
|
||||||
EventBus.getDefault().unregister(this)
|
EventBus.getDefault().unregister(this)
|
||||||
// getFaceScheduler?.shutdown()
|
// getFaceScheduler?.shutdown()
|
||||||
checkFaceScheduler?.shutdown()
|
// checkFaceScheduler?.shutdown()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,6 +528,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
if (rgbCameraHelper != null && rgbCameraHelper!!.isStopped) {
|
if (rgbCameraHelper != null && rgbCameraHelper!!.isStopped) {
|
||||||
loadLogInfo("collectFace,resumeCamera: ")
|
loadLogInfo("collectFace,resumeCamera: ")
|
||||||
rgbCameraHelper!!.start()
|
rgbCameraHelper!!.start()
|
||||||
|
} else {
|
||||||
|
recognizeViewModel.onPreviewFrame(ByteArray(1382400), true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,7 +547,6 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}, 1000)
|
}, 1000)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
faceDataList.clear()
|
|
||||||
isCollectFace = false
|
isCollectFace = false
|
||||||
plateEnable = true
|
plateEnable = true
|
||||||
collectCount = 0
|
collectCount = 0
|
||||||
@@ -546,8 +557,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
it.cancel()
|
it.cancel()
|
||||||
it.start()
|
it.start()
|
||||||
}
|
}
|
||||||
initFaceScheduler()
|
// initFaceScheduler()
|
||||||
checkFaceState()
|
// checkFaceState()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
@@ -612,12 +623,12 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
// private var getFaceScheduler: ScheduledExecutorService? = null
|
// private var getFaceScheduler: ScheduledExecutorService? = null
|
||||||
private var checkFaceScheduler: ScheduledExecutorService? = null
|
// private var checkFaceScheduler: ScheduledExecutorService? = null
|
||||||
|
//
|
||||||
private fun initFaceScheduler() {
|
// private fun initFaceScheduler() {
|
||||||
// getFaceScheduler = Executors.newScheduledThreadPool(1)
|
//// getFaceScheduler = Executors.newScheduledThreadPool(1)
|
||||||
checkFaceScheduler = Executors.newScheduledThreadPool(1)
|
// checkFaceScheduler = Executors.newScheduledThreadPool(1)
|
||||||
}
|
// }
|
||||||
|
|
||||||
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) {
|
||||||
@@ -631,8 +642,6 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
block(faceData)
|
block(faceData)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var faceDataList: MutableList<String> = mutableListOf()
|
|
||||||
|
|
||||||
private fun loadLogInfo(msg: String) {
|
private fun loadLogInfo(msg: String) {
|
||||||
Timber.tag(TAG).d( msg)
|
Timber.tag(TAG).d( msg)
|
||||||
}
|
}
|
||||||
@@ -647,9 +656,9 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
sendFaceData(faceData)
|
sendFaceData(faceData)
|
||||||
loadLogInfo("collectFace,saveFaceInfo: ----------12,人脸数据发送完成时间:${DateTimeUtils.getDateTimeString()}-----------")
|
loadLogInfo("collectFace,saveFaceInfo: ----------12,人脸数据发送完成时间:${DateTimeUtils.getDateTimeString()}-----------")
|
||||||
|
|
||||||
runOnUiThread {
|
// runOnUiThread {
|
||||||
openPlate(tempUserId)
|
// openPlate(tempUserId)
|
||||||
}
|
// }
|
||||||
|
|
||||||
loadLogInfo("collectFace,saveFaceInfo: ----------8,保存人脸取特征数据-----------")
|
loadLogInfo("collectFace,saveFaceInfo: ----------8,保存人脸取特征数据-----------")
|
||||||
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
||||||
@@ -664,6 +673,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
loadLogInfo("collectFace,saveFaceInfo: ----------10,人脸数据保存完成-----------")
|
loadLogInfo("collectFace,saveFaceInfo: ----------10,人脸数据保存完成-----------")
|
||||||
recognizeViewModel.refreshFaceList()
|
recognizeViewModel.refreshFaceList()
|
||||||
loadLogInfo("collectFace,saveFaceInfo: ----------11,刷新人脸数据-----------")
|
loadLogInfo("collectFace,saveFaceInfo: ----------11,刷新人脸数据-----------")
|
||||||
|
runOnUiThread { recognizeViewModel.onPreviewFrame(ByteArray(1382400), true) }
|
||||||
loadLogInfo("---------------------------------")
|
loadLogInfo("---------------------------------")
|
||||||
collectCount = 0
|
collectCount = 0
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -749,33 +759,33 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val WAITING_TIME = 3 * 1000L
|
// private val WAITING_TIME = 3 * 1000L
|
||||||
private var checkStartTime = 0L
|
// private var checkStartTime = 0L
|
||||||
|
|
||||||
private fun checkFaceState() {
|
private fun checkFaceState() {
|
||||||
checkStartTime = System.currentTimeMillis()
|
// checkStartTime = System.currentTimeMillis()
|
||||||
|
//
|
||||||
checkFaceScheduler?.scheduleWithFixedDelay(
|
// checkFaceScheduler?.scheduleWithFixedDelay(
|
||||||
{
|
// {
|
||||||
checkFaceBlock()
|
// checkFaceBlock()
|
||||||
}, 5L, 5L, TimeUnit.MILLISECONDS
|
// }, 5L, 5L, TimeUnit.MILLISECONDS
|
||||||
)
|
// )
|
||||||
}
|
}
|
||||||
private var isCollectFace = false
|
private var isCollectFace = false
|
||||||
private fun checkFaceBlock() {
|
// private fun checkFaceBlock() {
|
||||||
loadLogInfo("collectFace,currentUserId=${currentUserId}")
|
// loadLogInfo("collectFace,currentUserId=${currentUserId}")
|
||||||
if (currentUserId.isNullOrBlank().not()) {
|
// if (currentUserId.isNullOrBlank().not()) {
|
||||||
isCollectFace = false
|
// isCollectFace = false
|
||||||
|
//
|
||||||
checkFaceScheduler?.shutdown()
|
// checkFaceScheduler?.shutdown()
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
if (System.currentTimeMillis() - checkStartTime >= WAITING_TIME) {
|
//// if (System.currentTimeMillis() - checkStartTime >= WAITING_TIME) {
|
||||||
//超过1秒采集人脸并识别
|
//// //超过1秒采集人脸并识别
|
||||||
checkFaceScheduler?.shutdown()
|
//// checkFaceScheduler?.shutdown()
|
||||||
isCollectFace = true
|
//// isCollectFace = true
|
||||||
collectFace()
|
//// collectFace()
|
||||||
}
|
//// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -652,9 +652,16 @@ public class FaceHelper implements FaceListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int failCount = 0;
|
||||||
private void searchFace(final FaceFeature faceFeature, final Integer trackId) {
|
private void searchFace(final FaceFeature faceFeature, final Integer trackId) {
|
||||||
CompareResult compareResult = FaceServer.getInstance().searchFaceFeature(faceFeature, frEngine);
|
CompareResult compareResult = FaceServer.getInstance().searchFaceFeature(faceFeature, frEngine);
|
||||||
if (compareResult == null || compareResult.getFaceEntity() == null) {
|
if (compareResult == null || compareResult.getFaceEntity() == null) {
|
||||||
|
failCount++;
|
||||||
|
Log.d(TAG, "collectFace,searchFace查询失败"+failCount+"次");
|
||||||
|
if (failCount >= 2) {
|
||||||
|
recognizeCallback.onRecognized(null, LivenessInfo.UNKNOWN, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
retryRecognizeDelayed(trackId);
|
retryRecognizeDelayed(trackId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -505,7 +505,7 @@ public class RecognizeViewModel extends ViewModel implements RecognizeCallback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// recognizeUserId.postValue(new CompareResult(null, 0f));
|
recognizeUserId.postValue(new CompareResult(null, -1f));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user