First, I tried Huawei Face Liveness Detection. With the sample code, it works.
Next, I tried CameraView. Also, by just following the sample code, I am able to perform frame processing, achieving face detection and face recognition.
<com.otaliastudios.cameraview.CameraView
app:cameraFacing="front"
android:id="@+id/cameraView"
app:cameraEngine="camera2"
app:cameraPreview="glSurface"
android:keepScreenOn="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
app:cameraAudio="off"
app:cameraExperimental="true">
</com.otaliastudios.cameraview.CameraView>
Question: How to integrate Huawei Face Liveness Detection into CameraView?
Provided the Face Liveness Detection code below, I tried changing the view container (mPreviewContainer
as below), but it just throws error and app exits.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_liveness_custom_detection);
mPreviewContainer = findViewById(R.id.surface_layout); //<------ Change this to CameraView
mlLivenessDetectView = new MLLivenessDetectView.Builder()
.setContext(this)
.setFaceFrameRect(new Rect(0, 0, 0, 200))
.setDetectCallback(new OnMLLivenessDetectCallback() {
...
}
I am curious how to integrate the Huawei Face Liveness Detection into CameraView (or even normal Camera2 or CameraX)? Can the HMS take the input frames from CameraView, instead of opening another camera?
P.S.: The first error appeared (out of the lengthy message):
I/BufferQueue: [unnamed-11129-0](this:0x70859fb800,id:0,api:0,p:-1,c:-1) BufferQueue core=(11129:com.example.cv1)
E/AndroidRuntime: FATAL EXCEPTION: CameraViewEngine
Process: com.example.cv1, PID: 11129
com.otaliastudios.cameraview.CameraException
at com.otaliastudios.cameraview.engine.Camera2Engine$2.onDisconnected(Camera2Engine.java:435)
at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:252)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:226)
at android.os.HandlerThread.run(HandlerThread.java:65)
E/CameraEngine: EXCEPTION: Handler thread is gone. Replacing.
E/CameraEngine: EXCEPTION: Scheduling on the crash handler...