第44讲 af自动对焦实战 -凯发k8手机登录

本讲是android camera专题系列的第44讲,我们介绍android camera2 api专题的af自动对焦实战。

更多资源:

资源 描述
在线课程
知识星球 星球名称:深入浅出android camera
星球id: 17296815
wechat 极客笔记圈

连续(被动)对焦(continuous af)

判断支持哪些af mode

int [] supported_focus_modes = characteristics.get(cameracharacteristics.control_af_available_modes); // android format
camera_features.supported_focus_values = convertfocusmodestovalues(supported_focus_modes, camera_features.minimum_focus_distance); // convert to our format (also resorts)

设置af mode

private void setfocusmode(capturerequest.builder builder) {
    if( has_af_mode ) {
        if( mydebug.log )
            log.i(tag, "[af_practise] setfocusmode change af mode to "   af_mode);
        builder.set(capturerequest.control_af_mode, af_mode);
    }
    else {
        if( mydebug.log ) {
            log.i(tag, "af mode left at "   builder.get(capturerequest.control_af_mode));
        }
    }
}

监听af results

if (mydebug.log) {
    if (result.get(captureresult.control_af_state) != null) {
        int afstate = result.get(captureresult.control_af_state);
        string afstatestr = "";
        switch (afstate) {
            case captureresult.control_af_state_inactive:
                afstatestr = "inactive";
                break;
            case captureresult.control_af_state_passive_scan:
                afstatestr = "passive_scan";
                break;
            case captureresult.control_af_state_passive_focused:
                afstatestr = "passive_focused";
                break;
            case captureresult.control_af_state_active_scan:
                afstatestr = "active_scan";
                break;
            case captureresult.control_af_state_focused_locked:
                afstatestr = "focused_locked";
                break;
            case captureresult.control_af_state_not_focused_locked:
                afstatestr = "not_focused_locked";
                break;
            case captureresult.control_af_state_passive_unfocused:
                afstatestr = "passive_unfocused";
                break;
            default:
                break;
        }
        if (mprintresultcounter % 30 == 0 ||
            result.get(captureresult.lens_state) == captureresult.lens_state_moving) {
            log.i(tag, "[af_practise] af_state:"   afstatestr  
                    ", af mode:"   result.get(captureresult.control_af_mode)  
                    ", af scene changed:"   result.get(captureresult.control_af_scene_change)  
                    ", lens state:"   result.get(captureresult.lens_state)  
                    ", focus distance:"   result.get(captureresult.lens_focus_distance)  
                    ", focus range:"   result.get(captureresult.lens_focus_range));
        }
    }
}

主动对焦(touch af)

geekcamera2 代码逻辑:

preview#touchevent
|---->cameracontroller2#setfocusandmeteringarea
|-------->camerasettings#setafregions //设置对焦区域
|---->cameracontroller2#autofocus // 触发对焦
cameracontroller2#handlestatechange //监听touch af结果

camera课程

python教程

java教程

web教程

数据库教程

图形图像教程

办公软件教程

linux教程

计算机教程

大数据教程

开发工具教程

android camera2 api

网站地图