Is it possible to control flash intensity and flash frequency with Android Camera2?

274 Views Asked by At

I have an application where I am trying to impart the maximum possible light energy into a subject from an Android smartphone's flash.

In lab measurements with several phones we have observed that the light output of the flash while taking an auto exposure photo can be significantly higher than the steady state Torch On (of course this depends on the device). If it were possible to trigger the flash at the higher output level, regardless of external lighting conditions and at a reliable, sufficiently high frequency (5 Hz?) in some cases it would be possible to output more light than just leaving the flashlight on steady state.

Unfortunately, it appears to be impossible to achieve this fine grained control of the flash, I am guessing because the intensity control of the flash (besides the torch) is tied to the Auto Exposure control at a very low level.

I have been able to get the flash to fire while requesting preview frames with the following:

mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                                                       CaptureRequest.CONTROL_AF_MODE_OFF);

                            mPreviewRequestBuilder.set( CaptureRequest.FLASH_MODE,
                                                        CaptureRequest.FLASH_MODE_SINGLE );

                            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                                                       CaptureRequest
                                                               .CONTROL_AE_PRECAPTURE_TRIGGER_START);

                            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                                                       CaptureRequest.CONTROL_AE_MODE_OFF);

                            // Finally, we start displaying the camera preview.
                            mPreviewRequest = mPreviewRequestBuilder.build();

                            setState( STATE_PREVIEW );
                            mCaptureSession.setRepeatingRequest(mPreviewRequest,
                                                                mCaptureCallback, mBackgroundHandler);

When the capture result comes back with FLASH_STATE_FIRED then I make a single still image capture with:

            final CaptureRequest.Builder captureBuilder =
                mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(surface);

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);
        captureBuilder.set( CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF );

        captureBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                           CaptureRequest.CONTROL_AE_MODE_OFF);

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), mCaptureCallback, null);

Which seems to be required to reset the flash. I then go back to the preview code above to flash again however the flash fires extremely intermittently.

Is there a better way to produce highly consistent, high frequency, high output flashes with the Camera2 interface other than simply turning the torch on an off?

0

There are 0 best solutions below