How to replace use case on camerax camera provider

Viewed 27

On cameraX documentation is following rule: Preview + VideoCapture + ImageAnalysis + ImageCapture: not supported.

But I need to detect faces than capture image & cut face image, after that record video for 5 seconds.

I seen camera apps that can capture image during video record.

Here is my code:

cameraProvider = future.get()
textureEntry = textureRegistry.createSurfaceTexture()
val textureId = textureEntry!!.id()

val owner = activity as LifecycleOwner

val preview = buildPreview()
val analysis = buildImageAnalysis()

imageCapture = buildImageCapture()

camera = cameraProvider!!.bindToLifecycle(
    owner,
    cameraConfigs.cameraSelector,
    preview,
    analysis,
    imageCapture
)

cameraProvider have function unbind(useCase) but no function to bind other.

1 Answers

Right now, the simple way to do it is this:

  1. Bind ImageAnalysis and ImageCapture
  2. Detect face and take picture.
  3. Unbind ImageAnalysis and ImageCapture
  4. Bind VideoCapture
  5. Record the video for 5 seconds

This is less ideal in terms of performance, because unbinding/binding reconfigures the camera and introduces latency.

A better way is to share the Preview output with VideoCapture using OpenGL, but it requires a non-trivial amount of work right now. This feature is in CameraX roadmap, but it won't happen for a couple of month.

Related