提交历史代码
This commit is contained in:
@@ -67,6 +67,9 @@ import com.sw.plate.utils.arcface.facedb.entity.FaceEntity
|
|||||||
import com.sw.plate.utils.arcface.model.UserFaceInfo
|
import com.sw.plate.utils.arcface.model.UserFaceInfo
|
||||||
import com.sw.plate.utils.arcface.viewmodel.RecognizeViewModel
|
import com.sw.plate.utils.arcface.viewmodel.RecognizeViewModel
|
||||||
import com.sw.plate.utils.arcface.viewmodel.RecognizeViewModel.REGISTER_STATUS_READY
|
import com.sw.plate.utils.arcface.viewmodel.RecognizeViewModel.REGISTER_STATUS_READY
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.Arrays
|
import java.util.Arrays
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
@@ -123,6 +126,16 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), ViewTreeObserver.OnGlo
|
|||||||
//重新识别按钮
|
//重新识别按钮
|
||||||
resetRecognizeState()
|
resetRecognizeState()
|
||||||
}
|
}
|
||||||
|
binding.btnClear.setOnClickListener {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
val faceDao = FaceDatabase.getInstance(this@MainActivity).faceDao()
|
||||||
|
faceDao.deleteAll()
|
||||||
|
faceDao.resetId()
|
||||||
|
ToastUtils.showToast("已完成")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkCameraPermission() {
|
private fun checkCameraPermission() {
|
||||||
@@ -727,7 +740,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), ViewTreeObserver.OnGlo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// // 调用示例:构造 1920×1080 的全黑帧(长度 1382400)
|
// // 调用示例:构造 1920×1080 的全黑帧(长度 1382400)
|
||||||
val emptyFrame = createBlackNV21Frame(1920, 1080)
|
// val emptyFrame = createBlackNV21Frame(1920, 1080)
|
||||||
|
private val emptyFrame = createBlackNV21Frame(1280, 720)
|
||||||
// // 传递“空帧”
|
// // 传递“空帧”
|
||||||
// recognizeViewModel.onPreviewFrame(emptyFrame, true)
|
// recognizeViewModel.onPreviewFrame(emptyFrame, true)
|
||||||
|
|
||||||
@@ -806,7 +820,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), ViewTreeObserver.OnGlo
|
|||||||
|
|
||||||
private fun judgeRecognizeState(): Boolean {
|
private fun judgeRecognizeState(): Boolean {
|
||||||
val rectColor = binding.dualCameraFaceRectView.rectColor
|
val rectColor = binding.dualCameraFaceRectView.rectColor
|
||||||
if (rectColor == RecognizeColor.COLOR_SUCCESS && currentUserId.isNullOrBlank().not() && facePreviewInfoList.isNullOrEmpty().not()) {
|
if (rectColor == RecognizeColor.COLOR_SUCCESS && currentUserId.isNullOrBlank()
|
||||||
|
.not() && facePreviewInfoList.isNullOrEmpty().not()
|
||||||
|
) {
|
||||||
loadLogInfo("userId=$currentUserId")
|
loadLogInfo("userId=$currentUserId")
|
||||||
openPlateDebouncer.debounce {
|
openPlateDebouncer.debounce {
|
||||||
openPlate(currentUserId)
|
openPlate(currentUserId)
|
||||||
@@ -922,14 +938,24 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), ViewTreeObserver.OnGlo
|
|||||||
//1-会员、2-临时用户
|
//1-会员、2-临时用户
|
||||||
it.userType = if (faceModel.isMember) "1" else "2"
|
it.userType = if (faceModel.isMember) "1" else "2"
|
||||||
}
|
}
|
||||||
faceDao.insert(faceEntity)
|
val faceId = faceDao.insert(faceEntity)
|
||||||
loadLogInfo("collectFace,saveFaceInfo: ----------10,人脸数据保存完成-----------")
|
loadLogInfo("collectFace,saveFaceInfo: ----------10,人脸数据保存完成-----------")
|
||||||
recognizeViewModel.refreshFaceList()
|
// recognizeViewModel.refreshFaceList(true)
|
||||||
|
faceEntity.faceId = faceId
|
||||||
|
recognizeViewModel.addFace(faceEntity)
|
||||||
|
ToastUtils.showToast("faceCount = ${faceDao.faceCount}")
|
||||||
|
// recognizeViewModel.registerFace()
|
||||||
loadLogInfo("collectFace,saveFaceInfo: ----------11,刷新人脸数据-----------")
|
loadLogInfo("collectFace,saveFaceInfo: ----------11,刷新人脸数据-----------")
|
||||||
runOnUiThread {
|
// runOnUiThread {
|
||||||
// recognizeViewModel.onPreviewFrame(ByteArray(1382400), true)
|
//// recognizeViewModel.onPreviewFrame(ByteArray(1382400), true)
|
||||||
recognizeViewModel.onPreviewFrame(emptyFrame, true)
|
// binding.dualCameraFaceRectView.clearFaceInfo()
|
||||||
}
|
// recognizeViewModel.clearLeftFace(facePreviewInfoList)
|
||||||
|
// recognizeViewModel.onPreviewFrame(emptyFrame, true)
|
||||||
|
// isRecognition = false
|
||||||
|
// binding.root.postDelayed({
|
||||||
|
// isRecognition = true
|
||||||
|
// }, 1000)
|
||||||
|
// }
|
||||||
loadLogInfo("---------------------------------")
|
loadLogInfo("---------------------------------")
|
||||||
collectCount = 0
|
collectCount = 0
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
@@ -215,4 +215,15 @@
|
|||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/btnClear"
|
||||||
|
android:layout_width="160dp"
|
||||||
|
android:layout_height="80dp"
|
||||||
|
android:text="清除数据"
|
||||||
|
android:textSize="26sp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:layout_gravity="start|bottom"/>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
@@ -621,4 +621,10 @@ public class FaceServer {
|
|||||||
rect.inset(-padding, -padding);
|
rect.inset(-padding, -padding);
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void registerFace(Context context, FaceEngine frEngine) {
|
||||||
|
List<FaceEntity> faceEntityList = FaceDatabase.getInstance(context).faceDao().getAllFaces();
|
||||||
|
registerFaceFeatureInfoListFromDb(frEngine, faceEntityList);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-1
@@ -347,7 +347,14 @@ public class RecognizeViewModel extends ViewModel implements RecognizeCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void refreshFaceList() {
|
public void refreshFaceList() {
|
||||||
FaceServer.getInstance().initFaceList(App.getContext(), frEngine, faceCount -> loadFaceList = true, true);
|
refreshFaceList(true);
|
||||||
|
}
|
||||||
|
public void refreshFaceList(boolean recognize) {
|
||||||
|
loadFaceList = false;
|
||||||
|
FaceServer.getInstance().initFaceList(App.getContext(), frEngine, faceCount -> {
|
||||||
|
Log.i(TAG, "unInitEngine: faceCount=" + faceCount);
|
||||||
|
loadFaceList = true;
|
||||||
|
}, recognize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -674,4 +681,12 @@ public class RecognizeViewModel extends ViewModel implements RecognizeCallback {
|
|||||||
String[] size = ConfigUtil.getPreviewSize(App.getContext()).split("x");
|
String[] size = ConfigUtil.getPreviewSize(App.getContext()).split("x");
|
||||||
return new Point(Integer.parseInt(size[0]), Integer.parseInt(size[1]));
|
return new Point(Integer.parseInt(size[0]), Integer.parseInt(size[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void registerFace() {
|
||||||
|
FaceServer.getInstance().registerFace(App.getContext(), frEngine);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearAllFaces() {
|
||||||
|
FaceServer.getInstance().clearAllFaces();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user