备份代码

This commit is contained in:
2026-02-03 17:02:28 +08:00
parent 2656e89244
commit c7cad6d8b5
7 changed files with 1067 additions and 42 deletions
+2
View File
@@ -79,4 +79,6 @@ dependencies {
implementation(libs.logging.interceptor)
// gson
implementation(libs.gson)
// implementation("com.google.android.material:flowlayout:1.12.0")
}
@@ -0,0 +1,887 @@
//package com.sw.face.collect
//
//import android.Manifest
//import android.content.Intent
//import android.content.pm.PackageManager
//import android.graphics.Point
//import android.hardware.Camera
//import android.util.Log
//import android.view.View
//import android.view.ViewGroup
//import android.view.ViewTreeObserver
//import android.widget.FrameLayout
//import androidx.activity.viewModels
//import androidx.core.content.ContextCompat
//import androidx.lifecycle.Observer
//import androidx.lifecycle.lifecycleScope
//import com.arcsoft.face.ErrorInfo
//import com.sw.face.collect.base.BaseActivity
//import com.sw.face.collect.base.GlobalData
//import com.sw.face.collect.databinding.ActivityMainBinding
//import com.sw.face.collect.ext.dp
//import com.sw.face.collect.ext.gone
//import com.sw.face.collect.ext.toast
//import com.sw.face.collect.ext.visible
//import com.sw.face.collect.model.UserFaceModel
//import com.sw.face.collect.socket.LanServer
//import com.sw.face.collect.socket.TcpClient
//import com.sw.face.collect.utils.Base64
//import com.sw.face.collect.utils.BitmapUtils
//import com.sw.face.collect.utils.FaceEngineUtils
//import com.sw.face.collect.utils.IntervalExecutor
//import com.sw.face.collect.utils.SpTool
//import com.sw.face.collect.utils.countDownByFlow
//import com.sw.face.collect.view.LanServerListenerImpl
//import com.sw.face.collect.view.TcpClientListenerImpl
//import com.sw.face.collect.viewmodel.MainViewModel
//import com.sw.plate.utils.L
//import com.sw.plate.utils.NV21ToBitmap
//import com.sw.plate.utils.ToastUtils
//import com.sw.plate.utils.arcface.ConfigUtil
//import com.sw.plate.utils.arcface.ErrorCodeUtil
//import com.sw.plate.utils.arcface.FaceRectTransformer
//import com.sw.plate.utils.arcface.FaceRectView
//import com.sw.plate.utils.arcface.FaceRectView.DrawInfo
//import com.sw.plate.utils.arcface.PreviewConfig
//import com.sw.plate.utils.arcface.camera.CameraListener
//import com.sw.plate.utils.arcface.camera.DualCameraHelper
//import com.sw.plate.utils.arcface.face.constants.LivenessType
//import com.sw.plate.utils.arcface.face.model.CompareResult
//import com.sw.plate.utils.arcface.face.model.FacePreviewInfo
//import com.sw.plate.utils.arcface.face.model.RecognizeConfiguration
//import com.sw.plate.utils.arcface.facedb.FaceDatabase
//import com.sw.plate.utils.arcface.facedb.entity.FaceEntity
//import com.sw.plate.utils.arcface.model.UserFaceInfo
//import com.sw.plate.utils.arcface.viewmodel.RecognizeViewModel
//import com.sw.plate.utils.arcface.viewmodel.RecognizeViewModel.REGISTER_STATUS_READY
//import kotlinx.coroutines.Job
//import kotlinx.coroutines.runBlocking
//import org.json.JSONObject
//import kotlin.getValue
//import kotlin.system.exitProcess
//
//class MainActivityBak2 : BaseActivity<ActivityMainBinding>(), ViewTreeObserver.OnGlobalLayoutListener {
// // private val debouncer = Debouncer(2000)
//
// companion object {
// private const val TAG = "MainActivity"
// }
//
// // 虹软人脸配置 ⬇
// private var isRecognition = false
// private var rgbCameraHelper: DualCameraHelper? = null
// private var rgbFaceRectTransformer: FaceRectTransformer? = null
//
// private var livenessType = LivenessType.IR
//
// // private val livenessType = LivenessType.RGB
// private var openRectInfoDraw = false
//
// private val nv21ToBitmap by lazy { NV21ToBitmap(this) }
//
// //
// private var irCameraHelper: DualCameraHelper? = null
// private var irFaceRectTransformer: FaceRectTransformer? = null
//
// private val recognizeViewModel: RecognizeViewModel by lazy { viewModels<RecognizeViewModel>().value }
//
// private val mainViewModel by viewModels<MainViewModel>()
//
// private var currentUserId: String? = null
// private var lastFaceTrackId = -1
//
// override fun inflateViewBinding() = ActivityMainBinding.inflate(layoutInflater)
//
// override fun onGlobalLayout() {
// Log.d(TAG, "onGlobalLayout")
// binding.dualCameraTexturePreviewRgb.getViewTreeObserver().removeOnGlobalLayoutListener(this)
// openCamera()
// }
//
// private var pageNo = 1
// override fun initialize() {
// super.initialize()
// mainViewModel.getUserFaceCache(pageNo = pageNo)
// FaceEngineUtils.activeEngine()
//
// binding.btnCollectFace.setOnClickListener {
// requestSinglePermissionResult(Manifest.permission.CAMERA) { granted ->
// if (granted.not()) {
// toast("没有相机权限")
// return@requestSinglePermissionResult
// }
// collectFace()
// }
// }
// binding.tvTitle.setOnClickListener { finish() }
// addSocketListener()
//
// binding.flFace.visible()
// binding.flRecognizeIr.visible()
// binding.flCameraView.visible()
// binding.tvFaceTip.visible()
// binding.layoutState.gone()
//
//// resumeCamera()
// startFaceTask()
// }
//
//
// private fun openCamera() {
// Log.d(TAG, "openCamera")
// if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) !=
// PackageManager.PERMISSION_GRANTED
// ) {
// toast("无摄像头权限")
// return
// }
// try {
//// val cameraCount = Camera.getNumberOfCameras()
//// if (cameraCount < 3) {
//// toast("摄像头数量异常"+cameraCount)
//// return
//// }
// recognizeViewModel.init(
// PreviewConfig(
// PreviewConfig.DEFAULT_IR_CAMERA_ID, PreviewConfig.DEFAULT_RGB_CAMERA_ID,
// 0, 0
// )
// )
// initRgbCamera()
// if (DualCameraHelper.hasDualCamera() && livenessType === LivenessType.IR) {
// initIrCamera()
// }
// } catch (e: Exception) {
// Log.d(TAG, "打开摄像头失败")
// toast("打开摄像头失败+${e.message}")
// }
// }
//
//
// /**
// * 启用虹软人脸识别
// */
// fun setupArcCamera() {
// initArcViewModel()
// initArcView()
// openRectInfoDraw = true
// }
//
// private fun sendFaceData(faceData: String) {
// // 给某个客户端发送
// val jsonObject = JSONObject().also {
// it.put("type", "faceFeature")
// it.put("content", faceData)
// }
// tcpClient?.send(jsonObject)
//
// // TODO: 保存采集的人脸数据,暂时生成id,实际id在结算终端生成并发送到各台设备
// saveFaceInfo(faceData)
// }
//
// private fun saveFaceInfo(faceData: String) {
// Thread {
// try {
// val tempId = "${System.currentTimeMillis()}-123456789"
// val faceEntity = FaceEntity(
// tempId,
// null,
// Base64.decode(faceData)
// ).also {
// it.userType = "2"
// }
// FaceDatabase.getInstance(this).faceDao().insert(faceEntity)
// recognizeViewModel.refreshFaceList();
// runOnUiThread {
// toast("你的人脸信息已采集")
// }
// } catch (e: Exception) {
// e.printStackTrace()
// }
// }.start()
// }
//
// private var tcpClient: TcpClient? = null
//
// private fun addSocketListener() {
// //val ipAddress = NetworkUtils.getIPAddress(true)
// //Log.d(TAG, "addSocketListener,ipAddress: $ipAddress");
// tcpClient = TcpClient(
// "192.168.1.95",
// 5000,
// GlobalData.deviceId, // clientId
// 5000, // connectTimeoutMs
// 10 * 1000, // heartbeatIntervalMs
// 30 * 1000 // heartbeatTimeoutMs
// )
//
// tcpClient?.setListener(object : TcpClientListenerImpl() {
// override fun onSendSuccess(json: JSONObject?) {
// super.onSendSuccess(json)
//// toast("发送成功")
// }
//
// override fun onSendFailed(json: JSONObject?, e: java.lang.Exception?) {
// super.onSendFailed(json, e)
// toast("发送失败${e?.message}")
// }
//
// override fun onMessage(json: JSONObject?) {
// super.onMessage(json)
//
// val type = json?.getInt("type")
// // 根据服务端消息类型处理删除新增临时用户人脸数据---------------------
// when (type) {
// LanServer.TYPE_ADD_FACE_DATA -> {
// //采集设备id自己生成,不接收服务端的,在本地只判断是否存在同一人脸数据
// }
// LanServer.TYPE_CLEAR_FACE_DATA -> {
// clearFaceData()
// }
// else-> {}
// }
// }
// })
// tcpClient?.start();
//
// try {
// LanServer.getInstance().let {
// it.setListener(object : LanServerListenerImpl() {
// override fun onMessageReceived(clientId: String?, message: JSONObject?) {
// super.onMessageReceived(clientId, message)
// toast("收到消息clientId=$clientId")
// }
// })
// it.start()
// }
// } catch (e: Exception) {
// e.printStackTrace()
// }
// }
//
// // private var imageBitmap: Bitmap? = null
// private fun collectFace() {
// //toast("currentUserId=$currentUserId")
// if (currentUserId != null) {
// toast("您已采集过人脸信息")
// return
// }
// currentUserId = null
// userFaceInfo = null
// recognizeViewModel.updateRegisterStatus(REGISTER_STATUS_READY)
// //showWaitingDialog("人脸信息中……")
//
// binding.tvFaceTip.gone()
// binding.btnCollectFace.gone()
// binding.layoutState.visible()
// binding.pbCollectLoading.visible()
// binding.tvCollectState.text = "采集中......"
// getFaceData { faceData ->
// Log.d(TAG, "faceData: $faceData")
// runOnUiThread {
// //hideWaitingDialog()
// //toast("人脸信息已采集")
// binding.pbCollectLoading.gone()
// //binding.tvCollectState.text = "采集完成"
// userFaceInfo = null
// countDown()
// }
// sendFaceData(faceData)
// }
// }
//
// private var job: Job? = null
//
// private fun getFaceData(block: (String) -> Unit) {
// runBlocking {
// job = executor.startIntervalTask(5) {
//// if (currentUserId != null && currentUserId!!.isNotBlank()) {
//// toast("您已采集过人脸信息")
//// return@startIntervalTask
//// }
// if (userFaceInfo == null) {
// return@startIntervalTask
// }
// val faceData = Base64.encode(userFaceInfo!!.faceFeature!!.featureData)
// block(faceData)
// job?.cancel()
// }
// }
//
// }
//
// val executor = IntervalExecutor()
//
//
// public override fun onStop() {
// rgbCameraHelper?.release()
// rgbCameraHelper = null
// irCameraHelper?.release()
// irCameraHelper = null
// recognizeViewModel.destroy()
// super.onStop()
// }
//
// fun resumeCamera() {
// Log.d(TAG, "resumeCamera isRecognition = $isRecognition")
// isRecognition = true
// if (rgbCameraHelper != null && rgbCameraHelper!!.isStopped) {
// rgbCameraHelper!!.start()
// }
// }
//
// fun pauseCamera() {
// Log.d(TAG, "pauseCamera isRecognition = $isRecognition")
// isRecognition = false
//
// recognizeViewModel.onPreviewFrame(ByteArray(1382400), true)
// }
//
// private var userFaceInfo: UserFaceInfo? = null
// private var isCheckCamera = false
// private fun initArcViewModel() {
// if (DualCameraHelper.hasDualCamera()) {
// livenessType = LivenessType.IR
// isCheckCamera = true
// } else {
// livenessType = LivenessType.RGB
// isCheckCamera = false
// }
// recognizeViewModel.setLiveType(livenessType)
//
// recognizeViewModel.prepareRegister()
// recognizeViewModel.setOnRegisterFinishedCallback { facePreviewInfo, userFaceInfo ->
// this.userFaceInfo = userFaceInfo
// Log.d(TAG, "initArcViewModel: userFaceInfo == null : ${userFaceInfo == null}")
// }
// recognizeViewModel.ftInitCode.observe(this, Observer { ftInitCode: Int? ->
// if (ftInitCode != ErrorInfo.MOK) {
// val error: String? = context.getString(
// R.string.specific_engine_init_failed, "ftEngine",
// ftInitCode, ErrorCodeUtil.arcFaceErrorCodeToFieldName(ftInitCode!!)
// )
// Log.d(TAG, "ftInitCode observe = $error")
// ToastUtils.showToast(error)
// }
// })
// recognizeViewModel.frInitCode.observe(this, Observer { frInitCode: Int? ->
// if (frInitCode != ErrorInfo.MOK) {
// val error: String? = context.getString(
// R.string.specific_engine_init_failed, "frEngine",
// frInitCode, ErrorCodeUtil.arcFaceErrorCodeToFieldName(frInitCode!!)
// )
// Log.d(TAG, "frInitCode observe = $error")
// ToastUtils.showToast(error)
// }
// })
// recognizeViewModel.flInitCode.observe(this, Observer { flInitCode: Int? ->
// if (flInitCode != ErrorInfo.MOK) {
// val error: String? = context.getString(
// R.string.specific_engine_init_failed, "flEngine",
// flInitCode, ErrorCodeUtil.arcFaceErrorCodeToFieldName(flInitCode!!)
// )
// Log.d(TAG, "flInitCode observe = $error")
// ToastUtils.showToast(error)
// }
// })
//
// recognizeViewModel.recognizeConfiguration
// .observe(this, Observer { recognizeConfiguration: RecognizeConfiguration? ->
// Log.d(TAG, "recognizeConfiguration: observe = ${recognizeConfiguration.toString()}")
// })
// recognizeViewModel.recognizeNotice.observe(this, Observer { notice: String? ->
// Log.d(TAG, "recognizeNotice observe notice = $notice")
// })
//
// recognizeViewModel.recognizeUserId.observe(
// this,
// Observer { compareResult: CompareResult ->
// Log.d(
// TAG,
// "recognizeUserId observe compareResult = ${compareResult.trackId}, userId = ${compareResult.faceEntity.userName}"
// )
// lastFaceTrackId = compareResult.trackId
// val faceEntity = compareResult.faceEntity
// currentUserId = faceEntity.userName
// if (!currentUserId.isNullOrBlank()) {
// toast("您已采集过人脸信息")
// return@Observer
// }
//// //未识别到,拍摄照片
//
// })
//
// recognizeViewModel.drawRectInfoText.observe(this, Observer { info ->
// Log.d(TAG, "drawRectInfoText observe info = $info")
// })
// }
//
// private fun initArcView() {
// //在布局结束后才做初始化操作
// binding.dualCameraTexturePreviewRgb.getViewTreeObserver().addOnGlobalLayoutListener(this)
// recognizeViewModel.getCompareResultList().getValue()
// }
//
// /**
// * 调整View的宽高,使预览显示正常且采集框固定为
// *
// * @param rgbPreview RGB预览View
// * @param previewView 显示预览数据的view
// * @param faceRectView 画框的view
// * @param previewSize 预览大小
// * @param displayOrientation 相机旋转角度
// * @param scale 缩放比例
// * @return 调整后的LayoutParams
// */
// private fun adjustPreviewViewSize(
// rgbPreview: View,
// previewView: View,
// faceRectView: FaceRectView,
// previewSize: Camera.Size,
// displayOrientation: Int,
// scale: Float
// ): ViewGroup.LayoutParams {
//// val w = 640.dp//300.dp
// val w = 640.dp//300.dp
// val h = 480.dp//510.dp
// val layoutParams = FrameLayout.LayoutParams(w, h);
// previewView.setLayoutParams(layoutParams)
// faceRectView.setLayoutParams(layoutParams)
//
// return layoutParams
// }
//
// private fun initRgbCamera() {
// val cameraListener: CameraListener = object : CameraListener {
// override fun onCameraOpened(
// camera: Camera,
// cameraId: Int,
// displayOrientation: Int,
// isMirror: Boolean
// ) {
// Log.d(
// TAG,
// "initRgbCamera Rgb onCameraOpened: cameraId = $cameraId, displayOrientation = $displayOrientation"
// )
// runOnUiThread({
// val previewSizeRgb = camera.getParameters().getPreviewSize()
// val layoutParams = adjustPreviewViewSize(
// binding.dualCameraTexturePreviewRgb,
// binding.dualCameraTexturePreviewRgb,
// binding.dualCameraFaceRectView,
// previewSizeRgb, displayOrientation,
// 0.5F
// //0.6F
// )
//
// Log.d(
// TAG,
// "initRgbCamera previewSizeRgb = ${previewSizeRgb.width}-${previewSizeRgb.height}"
// )
// Log.d(
// TAG,
// "initRgbCamera layoutParams = ${layoutParams.width}-${layoutParams.height}"
// )
// Log.d(
// TAG,
// "initRgbCamera isMirror = ${isMirror}, isDrawRgbRectHorizontalMirror = ${
// ConfigUtil.isDrawRgbRectHorizontalMirror(
// context
// )
// }, isDrawRgbRectVerticalMirror = ${
// ConfigUtil.isDrawRgbRectVerticalMirror(
// context
// )
// }"
// )
// // 调整识别窗口位置
// rgbFaceRectTransformer = FaceRectTransformer(
// previewSizeRgb.width,
// previewSizeRgb.height,
// layoutParams.width,
// layoutParams.height,
// displayOrientation,
//// 90,
// cameraId,
// isMirror,
// true,
// false
// )
//
// recognizeViewModel.onRgbCameraOpened(camera)
// recognizeViewModel.setRgbFaceRectTransformer(rgbFaceRectTransformer)
// })
// }
//
// override fun onPreview(nv21: ByteArray?, camera: Camera?) {
//// faceByteArray = nv21
// if (!isRecognition) {
// return
// }
// if (isCheckCamera) {
// L.e("检查摄像头数据")
//
// isCheckCamera = false
//
// val isBw: Boolean = BitmapUtils.isBlackWhite(
// nv21ToBitmap.nv21ToBitmap(
// nv21,
// rgbFaceRectTransformer!!.previewWidth,
// rgbFaceRectTransformer!!.previewHeight,
// 0
// )
// )
// if (isBw) {
// L.e("黑白切换摄像头")
// switchCamera()
// }
// L.e("摄像头正常")
// }
// binding.dualCameraFaceRectView.clearFaceInfo()
// val facePreviewInfoList: MutableList<FacePreviewInfo>? =
// recognizeViewModel.onPreviewFrame(nv21, true)
// if (facePreviewInfoList != null
// && rgbFaceRectTransformer != null
// ) {
// drawPreviewInfo(facePreviewInfoList)
// }
// recognizeViewModel.clearLeftFace(facePreviewInfoList)
// }
//
// override fun onCameraClosed() {
// Log.d(TAG, "initRgbCamera onCameraClosed: ")
// }
//
// override fun onCameraError(e: java.lang.Exception) {
// Log.d(TAG, "initRgbCamera onCameraError: ${e.message}")
// e.printStackTrace()
// }
//
// override fun onCameraConfigurationChanged(cameraID: Int, displayOrientation: Int) {
// Log.d(
// TAG,
// "initRgbCamera onCameraConfigurationChanged: threadName = ${Thread.currentThread().name}"
// )
// if (rgbFaceRectTransformer != null) {
// rgbFaceRectTransformer!!.cameraDisplayOrientation = displayOrientation
// }
// Log.d(
// TAG,
// "initRgbCamera onCameraConfigurationChanged: $cameraID $displayOrientation"
// )
// }
// }
// val measuredWidth = binding.dualCameraTexturePreviewRgb.measuredWidth
// val measuredHeight = binding.dualCameraTexturePreviewRgb.measuredHeight
// Log.d(TAG, "initRgbCamera measuredWidth=$measuredWidthmeasuredHeight=$measuredHeight")
//
// val previewConfig = recognizeViewModel.previewConfig
// rgbCameraHelper = DualCameraHelper.Builder()
// .previewViewSize(Point(measuredWidth, measuredHeight))
//// .previewViewSize(Point(608.dp, 456.dp))
//// .previewViewSize(Point(1024, 768))
// .rotation(windowManager.defaultDisplay.rotation)
// .additionalRotation(previewConfig.rgbAdditionalDisplayOrientation) // 角度
// .previewSize(recognizeViewModel.loadPreviewSize())
//// .previewSize(Point(1080, 720))
// .specificCameraId(previewConfig.rgbCameraId)
// .isMirror(true)
// .previewOn(binding.dualCameraTexturePreviewRgb)
// .cameraListener(cameraListener)
// .build()
// rgbCameraHelper?.run {
// init()
//// setSurfaceFrameCallback { bitmap ->
//// imageBitmap = BitmapFlipUtil.flipHorizontally(bitmap)
////
////// binding.ivRecImage.visible()
////// binding.ivRecImage.setImageBitmap(imageBitmap)
//// }
// start()
// }
// }
//
// /**
// * 初始化红外相机,若活体检测类型是可见光活体检测或不启用活体,则不需要启用
// */
// private fun initIrCamera() {
// Log.d(TAG, "initIrCamera: livenessType = $livenessType")
// if (livenessType === LivenessType.RGB) {
// return
// }
// val irCameraListener: CameraListener = object : CameraListener {
// override fun onCameraOpened(
// camera: Camera,
// cameraId: Int,
// displayOrientation: Int,
// isMirror: Boolean
// ) {
// Log.d(
// TAG,
// "initIrCamera IR onCameraOpened: cameraId = $cameraId, displayOrientation = $displayOrientation"
// )
// val previewSizeIr = camera.getParameters().getPreviewSize()
// val layoutParams = adjustPreviewViewSize(
// binding.dualCameraTexturePreviewRgb,
// binding.dualCameraTexturePreviewIr, binding.dualCameraFaceRectViewIr,
// previewSizeIr, displayOrientation, 0.25f
// )
//
// irFaceRectTransformer = FaceRectTransformer(
// previewSizeIr.width, previewSizeIr.height,
//// layoutParams.width, layoutParams.height,
// layoutParams.width, layoutParams.height,
// displayOrientation, cameraId, isMirror,
// ConfigUtil.isDrawIrRectHorizontalMirror(context),
// ConfigUtil.isDrawIrRectVerticalMirror(context)
// )
//
// recognizeViewModel.onIrCameraOpened(camera)
// recognizeViewModel.setIrFaceRectTransformer(irFaceRectTransformer)
// }
//
//
// override fun onPreview(nv21: ByteArray?, camera: Camera?) {
// recognizeViewModel.refreshIrPreviewData(nv21)
// }
//
// override fun onCameraClosed() {
// Log.d(TAG, "initIrCamera onCameraClosed: ")
// }
//
// override fun onCameraError(e: java.lang.Exception) {
// Log.d(TAG, "initIrCamera onCameraError: ${e.message}")
// e.printStackTrace()
// }
//
// override fun onCameraConfigurationChanged(
// cameraID: Int,
// displayOrientation: Int
// ) {
// if (irFaceRectTransformer != null) {
// irFaceRectTransformer!!.cameraDisplayOrientation = displayOrientation
// }
// Log.d(
// TAG,
// "initIrCamera onCameraConfigurationChanged: cameraID = $cameraID, displayOrientation = $displayOrientation"
// )
// }
// }
//
// val previewConfig = recognizeViewModel.previewConfig
// irCameraHelper = DualCameraHelper.Builder()
// .previewViewSize(
// Point(
// binding.dualCameraTexturePreviewIr.measuredWidth,
// binding.dualCameraTexturePreviewIr.measuredHeight
// )
// )
//// .previewViewSize(Point(4,3))
// .rotation(windowManager.defaultDisplay.rotation)
// .specificCameraId(previewConfig.irCameraId)
// .previewOn(binding.dualCameraTexturePreviewIr)
// .cameraListener(irCameraListener)
// .isMirror(true)
// .previewSize(recognizeViewModel.loadPreviewSize()) //相机预览大小设置,RGB与IR需使用相同大小
// .additionalRotation(previewConfig.irAdditionalDisplayOrientation) //额外旋转角度
// .build()
// irCameraHelper?.init()
// try {
// irCameraHelper?.start()
// } catch (e: RuntimeException) {
// ToastUtils.showToast(e.message + context.getString(R.string.camera_error_notice))
// }
// }
//
// /**
// * 绘制RGB、IR画面的实时人脸信息
// *
// * @param facePreviewInfoList RGB画面的实时人脸信息
// */
// private fun drawPreviewInfo(facePreviewInfoList: MutableList<FacePreviewInfo>) {
//// Timber.tag(TAG).d("drawPreviewInfo facePreviewInfoList = ${facePreviewInfoList.size}, rgbFaceRectTransformer = ${rgbFaceRectTransformer != null}")
// if (rgbFaceRectTransformer != null) {
// val rgbDrawInfoList: MutableList<DrawInfo>? = recognizeViewModel.getDrawInfo(
// facePreviewInfoList,
// LivenessType.RGB,
// openRectInfoDraw
// )
// // 识别成功
// binding.dualCameraFaceRectView.drawRealtimeFaceInfo(rgbDrawInfoList)
// }
//
// val listIsEmpty = facePreviewInfoList.isEmpty()
// val listFirstTrackId = if (listIsEmpty.not()) facePreviewInfoList[0].trackId else null
// Log.d(
// TAG,
// "listIsEmpty=$listIsEmpty,lastFaceTrackId=$lastFaceTrackId,listFirstTrackId=$listFirstTrackId"
// )
// if (listIsEmpty || (lastFaceTrackId != listFirstTrackId)) {
// if (lastFaceTrackId != -1 && currentUserId != null) {
// Log.d(TAG, "$lastFaceTrackId 用户离开")
// lastFaceTrackId = -1
// currentUserId = null
// }
// }
// }
//
// fun switchCamera() {
// try {
// L.e("开始切换摄像头")
// if (rgbCameraHelper != null && irCameraHelper != null) {
// rgbCameraHelper!!.stop()
// irCameraHelper!!.stop()
// rgbCameraHelper!!.switchCameraId()
// irCameraHelper!!.switchCameraId()
// rgbCameraHelper!!.start()
// irCameraHelper!!.start()
// rgbFaceRectTransformer!!.cameraId =
// if (rgbFaceRectTransformer!!.getCameraId() === 1) 0 else 1
// // showLongToast(getString(R.string.notice_change_detect_degree));
// L.e("切换摄像头成功")
// } else {
// L.e("切换摄像头失败")
//
// // showToast(getString(R.string.switch_camera_failed));
// exit()
// val newIntent = Intent(this, MainActivityBak2::class.java) // 要启动的Activity
// newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
// startActivity(newIntent)
// }
// } catch (e: java.lang.RuntimeException) {
// L.e("切换摄像头失败")
// toast(e.message + getString(R.string.camera_error_notice))
//
// exit()
// val newIntent = Intent(this, MainActivityBak2::class.java) // 要启动的Activity
// newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
// startActivity(newIntent)
// }
// }
//
// private fun exit() {
// finish()
// exitProcess(0)
// }
//
// override fun onDestroy() {
// countDownJob?.cancel()
// faceTaskJob?.cancel()
// super.onDestroy()
// }
//
// private var countDownJob: Job? = 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.gone()
// binding.tvFaceTip.visible()
// binding.btnCollectFace.visible()
// }
// )
// }
//
// private val intervalExecutor by lazy { IntervalExecutor() }
// private var faceTaskJob: Job? = null
//
// private var taskPageNo = 1
// fun startFaceTask() {
// faceTaskJob =
// intervalExecutor.startIntervalTaskWithInitialDelay(60 * 1000L, 30 * 1000L) {
// val timestamp = SpTool.getLastFaceTimestamp()
// if (timestamp == 0L) {
// return@startIntervalTaskWithInitialDelay
// }
// mainViewModel.getFaceIncrementList(
// pageNo = taskPageNo,
// timestamp = timestamp,
// onAllQueryFinished = {
// taskPageNo = 1
// },
// onPageQueryFinished = { list ->
// runOnUiThread {
// if (list.isEmpty()) {
// return@runOnUiThread
// }
// updateFaceData(list)
// }
// }
// )
// }
// }
//
// private fun updateFaceData(list: List<UserFaceModel>) {
// Thread {
// val faceList = mutableListOf<FaceEntity>()
// try {
// list.forEach { model ->
// if (model.faceDeleted == true) {
// //删除数据
// FaceDatabase.getInstance(this).faceDao().deleteFaceById(model.userId)
// } else {
// //保存数据
// val faceEntity = FaceEntity(
// model.userId,
// null,
// Base64.decode(model.faceFeatureStr)
// ).also {
// it.userType = "1"
// }
// faceList.add(faceEntity)
// }
// }
// } catch (e: Exception) {
// e.printStackTrace()
// }
// try {
// if (faceList.isNotEmpty()) {
// FaceDatabase.getInstance(this).faceDao().insert(faceList)
// }
// recognizeViewModel.refreshFaceList();
// } catch (e: Exception) {
// e.printStackTrace()
// }
// }.start()
// }
//
//// private var dinnerTypeJob: Job? = null
//// fun startDinnerTypeTask() {
//// dinnerTypeJob =
//// intervalExecutor.startIntervalTaskWithInitialDelay(10 * 60 * 1000L, 15 * 60 * 1000L) {
//// mainViewModel.getDinnerType {
////
//// }
//// }
//// }
//
// private fun clearFaceData() {
// Thread {
// val faceDao = FaceDatabase.getInstance(this).faceDao()
// faceDao.deleteTempUserFaceData()
// recognizeViewModel.refreshFaceList();
// }.start()
// }
//
// override fun onResume() {
// super.onResume()
// setupArcCamera()
//
// resumeCamera()
// }
//
// override fun onPause() {
// super.onPause()
// pauseCamera()
// }
//
//}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 419 KiB

+21 -21
View File
@@ -3,25 +3,25 @@
<item
android:width="1920dp"
android:height="1080dp"
android:drawable="@drawable/bg_collect_page" />
<item
android:width="1920dp"
android:height="270dp">
<shape android:shape="rectangle">
<solid android:color="#D00D269F" />
</shape>
</item>
<item
android:width="1920dp"
android:height="810dp"
android:top="270dp">
<shape android:shape="rectangle">
<gradient
android:angle="270"
android:endColor="#99407ACA"
android:startColor="#D00D269F"
android:type="linear"
android:useLevel="false" />
</shape>
</item>
android:drawable="@drawable/bg_collect_page3" />
<!-- <item-->
<!-- android:width="1920dp"-->
<!-- android:height="270dp">-->
<!-- <shape android:shape="rectangle">-->
<!-- <solid android:color="#D00D269F" />-->
<!-- </shape>-->
<!-- </item>-->
<!-- <item-->
<!-- android:width="1920dp"-->
<!-- android:height="810dp"-->
<!-- android:top="270dp">-->
<!-- <shape android:shape="rectangle">-->
<!-- <gradient-->
<!-- android:angle="270"-->
<!-- android:endColor="#99407ACA"-->
<!-- android:startColor="#D00D269F"-->
<!-- android:type="linear"-->
<!-- android:useLevel="false" />-->
<!-- </shape>-->
<!-- </item>-->
</layer-list>
+4 -21
View File
@@ -65,31 +65,14 @@
</androidx.cardview.widget.CardView>
<!-- <eightbitlab.com.blurview.BlurView-->
<!-- android:id="@+id/target"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- app:blurOverlayColor="#4482CD">-->
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:src="@drawable/bg_face_wrap"
android:src="@drawable/bg_face_wrap3"
android:visibility="visible" />
<!-- </eightbitlab.com.blurview.BlurView>-->
<!-- <com.google.android.material.imageview.ShapeableImageView-->
<!-- android:id="@+id/ivRecImage"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- android:scaleType="centerCrop"-->
<!-- android:visibility="gone"-->
<!-- app:shapeAppearance="@style/round10dpCornerStyle"-->
<!-- tools:src="@mipmap/ic_launcher_round" />-->
</FrameLayout>
<TextView
@@ -0,0 +1,153 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_collect_shape"
tools:context=".MainActivity">
<!-- <ImageView-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- android:src="@drawable/bg_collect_shape"/>-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="50dp"
android:gravity="center"
android:text="人脸采集"
android:textColor="@color/white"
android:textSize="40sp"
android:textStyle="bold" />
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="1dp"
app:dividerColor="#3391CEFF" />
<!-- android:layout_width="640dp"-->
<FrameLayout
android:id="@+id/flCameraView"
android:layout_width="852dp"
android:layout_height="480dp"
android:layout_gravity="center_horizontal"
android:layout_marginVertical="50dp"
android:visibility="visible">
<androidx.cardview.widget.CardView
android:id="@+id/flFace"
android:layout_width="640dp"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
app:cardBackgroundColor="@android:color/transparent"
app:cardCornerRadius="10dp"
app:cardElevation="0dp">
<TextureView
android:id="@+id/dual_camera_texture_preview_rgb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible" />
<com.sw.plate.utils.arcface.FaceRectView
android:id="@+id/dual_camera_face_rect_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.cardview.widget.CardView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:src="@drawable/bg_face_wrap3"
android:visibility="visible" />
</FrameLayout>
<TextView
android:id="@+id/tvFaceTip"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center_vertical"
android:text="请正视摄像头,保持面部居中于取景框内"
android:textColor="@color/white"
android:textSize="26sp"
android:textStyle="bold"
android:visibility="visible" />
<LinearLayout
android:id="@+id/layoutState"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="gone">
<ProgressBar
android:id="@+id/pbCollectLoading"
android:layout_width="36dp"
android:layout_height="36dp"
android:indeterminateTint="@color/white" />
<TextView
android:id="@+id/tvCollectState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="采集中......"
android:textColor="@color/white"
android:textSize="26sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btnCollectFace"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_margin="20dp"
android:background="@drawable/bg_collect_btn"
android:text="开始采集"
android:textColor="@color/white"
android:textSize="40sp"
android:textStyle="normal" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/flRecognizeIr"
android:layout_width="4dp"
android:layout_height="3dp"
android:layout_gravity="bottom">
<TextureView
android:id="@+id/dual_camera_texture_preview_ir"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.sw.plate.utils.arcface.FaceRectView
android:id="@+id/dual_camera_face_rect_view_ir"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</FrameLayout>