我如何监控 android 相机的当前焦距 [英] How can i monitor the current FocalLength of android Camera

查看:50
本文介绍了我如何监控 android 相机的当前焦距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SurfaceView 保存相机预览.我已将相机对焦模式设置为:Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO

I have a SurfaceView that holds a Camera Preview. I have set the camera focus mode to: Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO

并添加了自动对焦回调.当我运行应用程序时,我可以看到相机实时调整其焦点,但是 autoFocusCallback 只会被触发一次,并且当它触发时,它总是返回相同的值.(2.95) 无论我离焦点对象多近或多远.

and added an AutoFocus callback. When i run the app, i can see the camera adjusting its' focus in real time, but the autoFocusCallback only ever gets fired once, and when it does, it always returns the same value. (2.95) regardless of how close or far i am from an in focus object.

想知道我做错了什么......甚至有可能获得有关实际焦距的实时信息吗?

Wondering what i am doing wrong.. is it even possible to get real time info on what the actual focal length is?

我的SurfaceViewonSurfaceChanged 代码:

SurfaceHolder.Callback surfaceHolderListener = new SurfaceHolder.Callback() {

            public void surfaceCreated(SurfaceHolder holder) {
                camera=Camera.open();
            try {
                camera.setPreviewDisplay(previewHolder);
               camera.setDisplayOrientation(90);

            }
                catch (Throwable e){ }
            }
            public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
            {

                Parameters params = camera.getParameters();
               Rect centralFocusArea = new Rect();
               centralFocusArea.set(holder.getSurfaceFrame().width()/2-10, holder.getSurfaceFrame().height()/2-10, holder.getSurfaceFrame().width()/2+10, holder.getSurfaceFrame().height()/2+10);

               ArrayList<Camera.Area> focusAreas = new ArrayList<Camera.Area>();
               focusAreas.add(new Camera.Area(centralFocusArea, 1000));

                //params.setPreviewSize(width, height);
                params.setPictureFormat(PixelFormat.JPEG);
                params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
               // params.setFocusAreas(focusAreas);
                camera.setParameters(params);

                camera.startPreview();
                camera.autoFocus(new AutoFocusCallback() {

                    @Override
                    public void onAutoFocus(boolean success, Camera camera) {
                        // TODO Auto-generated method stub
                        Log.v("CAMERA", "FOCUS CHANGE:"+camera.getParameters().getFocalLength());
                        camera.getParameters().setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);

                    }
                });

            }
            public void surfaceDestroyed(SurfaceHolder arg0)
            {
                camera.stopPreview();
                camera.release();
            }

        };

推荐答案

尽管 Android 规范中明确定义了该参数,但大多数 Android 实现都没有为焦距提供合适的值.前段时间,我检查了三个不同的相机,都没有提供有用的信息.

Most Android implementations do not provide a proper value for the focus distance, despite the parameter being well-defined in the Android specification. Some time ago, I checked three different cameras, and none of them provided useful information.

这篇关于我如何监控 android 相机的当前焦距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆