Continuously take still photo with android Camera2

心已入冬 提交于 2019-12-24 09:30:00

问题


From Camera2Basic example, I modified the code to make the program continuously takes still photo every 2 seconds. It runs fine but after a while it enters the same statecallback condition and does not take picture anymore:

case STATE_WAITING_PRECAPTURE: {
                // CONTROL_AE_STATE can be null on some devices
                Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
                if (aeState == null ||
                        aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE ||
                        aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
                    mState = STATE_WAITING_NON_PRECAPTURE;
                }
                else
                {
                    Log.e(TAG,"aeState = " + aeState);
                }
                break;
            }

The log keeps printing aeState = 2, which is CONTROL_AE_STATE_CONVERGED. My question is why the code does nothing when the AE is converged? Why not change state to STATE_WAITING_NON_PRECAPTURE?

I mean why not doing this instead?

case STATE_WAITING_PRECAPTURE: {
            // CONTROL_AE_STATE can be null on some devices
            Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
            if (aeState == null ||
                    aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED ||
                    aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE ||
                    aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
                mState = STATE_WAITING_NON_PRECAPTURE;
            }
            else
            {
                Log.e(TAG,"aeState = " + aeState);
            }
            break;
        }

ps: Where should I call takePicture() if I want to take photo every 2 seconds? Currently I call it in the CaptureCallback, but look like there some race condition because the CaptureCallback is in the background thread.

Thanks.


回答1:


The code should be setting the AE_PRECAPTURE_TRIGGER to START right before this; it's then waiting to see at least one result come in with AE_STATE of AE_PRECAPTURE to know the trigger has activated and precapture has started. It'll then wait for the first non-PRECAPTURE AE_STATE to know that precapture has completed.



来源:https://stackoverflow.com/questions/48198374/continuously-take-still-photo-with-android-camera2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!