问题
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