Capture flash/no-flash images quickly using Androi

2019-09-04 01:31发布

问题:

I am writing an android application to capture flash/no-flash image pair quickly when a user presses capture button. For writing my application I referred to Camera2Basic app here.

From Android documentation, I found that for flash to fire, the preview request builder should have AE_MODE set to AE_MODE_ON_ALWAYS_FLASH.

I am using three request builders: preview, noflash and flash The difference between three is:

  • preview: AE_MODE set to AE_MODE_ON_ALWAYS_FLASH and AF_MODE set to CONTROL_AF_MODE_CONTINUOUS_PICTURE

  • noflash: AE_MODE set to AE_MODE_ON

  • flash: AE_MODE set to AE_MODE_ONALWAYS_FLASH

I am using Nexus 5 device and I found that for capturing just a flash image, one must have preview builder and flash builder as described above, and submit a still capture request using above flash builder. Using this sequence, I always get a proper flash image in Nexus 5. The pre-flash is always automatically handled.

Coming to original question, capturing a pair of flash/no-flash images, my sequence of steps is as follows:

  1. In take picture, I start auto-focus trigger using preview builder.

  2. When auto-focus is complete, I submit two still capture requests back to back using noflash and flash builders (first noflash, then flash)

However, the first image I get is a flash image and second is a no-flash image. I don't understand this reversal in output.

  1. JPEG case: First image is always a proper flash image, second image is always a proper no-flash image as shown below:

Flash image corresponding to request submitted using noflash builder:

No-flash image corresponding to request submitted using flash builder:

  1. YUV_420_888 case: Sames as in JPEG, however, noflash image is never proper. One can notice a white strip on right side as well as improper colors, also it is very noisy!

Flash image corresponding to request submitted using noflash builder:

Improper no-flash image corresponding to request submitted using flash builder:

Off-course, since in YUV_420_888 format two images are captured back to back, I add a preview request in between to prevent spill over.

My questions are:

  1. Why the order of output images is reversed?

  2. Why no-flash image in YUV_420_888 format is not proper?

Please help.

回答1:

To confirm a few things:

  1. Make sure the triggers are only set to START for a single request, not continuously
  2. If the AE_MODE is one of the ones where AE controls flash, FLASH_MODE is ignored; best not to touch it just in case anyway.
  3. Make sure to use the STILL_CAPTURE request template for the final capture request; otherwise main flash is not expected to fire.
  4. You should be able to submit a second no-flash STILL_CAPTURE request almost right after the flash request (to be safe, leave one request of buffer, since due to rolling shutter, the main flash may partially be visible one frame before and after the flash capture); just submit a preview request and then a STILL_CAPTURE request with AE_MODE_ON.
  5. For maximum speed, do not capture JPEG images; the extra encoding time can cause delays between the images. Use YUV_420_888 and create JPEGs yourself.