三星S5摄像机2 API自动对焦 [英] Camera2 API AutoFocus with Samsung S5

查看:1248
本文介绍了三星S5摄像机2 API自动对焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对三星S5新的摄像机2 API的工作。该设备报告支持的硬件水平是 LEGACY ,这是罚款。

I'm working with the new Camera2 API on a Samsung S5. The supported hardware level this device is reporting is LEGACY, which is fine.

不过,我似乎无法能够自动对焦此设备上。触发自动对焦的要求是这样的:

However, I cannot seem to be able to auto-focus on this device. The request to trigger auto-focus looks like this:

previewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
previewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START);
state = STATE_PREVIEW;
try {
  captureSession.setRepeatingRequest(previewRequestBuilder.build(), captureCallback, backgroundHandler);
} catch (CameraAccessException e) {
  e.printStackTrace();
}

请求被发送

之后,该请求的结果总是 CONTROL_AF_STATE_ACTIVE_SCAN 偶尔 CONTROL_AF_STATE_NOT_FOCUSED_LOCKED

但奇怪的是,状态是当 CONTROL_AF_STATE_NOT_FOCUSED_LOCKED ,自动对焦追溯到到 CONTROL_AF_STATE_ACTIVE_SCAN 状态了一会儿,然后回到 CONTROL_AF_STATE_NOT_FOCUSED_LOCKED ,产生无限聚焦循环。根据文档,当状态是 CONTROL_AF_STATE_NOT_FOCUSED_LOCKED ...

The strange thing is that, when the state is CONTROL_AF_STATE_NOT_FOCUSED_LOCKED, the auto-focus goes back into the CONTROL_AF_STATE_ACTIVE_SCAN state for a while and then back to CONTROL_AF_STATE_NOT_FOCUSED_LOCKED, resulting in a infinite focus loop. According to the docs, when state is CONTROL_AF_STATE_NOT_FOCUSED_LOCKED...

,直到自动对焦模式(android.control.afMode)被改变或新的AF触发被发送到照相机装置(android.control.afTrigger)的透镜将保持静止

The lens will remain stationary until the AF mode (android.control.afMode) is changed or a new AF trigger is sent to the camera device (android.control.afTrigger).

我想知道如果这种差异是因为一个事实,即硬件水平是 LEGACY ,我应该回去使用德precated相机API ,但似乎疯了这样的prevalent功能,如自动对焦。

I'm wondering if this discrepancy is because of the fact that the hardware level is LEGACY and that I should go back to using the deprecated Camera API, but that seems crazy for such a prevalent feature such as auto focus.

有任何建议步骤如何如何对待那些报告遗留设备

Is there any reccomendations how how to treat devices that are reporting LEGACY?

推荐答案

三星S5具有自动对焦返回 INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY ,这意味着它不支持摄像机2 API

The Samsung S5 with autofocus returned INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY, which means it does not support Camera2 api.

我有以下过滤器在我的应用程序中使用的摄像头。

I have the below filter for using camera in my application.

if (Build.VERSION.SDK_INT >= 21 && isDeviceCompatibleOfCamera2()) {
 // Use camera2
} else {
 // Use old camera
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
 public boolean isDeviceCompatibleOfCamera2() {
 try {
    CameraManager manager = (CameraManager) getActivity().getSystemService(Context.CAMERA_SERVICE);
    String backCameraId = manager.getCameraIdList()[0];
    CameraCharacteristics backCameraInfo = manager.getCameraCharacteristics(backCameraId);

    int level = backCameraInfo.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
    return level == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL;

    } catch (CameraAccessException e) {
     ETLog.d(TAG, "Device not compatible of camera2 api" + e);
    }
    return false;
 }

这篇关于三星S5摄像机2 API自动对焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆