对焦算法实现总结

简介

  本篇主要是对实现对焦算法的总结记录。

对焦模式

  常用模式:CAF、TOUCH focus、auto focus。
  CAF:
       1、判断条件:环境亮度变化、陀螺仪之类传感器数据变化
       2、检测到环境亮度或者传感器数据变化超过一定阀值
       3、继续检测到环境亮度或者传感器数据变化已经稳定
       4、触发CAF
    Touch focus
       1、点击预览界面时候触发
       2、点击位置坐标为对焦点,传入对焦算法中。
    auto focus:
       1、点击拍照时候触发
       2、对焦点为预览界面中心。

对焦算法结构

       1、获得当前帧图像
       2、图像清晰度计算
       3、下一步马达位置计算
       4、马达驱动
  驱动马达之后,从新获得新的帧图像,继续清晰度计算,获得信息对焦位置,不断循环,直到找到最高清晰度的马达位置,对焦完成。
  常用的清晰度评价算法有:
          频域函数  :对焦越好、高频部分越多,细节越多,图像越清晰。
          灰度函数  :对焦越好,和周围相邻灰度点差值越大,边缘越清晰,图像越清晰。
          信息熵函数:对焦越好,图像包含的信息熵越大,包含信息量更大,图像越清晰。
          统计学函数:对焦越好,直方图多样性越好,图像越清晰。
  常用的搜索算法有:
          1、函数逼近法
          2、Fibbonacci搜索法
          3、爬山搜索算法
  对焦算法中,基本都是在不停的做状态机查询,常用的状态有:
          1、等待对焦触发
          2、对焦参数更新(如图像分辨率变化或者对焦ROI坐标变化)
          3、对焦工作中
          4、对焦状态返回(对焦成功或者失败)

驱动马达

  	开环马达:以当前主流手机为例,驱动马达移动之后,自测需要50ms左右才能稳定。
  	闭环马达:以当前主流手机为例,驱动马达移动之后,自测需要15ms左右才能稳定。
  	闭环马达对比开环马达优势:稳定速度更快,功耗更小。

时间消耗

  	1、等待图像稳定
  	2、马达推动
  	3、状态机查询、搜索算法、清晰度评价算法等程序运行。
  	只要时间消耗在:等待图像稳定。
  	    以当前主流手机为例:
  	        1、30fps帧率为例,一帧图像为33ms左右。若为开环马达,等待帧数需要为3、4帧。在这上面,每推动一次马达,消耗时间为
                  100ms-133ms左右。若为闭环马达,需要等待2、3帧,每推动一次马达,消耗时间为66ms-100ms左右。
  	        2、马达推动稳定时间(15ms左右 或者 50ms左右)
  	           注意:因为马达推动稳定时间和图像帧收集等待时间为并行,所以这两者时间不用叠加。
  	        3、程序运行时间(15ms以下)
  	           这些程序中,主要是清晰度计算花费时间,但是也不多,自测在几毫秒就。这部分时间和马达驱动时间为串行,需要叠加。
                  和图像帧收集等待时间并行。
  	        4、自测普通对焦一次时间消耗大致在600ms-1000ms左右,随着帧率降低,对焦消耗时间越多。
  	 以上,对焦时间消耗主要为图像帧稳定上。

快速对焦

   常见快速对焦
  	1、激光对焦
  	2、双摄视差对焦
  	3、PdAF对焦
  	这些对焦方式,通过激光、视差、相位差之类方式,直接计算出大致的对焦点,然后再微调,实现对焦。
  	很大程度上减少了对焦搜索范围,大致上可以将对焦时间优化到300ms--500ms左右。
  	另外在快速对焦中,有些算法是直接计算出大致对焦点,没有继续微调对焦,这样对焦时间时间可以在100ms以内或左右。不过对焦效果
和对焦结果一致性会差一些。

注意

  	1、马达推动之后,需要等待图像稳定之后,才能计算清晰度
  	2、图像清晰度计算算法选择,需要对噪点之类不太敏感
  	3、对焦区域ROI的选择不能太小或者太大,1280X960的区域,可以选择160X160区域
  	4、如果有快速对焦功能,需要判断是否快速对焦成功,如果失败,则需要算法切换回普通对焦模式上,从新对焦。
  • 13
    点赞
  • 105
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1) Basic concepts of Auto Focus Algorithm 1.1) AF Detection methods There are two focus detection (AF) methods. 1) Distance detection method. 2) Contrast detection method. 1.1.1) Distance detection method The distance detection method is that the camera use AF module for detecting distance for main objects. If the camera is used this AF method, it will not need to use CCD to detect object’s contrast. There are three types of AF modules. 1. Active AF module 2. Passive AF module 3. TTL AF module 1.1.1.1) Active AF module Active AF systems measure distance to the subject independently of the optical system, and subsequently adjust the optical system for correct focus. There are various ways to measure distance, including ultrasonic sound waves and infrared light. In the first case, sound waves are emitted from the camera, and by measuring the delay in their reflection, distance to the subject is calculated. Polaroid cameras were known for successfully applying this system. In the latter case, infrared light is usually used to triangulate the distance to the subject. An exception to the two-step approach is the mechanical autofocus provided in some enlargers, which adjust the lens directly. 1.1.1.2) Passive AF module Passive AF systems determine correct focus by performing passive analysis of the image that is entering the optical system. They generally do not direct any energy, such as ultrasonic sound or infrared light waves, toward the subject. (However, an autofocus assist beam of usually infrared light is required when there is not enough light to take passive measurements.) Passive autofocusing can be achieved by phase detection or contrast measurement.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值