Update Android app login, home, and face verification flows.
Sync current local UI and activity changes to remote repository. Made-with: Cursor
This commit is contained in:
@@ -1,4 +1,44 @@
|
||||
package com.example.defenseapplication.view
|
||||
|
||||
class FaceAnalyzer {
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import androidx.camera.core.ExperimentalGetImage
|
||||
import androidx.camera.core.ImageAnalysis
|
||||
import androidx.camera.core.ImageProxy
|
||||
import com.google.mlkit.vision.common.InputImage
|
||||
import com.google.mlkit.vision.face.FaceDetector
|
||||
/*
|
||||
* 人脸分析器
|
||||
* */
|
||||
@ExperimentalGetImage
|
||||
class FaceAnalyzer(
|
||||
private val detector: FaceDetector?,
|
||||
private val overlayView: FaceOverlayView
|
||||
) : ImageAnalysis.Analyzer {
|
||||
|
||||
override fun analyze(imageProxy: ImageProxy) {
|
||||
if (detector == null) {
|
||||
imageProxy.close()
|
||||
return
|
||||
}
|
||||
val mediaImage = imageProxy.image ?: run {
|
||||
imageProxy.close()
|
||||
return
|
||||
}
|
||||
val image = InputImage.fromMediaImage(mediaImage, imageProxy.imageInfo.rotationDegrees)
|
||||
|
||||
detector.process(image)
|
||||
.addOnSuccessListener { faces ->
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
overlayView.setFaces(faces)
|
||||
}
|
||||
}
|
||||
.addOnFailureListener { e ->
|
||||
Log.e("FaceAnalyzer", "人脸检测失败", e)
|
||||
}
|
||||
.addOnCompleteListener {
|
||||
imageProxy.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user