简体   繁体   中英

How to replace use case on camerax camera provider

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM