前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android Camera开发系列:设置对焦模式模式

Android Camera开发系列:设置对焦模式模式

原创
作者头像
小驰随想录
修改2021-04-19 17:56:17
1.7K0
修改2021-04-19 17:56:17
举报
文章被收录于专栏:Android Camera开发Android Camera开发

你对android camera的对焦模式熟悉吗?

知道什么场景下该设置哪种对焦模式吗?

本文针对下面2点展开介绍,和大家一起学习~

代码语言:javascript
复制
一、有哪几种对焦模式?
二、如何使用各种对焦模式?

一、有哪几种对焦模式?

1)获取设备支持的对焦模式

Google为我们提供了查询当前设备支持的对焦模式的接口~

Camera1获取对焦模式接口:

代码语言:javascript
复制
----- Camera.java

        public String getFocusMode() {
            return get(KEY_FOCUS_MODE);
        }

Camera2获取对焦模式接口:

代码语言:javascript
复制
----- CameraCharacteristics.java

    @PublicKey
    public static final Key<int[]> CONTROL_AF_AVAILABLE_MODES =
            new Key<int[]>("android.control.afAvailableModes", int[].class);
2)各种对焦模式的介绍

这里只介绍常用的几种对焦模式,详解的介绍,可以查看文末附的源码内容。 我们常用的也就下面4种对焦模式。

代码语言:javascript
复制
    public static final String FOCUS_MODE_AUTO = "auto";
    public static final String FOCUS_MODE_FIXED = "fixed";
    public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video";
    public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture";
代码语言:javascript
复制
   FOCUS_MODE_AUTO:自动对焦,这个只会触发一次对焦,并且是需要在预览开启后,调用autoFocus接口后才会触发,
像触点对焦、和拍照对焦都可以用到该模式;
   FOCUS_MODE_FIXED:定焦,有些摄像头本身不支持对焦;
   FOCUS_MODE_CONTINUOUS_VIDEO:录像的时候,可以采用该模式,会持续对焦,设置parameter参数后就会生效;
   FOCUS_MODE_CONTINUOUS_PICTURE :拍照的时候,可以采用该模式,会持续对焦,设置parameter参数后就会生效,对焦速度相对 
   FOCUS_MODE_CONTINUOUS_VIDEO 会快点;

三、如何使用各种对焦模式?

上面第二点针对4种常见的对焦模式,做了简单的介绍,我们也知道,除了auto模式,像 FOCUS_MODE_CONTINUOUS_VIDEO、FOCUS_MODE_CONTINUOUS_PICTURE 模式,是在设置camera parameter参数后就生效。

下面来看下google给我们提供了哪些调用接口:

1)Camera1
代码语言:javascript
复制
      public final void autoFocus(AutoFocusCallback cb)
      {
        ...
       }

      public void setFocusMode(String value) {
            ...
      }

      public void setParameters(Parameters params) {
         ...
       }

      public final void cancelAutoFocus()
      {
        ...
      }
2)Camera2
代码语言:javascript
复制
request.set(CaptureRequest.CONTROL_AF_MODE, int focusMode);

各种对焦模式的介绍?(贴的Android源码里面的介绍,写的够详细)
代码语言:javascript
复制
       /**
         * Auto-focus mode. Applications should call {@link
         * #autoFocus(AutoFocusCallback)} to start the focus in this mode.
         */
        public static final String FOCUS_MODE_AUTO = "auto";

        /**
         * Focus is set at infinity. Applications should not call
         * {@link #autoFocus(AutoFocusCallback)} in this mode.
         */
        public static final String FOCUS_MODE_INFINITY = "infinity";

        /**
         * Macro (close-up) focus mode. Applications should call
         * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
         * mode.
         */
        public static final String FOCUS_MODE_MACRO = "macro";

        /**
         * Focus is fixed. The camera is always in this mode if the focus is not
         * adjustable. If the camera has auto-focus, this mode can fix the
         * focus, which is usually at hyperfocal distance. Applications should
         * not call {@link #autoFocus(AutoFocusCallback)} in this mode.
         */
        public static final String FOCUS_MODE_FIXED = "fixed";

        /** @hide
         * Normal focus mode. Applications should call
         * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
         * mode.
         */
        public static final String FOCUS_MODE_NORMAL = "normal";

        /**
         * Extended depth of field (EDOF). Focusing is done digitally and
         * continuously. Applications should not call {@link
         * #autoFocus(AutoFocusCallback)} in this mode.
         */
        public static final String FOCUS_MODE_EDOF = "edof";

        /**
         * Continuous auto focus mode intended for video recording. The camera
         * continuously tries to focus. This is the best choice for video
         * recording because the focus changes smoothly . Applications still can
         * call {@link #takePicture(Camera.ShutterCallback,
         * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the
         * subject may not be in focus. Auto focus starts when the parameter is
         * set.
         *
         * <p>Since API level 14, applications can call {@link
         * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will
         * immediately return with a boolean that indicates whether the focus is
         * sharp or not. 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_PICTURE
         */
        public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video";

        /**
         * 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.
         *
         * <p>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
         */
        public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture";

本人从事Android Camera相关开发已有5年

目前在深圳上班

欢迎大家关注我的微信公众号“小驰笔记”

大家一起学习交流

---- 2020.01.04 深圳

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、有哪几种对焦模式?
    • 1)获取设备支持的对焦模式
      • 2)各种对焦模式的介绍
      • 三、如何使用各种对焦模式?
        • 1)Camera1
          • 2)Camera2
          • 附:
            • 各种对焦模式的介绍?(贴的Android源码里面的介绍,写的够详细)
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档