AF monitor tuning <2>

1. af monitor concept

AF 监控状态的主要功能是场景切换检测。直观地看,场景切换意味着当前场景没有对焦,导致算法触发搜索以找到准焦的最佳位置。

每种算法有其自己的场景切换检测标准。例如, CAF 依赖于陀螺仪参数、绝对误差和 (SAD)参数以及 SAD 相关参考帧 (SADR) 参数以检测场景切换。相比之下, PDAF 依赖于当前帧散焦值的组合、算法的可信度以及场景的稳定性。

AF 监控也负责场景平移检测。为避免不必要的搜索,算法区分了场景切换和场景平移。搜索算法直到场景稳定(即,不平移)时,才开始搜索。总而言之,场景切换和场景平移检测是AF 监控状态中的两种基本功能。

  • CAF 依赖于陀螺仪参数、SAD(sum of absolute differences)、SADR 参数以检测场景切换。 PDAF依赖于当前帧defocus value、算法的confidence 和 场景的稳定性(stability of the scene)。
  • SADR 是统计 当前画面的平均亮度值和上次对焦完成的亮度之间的差异得到的。
  • SAD 是统计当前画面的平均亮度值和上一帧的亮度之间的差异得到。
    亮度的绝对误差和
    SAD compares frame by frame, which is less sensitive to slow scene changes
    SADR compares to a reference that is established when the scene is stable after a scene change (which is after focus is finished and both SAD and SADR are not stable).

SAD keywords:
af_cont_detect_scene_change_sad //获取当前的SAD 值
af_cont_detect_scene_change //判断当前场景是否改变

2. value monitor bank and algo configure

数值监控实例化了每个监控算法的配置和决策逻辑。尽管监控逻辑与之前的 3A 版本类似,但是数值监控的结构、配置和操作是该逻辑的全新实施。数值监控的主要优点在于配置灵活、调试简便。下图显示了数值监控的两种主要结构.

在这里插入图片描述

  • 监控算法配置 – 包含在 CAF、 PDAF、 TOF 和 DCIAF 监控算法中使用的各状态类型的灵敏
    度设置。
  • 数值监控库 – 包含各状态类型各种参数。

Monitor Algo Config 对应 algo configure
在这里插入图片描述

  1. 在本示例中,陀螺仪灵敏度值为 50。这是所有灵敏度参数的默认值。所有灵敏度参数的范围在 1 至 100(0 表示关闭)。在 1-100 之间的所有灵敏度值都是有效的,并预计会导致合理的监控行为。
  2. 因为灵敏度是 50,所以选择中灵敏度参数。如果灵敏度是 1,则选择低灵敏度参数。如果灵敏度是 100,则选择高灵敏度参数。如果灵敏度在 1 至 50 或 50 至 100 之间,则分别在低和中或中和高之间使用线性插值。每个配置文件(低、中、高)中的参数完全相同。然而,其值经过了预配置,可根据监控算法配置中的灵敏度参数提供不同级别的灵敏度。
  3. 根据作为 1 和 2 的结果产生的配置, CAF 和任何其他配置了陀螺仪数值监控设置类型的监控算法都可实例化。

如果调试工程师想要使陀螺仪灵敏度比中灵敏度配置更加敏感,最简单的方法是将陀螺仪灵敏度修改为 50 以上。如果调试工程师想要使陀螺仪灵敏度与中灵敏度配置相比更为不敏感,则将灵敏度修改为 50 以下。
注: 当在调试过程中使用逻辑灵敏度参数时,数值监控库中的参数不会发生变化。

a. algo configure

算法的优先级别
在这里插入图片描述
注: 将灵敏度参数设置为 0,可禁用相应数值监控库中的参数。例如,将 SADR 设置为 0,可禁用 SADR VM 设置类型中的参数。在这种情况下,输出决策为 0。

Topo CAF 中的逻辑灵敏度参数字面意思的灵敏度。

b. value monitor bank

在这里插入图片描述

Trigger Threshold :确定信号是否稳定的阈值。它被定义为元滤波器输出和基准之间的绝对误差。
Consecutive Count Threshold :用于检测器检测信号稳定/不稳定的连续计数的计数阈值。如果达到阈值,则数值监控为VM_DETECTOR_UNSTABLE 模式输出 1,为VM_DETECTOR_STABLE 模式输出 0。
Frame To Armed: 强制数值监控开始检测流程的数字。例如,如果frame2armed=2,则数值监控在场景对焦后 2 帧开始检测流程(调用变基)。
Median Filter Config Enable: 用于启用中值滤波器的标记。 
Num of Samples: 中值滤波器的长度。
Mvavg Fltr Cf Enable 用于在元滤波器模块中启用移动平均滤波器的标记。
Num of Samples: 元滤波器模块中移动平均滤波器的待滤波样本数。
IIR Fltr Cfg Enable: 用于在元滤波器模块中启用 IIR 滤波器的标记。
Num of Samples IIR:滤波器的缓冲区大小(在当前版本中,值限制为 2)。
Coeff Numerator:分子中的系数(需要调试工程师来检查滤波器稳定性)
Coeff Denominator:分母中的系数(需要调试工程师来检查滤波器稳定性)。
Detection Type:数值监控的检测类型的标记。
如果选择不稳定,则指定的数值监控会判断信号是否变得不稳定。如果信号不稳定,数值监控输出为 1;如果信号稳定,数值监控输出为 0。
如果选择稳定,则指定的数值监控会判断信号是否变得稳定。如果信号不稳定,数值监控输出为 0;如果信号稳定,数值监控输出为 1。
在稳定/不稳定检测期间,通常考虑连续计数。因此,这两种配置有不同的检测逻辑。
Absolute Mode Cfg:用于确定基准的模式选择的标记。如果启用绝对模式 (==1),则指定的数值监控在检测过程中使用 absolute_mode_cfg.baseline 参数作为固定基准。如果禁用绝对模式 (==0),则指定的数值监控会自适应地配置基准。当达到 frame2armed 值时,基准为元滤波器输出。

3. AF调试步骤

caf的monitor key log根本不是af_cont_state_monitor/ af_cont_detect_scene_change/ af_cont_detect_panning。没有更多的详细数据日志。
CAF只需查看这个函数af_caf_process_monitor,并检查状态结果[0或1]来微调sad/gyro场景变化和平移。

Trigger refocus condition:
is_scene_change = sad->is_change | gyro->is_change;
is_scene_panning =sad->is_panning | gyro->is_panning;
is_trig_refocus = is_scene_change && is_scene_stable

(1)亮度变化引起的monitor

(2)场景变化引起的monitor

调试monitor algo config Topo CAF

  1. 只打开CAF algorithm
  2. 调试SADR(scene change) 设置GYRO/GYRO_PANNING/SAD_PANNING sensitivities to 0
  3. 调整SADR 灵敏度范围1-100. 值越大越容易触发scene change
  4. SADR sensitivity 调整好,开始调试SAD_Panning sensitivity value。
  5. 调整SAD_Panning 灵敏度1-100. 数值越大,越容易获得场景稳定
  6. SADR SAD_Panning 场景变化和场景稳定 ,调试GYRO
  7. 调试GYRO(scene change) 设置SADR/GYRO_Panning/SAD_Panning sensitivities to 0
  8. 调整GYRO灵敏度范围1-100. 值越大越容易触发scene change
  9. GYRO sensitivity 调整好,开始调试GYRO_Panning sensitivity value。
  10. 调整GYRO_Panning灵敏度1-100. 数值越大,越容易获得场景稳定
  11. 更新所有调试好的sensitivities ,查看性能。
  12. 依据testing cases,fine tuned 每个sensitivity 到可以接受。
03-31 16:02:08.051   888  1189 V CamX    : [ VERB][STATS_AF ] af_haf_caf.cpp:999: af_caf_process_monitor Caf topology index 1 
03-31 16:02:08.051   888  1189 V CamX    : [ VERB][STATS_AF ] af_value_monitor.cpp:634: af_value_monitor_get_trigger CAF_SADR VM GET TRIGGER detection mode 2, abs mode 1, baseline 0, input 14.577575, metafilter 13.794128, decision 1
03-31 16:02:08.051   888  1189 V CamX    : [ VERB][STATS_AF ] af_value_monitor.cpp:634: af_value_monitor_get_trigger CAF_GYRO VM GET TRIGGER detection mode 1, abs mode 1, baseline 0, input 0.000000, metafilter 0.000000, decision 0
03-31 16:02:08.051   888  1189 V CamX    : [ VERB][STATS_AF ] af_value_monitor.cpp:634: af_value_monitor_get_trigger CAF_SAD_PANNING VM GET TRIGGER detection mode 1, abs mode 1, baseline 0, input 1.103057, metafilter 1.103027, decision 0
03-31 16:02:08.051   888  1189 V CamX    : [ VERB][STATS_AF ] af_value_monitor.cpp:634: af_value_monitor_get_trigger CAF_GYRO_PANNING VM GET TRIGGER detection mode 1, abs mode 1, baseline 0, input 0.000000, metafilter 0.000000, decision 0
03-31 16:02:08.052   888  1189 V CamX    : [ VERB][STATS_AF ] af_value_monitor.cpp:634: af_value_monitor_get_trigger CAF_FACE_SCENE_CHANGE_HOLD VM GET TRIGGER detection mode 1, abs mode 1, baseline 0, input 0.000000, metafilter 0.000000, decision 0
03-31 16:02:08.052   888  1189 V CamX    : [ VERB][STATS_AF ] af_haf_caf.cpp:1030: af_caf_process_monitor setting face value monitor to 0
03-31 16:02:08.052   888  1189 V CamX    : [ VERB][STATS_AF ] af_haf_caf.cpp:1075: af_caf_process_monitor Scene change sad 1 gyro 0 face 0 scene panning sad 0 gyro 0
03-31 16:02:08.052   888  1189 V CamX    : [ VERB][STATS_AF ] af_value_monitor.cpp:634: af_value_monitor_get_trigger CAF_CAF_SCENE_CHANGE_HOLD VM GET TRIGGER detection mode 1, abs mode 1, baseline 0, input 0.000000, metafilter 0.000000, decision 0
03-31 16:02:08.052   888  1189 V CamX    : [ VERB][STATS_AF ] af_haf_caf.cpp:1097: af_caf_process_monitor CAF caf_sc_extension 0 is scene changed 1 is_scene_panning 0
03-31 16:02:08.052   888  1189 V CamX    : [ VERB][STATS_AF ] af_haf_caf.cpp:1099: af_caf_process_monitor CAF_is_scene_changed:1 panning 0 stable 1!
03-31 16:02:08.052   888  1189 V CamX    : [ VERB][STATS_AF ] af_haf_caf.cpp:1138: af_caf_process_monitor is_face_af: 0 is_caf_af 1 cur_pos 311
03-31 16:02:08.052   888  1189 V CamX    : [ VERB][STATS_AF ] af_haf_caf.cpp:1139: af_caf_process_monitor CAF_is_scene_changed: sadr 1 gyro 0!
03-31 16:02:08.052   888  1189 V CamX    : [ VERB][STATS_AF ] af_haf_caf.cpp:1140: af_caf_process_monitor CAF_is_panning: sad 0 gyro 0!
03-31 16:02:08.052   888  1189 V CamX    : [ VERB][STATS_AF ] af_haf_caf.cpp:1145: af_caf_process_monitor CAF monitor output : 100 0 100 1 !

*Caf topology index 1 means used CAF_TOPO_PROFILE_ADVANCED*
is_scene_change = sad->is_change | gyro->is_change;
is_scene_panning =sad->is_panning | gyro->is_panning;
is_trig_refocus = is_scene_change && is_scene_stable
please notice this log af_caf_process_monitor: CAF monitor output : 100 0 100 1  confidence/focus_level/stability/is_trig_refocus

The  values respectively is  confidence/focus_level/stability/is_trig_refocus. And will affect different monitor status.
Focus level and Stability only have two values [100 or 0].
is_scene_change == 0? focus_level=100: focuc_level=0
is_scene_stable==1? stability=100: stability=0
Confidence generally only have two values [100/0], but when used multi-window will generateone special value 50 and if enabled PDAF_TOPO_PROFILE_ADVANCED will also finally has chance to re-write confidence to value 50
Topo Default Mixer 这里面参数不知道什么意思。后面在看下。 
 secondary scene change cnt > 0 稳定就会从新触发对焦
03-31 16:02:00.717   888  1190 V CamX    : [ VERB][STATS_AF ] af_haf_default_mixer.cpp:791: af_default_mixer_process_monitor secondary scene change cnt: 5
03-31 16:02:00.717   888  1190 V CamX    : [ VERB][STATS_AF ] af_haf_default_mixer.cpp:831: af_default_mixer_process_monitor primary monitor has low confidence. is trig_refocus: 1


4. PDAF调试monitor

PDAF只需查看这个函数af_pdaf_monitor
pdaf monitor:defocus,confident,stable
通常,PDAF监控场景的变化,并在满足以下条件时触发搜索:

  • 当前帧defocus 值大于 defocus threshold
  • 算法可信度ok
  • 场景稳定。
  1. defcous
    正离焦值意味着运动是从近到远。负离焦值意味着运动是从远到近。当离焦值接近零时,表示目标有焦。

  2. confident
    置信度是用于相位差估计的场景中线索数量(例如,垂直边缘,场景亮度)的函数。高置信度意味着ROI中的PD具有较小的方差和较高的边缘强度。置信表用于定义相对于传感器增益的最小置信阈值。
    high confidence:亮环境和多个垂直边缘。
    lower confidence 亮度低的环境和少的vertical edges。

3.Stable
稳定性是通过评估离焦值历史来计算的。如果值在可调阈值内,则认为场景是稳定的。

confidence table 如何工作
高置信度意味着该 ROI 中 PD 的偏差较小并且可能具有更高的边缘密度。 置信度表用于定义相对于传感器增益的最小置信度阈值.
噪点增益小于或等于某个参数noise gain时,对应Minimum Confidence。

4. PDAF不触发的 log 分析

(1)PDAF 触发
Trigger refocus condition : is_conf && is_defocused && is_stabl

	Line 16022: 03-31 16:07:14.492   892  1185 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:2040: af_pdaf_monitor is_conf 1, is_defocused 0, is_stable 1, is_trig_refocus 0
	Line 16426: 03-31 16:07:14.533   892  1189 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:1897: af_pdaf_monitor monitors: defocus_low 0, defocus_high 0 sad_panning 0, gyro_panning 0
	Line 16817: 03-31 16:07:14.575   892  1188 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:1897: af_pdaf_monitor monitors: defocus_low 1, defocus_high 0 sad_panning 0, gyro_panning 0
	Line 16821: 03-31 16:07:14.575   892  1188 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:1925: af_pdaf_monitor decisions of value monitors: defocus_low 1, defocus_high 0 sad_panning 0, gyro_panning 0 caf_face_is_stable 0 caf_track_is_stable 0
	Line 16822: 03-31 16:07:14.575   892  1188 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:1947: af_pdaf_monitor Spotlight flag 0,conf 1
	Line 16823: 03-31 16:07:14.576   892  1188 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:2040: af_pdaf_monitor is_conf 1, is_defocused 1, is_stable 1, is_trig_refocus 1
	Line 17204: 03-31 16:07:14.622   892  1189 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:1897: af_pdaf_monitor monitors: defocus_low 1, defocus_high 0 sad_panning 0, gyro_panning 0
	Line 17209: 03-31 16:07:14.622   892  1189 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:1925: af_pdaf_monitor decisions of value monitors: defocus_low 1, defocus_high 0 sad_panning 0, gyro_panning 0 caf_face_is_stable 0 caf_track_is_stable 0
	Line 17212: 03-31 16:07:14.622   892  1189 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:1947: af_pdaf_monitor Spotlight flag 0,conf 1

(2)is_defocused=FALSE 启用pd 对焦失败。
should be trigger refocus but it didn’t trigger again?

	Line 10866: 03-31 16:07:13.923   892  1186 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:5161: af_pdaf_proc_defocused roi(0) defocus=29, dof_mult=1.0, defocus_thres=26.5, defocus_cnt=6, min_defocus_cnt=1, is_defocused=TRUE
   Line 11444: 03-31 16:07:13.985   892  1187 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:5161: af_pdaf_proc_defocused roi(0) defocus=25, dof_mult=1.0, defocus_thres=26.5, defocus_cnt=0, min_defocus_cnt=1, is_defocused=FALSE
And please remember defocused condition: defocus_cnt >= min_defocus_cnt
  1. adjust Scene Monitor
  2. adjust Stable Table

(3)场景没用pdaf,启用CAF 对焦原因
focus_converge_done=true的条件
a. 场景稳定stable
b.PD Preprocessing -> PD Max Limit Do Not Use Defocus Sample > defocus

场景不稳定 
03-31 16:07:17.438   892  1189 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:3828: af_pdaf_is_focus_converge_done defocus=22, focus_converge_done_thres=20, focus_converge_done=FALSE
03-31 16:07:17.438   892  1189 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:3445: af_pdaf_focus_converge Scene is panning. No action until stable.
 场景稳定.  32 >26
	Line 8566: 03-31 16:07:13.591   892  1185 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:3828: af_pdaf_is_focus_converge_done defocus=26, focus_converge_done_thres=19, focus_converge_done=TRUE
	Line 44940: 03-31 16:07:17.484   892  1188 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:3828: af_pdaf_is_focus_converge_done defocus=6, focus_converge_done_thres=20, focus_converge_done=TRUE

 find the biggers dac and set the pd_max_limit_do_not_use_defocus_sample over this dac.
 If no, it means af_pdaf_is_focus_converge_done failed, return -1 and fallback to contrast af

(4)收敛完成进入finesearch

  • af_pdaf_focus_converge condition : need meet is_caf_stable and thenaf_pdaf_is_focus_converge_done return 1.

  • af_pdaf_is_focus_converge_done condition : abs(defocus)-abs(next_move) less thanfocus_done_thresh

  • next_move is returned by af_pdaf_get_focus_move_steps:

  • 03-31 16:07:17.438 892 1189 V CamX : [ VERB][STATS_AF ] af_haf_pdaf.cpp:4255: af_pdaf_get_focus_move_steps defocus=22.00, focus_pcnt=1.00, move_steps=22

  • focus_done_thresh equal focus_scan.focus_done_threshold * dof_multiplier * noise_multiplier

	Line 7461: 03-31 16:07:13.461   892  1189 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:3381: af_pdaf_focus_converge Adjust wait_conf_recover_cnt for focus convergence in first run = 4
	Line 7480: 03-31 16:07:13.462   892  1189 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:3445: af_pdaf_focus_converge Scene is panning. No action until stable.
	Line 7899: 03-31 16:07:13.503   892  1184 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:3381: af_pdaf_focus_converge Adjust wait_conf_recover_cnt for focus convergence in first run = 4
	Line 8197: 03-31 16:07:13.541   892  1187 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:3381: af_pdaf_focus_converge Adjust wait_conf_recover_cnt for focus convergence in first run = 4
	Line 8546: 03-31 16:07:13.590   892  1185 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:3381: af_pdaf_focus_converge Adjust wait_conf_recover_cnt for focus convergence in first run = 4
	Line 8569: 03-31 16:07:13.592   892  1185 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:3434: af_pdaf_focus_converge Converge done. Go to fine scan
	Line 44512: 03-31 16:07:17.438   892  1189 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:3445: af_pdaf_focus_converge Scene is panning. No action until stable.
	Line 44941: 03-31 16:07:17.484   892  1188 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:3434: af_pdaf_focus_converge Converge done. Go to fine scan

(5)状态查询

	Line 15400: 03-31 16:07:14.402   892  1185 V CamX    : [ VERB][STATS_AF ] af_haf.cpp:152: af_haf_util_change_state HAF_STATE_CHANGE to SEARCH
	Line 15405: 03-31 16:07:14.403   892  1185 V CamX    : [ VERB][STATS_AF ] af_haf.cpp:159: af_haf_util_change_state HAF_STATE_CHANGE to MONITOR
	Line 47337: 03-31 16:07:17.731   892  1187 V CamX    : [ VERB][STATS_AF ] af_haf.cpp:165: af_haf_util_change_state HAF_STATE_CHANGE to GO_TO_DEST

5. 注意

红框的内容会覆盖黑框的值。
AF算法已经支持使用不同的值监视器对不同光照条件的灵敏度。该算法采用AEC实数增益作为触发输入,在数值监测库中采用不同的灵敏度剖面。该功能默认关闭。
在这里插入图片描述

Sensitivity Trigger Arr 参数对应的xml 红框。
对于黑框矩形中的参数是每个值监视的默认灵敏度值,红色矩形中的参数默认不存在,它们是每个值监视的灵敏度触发器数组。算法会检查灵敏度触发器数组是否存在。如果触发器数组存在,它将使用它们而不是黑框矩形中的默认值。
在这里插入图片描述

算法将检查通过实增益是落在哪个区域。我们将比较传入的增益值和gain_start,所以请将gain_start和gain_end设置为相同的值

set_sensitivity_trigger
	Line 2962: 03-31 16:43:02.200   879  1179 V CamX    : [ VERB][STATS_AF ] af_haf_pdaf.cpp:5573: af_pdaf_set_sensitivity_trigger sensor gain changed :3.960967, check for VM sens update
	Line 2963: 03-31 16:43:02.200   879  1179 V CamX    : [ VERB][STATS_AF ] af_haf_caf.cpp:1328: af_caf_set_sensitivity_trigger sensor gain changed :3.960967, check for VM sens update


sensitivity_trigger_vm
vm 设置的无效没有对应的log
HAF_MSG_LOW("setting %s sensitivity to %d from %d", p_VM->name, sens, prev_sens);

参考:KBA-170501033706

  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值