Reputation: 668
I am trying to detect when camera has focused (or has stopped trying to) so I am calling result.get(CaptureResult.CONTROL_AF_STATE)
in onCaptureCompleted method of callback.
It kind of works for mode AF_MODE_CONTINUOUS_PICTURE, camera reports CONTROL_AF_STATE 1 or 2 (CONTROL_AF_STATE_PASSIVE_SCAN or CONTROL_AF_STATE_PASSIVE_LOCKED), which is nice.
However when camera is switched to AF_MODE_MACRO, then reported CONTROL_AF_STATE is always 0 (INNACTIVE) no matter what happens. I was trying to refer to 1 but probably I do not get it right.
Further info: when changing modes between AF_MODE_MACRO and AF_MODE_CONTINUOUS_PICTURE I always start new capture session like this:
private void configCaptureSession(boolean macroModeNew) {
this.macroMode = macroModeNew;
try {
// Wanna macro?
if (macroMode) {
LOGGER.d( "MACRO ON","");
previewRequestBuilder.set(
CaptureRequest.CONTROL_AF_MODE,CaptureRequest.CONTROL_AF_MODE_MACRO);
}
else {
// Continuous AF
LOGGER.d( "MACRO OFF","");
previewRequestBuilder.set(
CaptureRequest.CONTROL_AF_MODE,CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
}
// Finally, we start displaying the camera preview.
previewRequest = previewRequestBuilder.build();
LOGGER.d( "SETTING NEW SESSION","");
captureSession.setRepeatingRequest(
previewRequest, captureCallback, backgroundHandler);
} catch (final CameraAccessException e) {
LOGGER.e(e, "Exception!");
}
}
captureCallback:
private final CameraCaptureSession.CaptureCallback captureCallback =
new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureProgressed(
final CameraCaptureSession session,
final CaptureRequest request,
final CaptureResult partialResult) {}
@Override
public void onCaptureCompleted(
final CameraCaptureSession session,
final CaptureRequest request,
final TotalCaptureResult result) {
afState = result.get(CaptureResult.CONTROL_AF_STATE);
LOGGER.i("FOKKUS-MODE:"+result.get(CaptureResult.CONTROL_AF_MODE));
LOGGER.i("FOKKUS:"+result.get(CaptureResult.CONTROL_AF_STATE));
}
};
Upvotes: 1
Views: 2703
Reputation: 18107
Does your device list support for AF_MODE_MACRO in https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#CONTROL_AF_AVAILABLE_MODES ?
If not, then this is expected as you're trying to use a non-supported focusing mode.
If it is supported, the next issue is that I don't see you issuing an AF trigger command anywhere. Have you looked at the state transition tables for AF_STATE here: https://developer.android.com/reference/android/hardware/camera2/CaptureResult.html#CONTROL_AF_STATE ?
For AF_AUTO and AF_MACRO, you have to trigger AF when you want a focus pass, and then wait for AF_STATE_FOCUSED_LOCKED or NOT_FOCUSED_LOCKED.
The continuous modes don't require a trigger to focus, which is why you're seeing something happening with them.
Upvotes: 1