对于CONTROL_AF_MODE_MACRO

时间:2017-12-01 16:38:05

标签: android android-camera2

我正在尝试检测相机何时聚焦(或已停止尝试),因此我在 onCaptureCompleted 回调方法中调用result.get(CaptureResult.CONTROL_AF_STATE)

它适用于模式 AF_MODE_CONTINUOUS_PICTURE ,相机报告CONTROL_AF_STATE 1或2(CONTROL_AF_STATE_PASSIVE_SCAN或CONTROL_AF_STATE_PASSIVE_LOCKED),这很不错。

但是,当相机切换到 AF_MODE_MACRO 时,无论发生什么情况,报告的CONTROL_AF_STATE始终为0(创新)。我试图引用1,但可能我说得不对。

更多信息:在 AF_MODE_MACRO AF_MODE_CONTINUOUS_PICTURE 之间更改模式时,我总是按照以下方式启动新的捕获会话:

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));

    }

  };

1 个答案:

答案 0 :(得分:1)

您的设备是否在https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#CONTROL_AF_AVAILABLE_MODES中列出了对AF_MODE_MACRO的支持?

如果没有,那么当您尝试使用不支持的对焦模式时,这是预期的。

如果支持,下一个问题是我没有看到你在任何地方发出AF trigger命令。您是否在此处查看了AF_STATE的状态转换表: https://developer.android.com/reference/android/hardware/camera2/CaptureResult.html#CONTROL_AF_STATE

对于AF_AUTO和AF_MACRO,您需要在需要焦点传递时触发AF,然后等待AF_STATE_FOCUSED_LOCKED或NOT_FOCUSED_LOCKED。

连续模式不需要触发器来聚焦,这就是为什么你会看到它们发生的事情。