1,相机对焦模式有以下几种:
auto //自动
infinity //无穷远
macro //微距
continuous-picture //持续对焦
fixed //固定焦距
2,常见对焦模式切换场景
2.1,单拍时,会先对焦再拍照,再切换到CAF;
有一个从 af 切换到 caf 过程
2.2,连拍时,会先对焦再拍照,连拍完成,再切换到 CAF;
同样一个从 af 切换到 caf 过程
2.3,触屏对焦,过一段时间(2s-3s)会自动切换到CAF; (对焦锁定2s-3s)
也是从af 切换到 caf 过程
这三个场景都涉及到从 af 切换到 caf 过程,这个切换过程有两个地方需要注意:
一是focus-mode 要切换过来,并且设置到底层
mParameters.setFocusMode("auto");
mParameters.setFocusMode("continuous-picture");
二是相应的回调也要切换过来,设置到底层
mActivity.getCameraDevices().autoFocus(mAutoFocusCallback);
mActivity.getCameraDevices().setAutoFocusCallBack(mAutoFocusMoveCallback);
这两个步骤缺一不可。
3,对焦画框逻辑
3.1, autoFocus 流程中会有三类图片,五种状态
三类图片很好理解,正在对焦画白框,对焦成功画绿框,对焦失败画红框
五种状态分别为:
public static final int STATE_IDLE = 0; // Focus is not active.
public static final int STATE_FOCUSING = 1; // Focus is in progress.
// Focus is in progress and the camera should take a picture after focus finishes.
public static final int STATE_FOCUSING_SNAP_ON_FINISH = 2;
public static final int STATE_SUCCESS = 3; // Focus finishes and succeeds.
public static final int STATE_FOCUSING = 1; // Focus is in progress.
// Focus is in progress and the camera should take a picture after focus finishes.
public static final int STATE_FOCUSING_SNAP_ON_FINISH = 2;
public static final int STATE_SUCCESS = 3; // Focus finishes and succeeds.
public static final int STATE_FAIL = 4; // Focus finishes and fails.
3.2, autoFocusMoving 流程中只有两类图片,三种状态
autoFocusMoving 的回调中有一个参数即 moving 判断当前是否正在运动,若运动则该参数值为 true,否则为 false。正常流程即判断到在运动(切换场景)即开始对焦,画白框;稳定后(对焦成功),画绿框;还有一种状态即为对焦超时,此时会直接清除白框。
log会有类似这种显示:
onAutoFocusMoving moving = true
onAutoFocusMoving moving = false
onAutoFocusMoving moving = false
onAutoFocusMoving timeout
3.3, 对焦框 与 人脸框 是互斥的,会在代码中看到类似这种逻辑
// Ignore if the camera has detected some faces.
if (mFaceView != null && mFaceView.faceExists()) {
mFocusIndicatorRotateLayout.clear();
if (mFaceView != null && mFaceView.faceExists()) {
mFocusIndicatorRotateLayout.clear();
}
4,相机专业模式中是如何做到这几种对焦逻辑切换的
auto //自动
infinity //无穷远
macro //微距
continuous-picture //持续对焦
手机所搭载的摄像头一般都是定焦的,只是各个焦段的特性不一样,即只有一个焦平面是可以合焦的。因此在无穷远和微距模式下都是通过事先写在驱动中的一些参数去设置的。auto和continuous-picture 是摄像头本身就支持的对焦模式,可以把 continuous-picture理解为程序在检测到场景变化时自动autoFocus。
转自:http://blog.csdn.net/fulinwsuafcie/article/details/49558001