android自动对焦代码,Android相机实时自动对焦的完美实现

本文详细介绍了在Android中实现相机实时自动对焦遇到的问题和解决方案,包括各种对焦模式的尝试,如autoFocus()、FOCUS_MODE_CONTINUOUS_PICTURE、FOCUS_MODE_CONTINUOUS_VIDEO,以及最终通过传感器判断手机运动状态来触发对焦的方法,以实现更好的自动对焦效果。
摘要由CSDN通过智能技术生成

Android相机实时自动对焦的完美实现

github,由于android碎片化严重,而且各大厂商极有可能去修改相关API的实现,其中遇到了不少坑,包括实时相机高斯模糊,自动对焦的兼容问题,以及一系列性能问题。换过很多搜索引擎,访问过很多网站,访问过很多网站,拜读过很多代码,没有发现对于相机实时自动对焦特别完美的实现方式。现对相机的自动对焦问题单独做一个记录,算是对这部分的一个总结。也希望后人在这部分能够快速地解决问题,不必浪费过多的时间。测试手机包括:MX4 pro,小米4,华为荣耀3C等等。

参考过@yanzi1225627 大神的一些做法,测试结果不是特别满意。

一,一些对焦方案的尝试

1,autoFocus()的尝试:

private Camera.AutoFocusCallback mAutoFocusCallback;

mAutoFocusCallback = new Camera.AutoFocusCallback() {

public void onAutoFocus(boolean success, Camera camera) {

// TODO Auto-generated method stub

if(success){

myCamera.setOneShotPreviewCallback(null);

Toast.makeText(TestPhotoActivity.this,

"自动聚焦成功" , Toast.LENGTH_SHORT).show();

}

}

};

myCamera.autoFocus(mAutoFocusCallback);

在一部分手机上,始终只对焦一次,也就是说根本不能实现。即使是在按下拍照的时候去调用一次对焦,等对焦成功后再进行拍照,实现的效果也不是很完美。

还见部分博客把autoFocus()方法放在Camera预览SurfaceView的surfaceChanged()中的一些实现,发现也只对焦了一次。

2,设置对焦模式FOCUS_MODE_CONTINUOUS_PICTURE

/**

* Continuous auto focus mode intended for taking pictures. The camera

* continuously tries to focus. The speed of focus change is more

* aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus

* starts when the parameter is set.

*

*

Applications can call {@link #autoFocus(AutoFocusCallback)} in

* this mode. If the autofocus is in the middle of scanning, the focus

* callback will return when it completes. If the autofocus is not

* scanning, the focus callback will immediately return with a boolean

* that indicates whether the focus is sharp or not. The apps can then

* decide if they want to take a picture immediately or to change the

* focus mode to auto, and run a full autofocus cycle. The focus

* position is locked after autoFocus call. If applications want to

* resume the continuous focus, cancelAutoFocus must be called.

* Restarting the preview will not resume the continuous autofocus. To

* stop continuous focus, applications should change the focus mode to

* other modes.

*

* @see #FOCUS_MODE_CONTINUOUS_VIDEO

<
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值