如何锁定自动对焦 [英] How to lock autofocus

查看:253
本文介绍了如何锁定自动对焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用任何标准库(例如OpenCV,EmGU,DirectShow等)来阻止自动聚焦?

Is there a way to prevent auto-focus from focusing, using any of the "standard" libraries, such as OpenCV, EmGU, DirectShow, etc?

I要自动对焦以找到最佳对焦,然后在视频捕获期间防止自动对焦自动对焦。

I want auto-focus to find the optimal focus, then during video capture, prevent auto-focus from auto-focusing.

我知道我可以手动设置该值,但是达不到使用自动对焦的目的,我还没有找到一种方法来获得由自动对焦确定的最佳对焦值。

I know I can manually set the value, but that defeats the purpose of using auto-focus, and I have yet to find a way to obtain the optimal focus value as determined by the auto-focus.

推荐答案

您可以检测校准阶段(找到最佳焦点时)何时聚焦图像,并保存该配置(聚焦距离)。然后将焦点设置为保存的值,并在捕获阶段之前禁用自动聚焦。要找到最佳聚焦距离,您可以从最接近的(宏观)聚焦距离开始,然后逐渐将其提高到最大,以测量图像的聚焦程度。

You can detect when the image is focused during calibration phase (when you are finding the optimal focus) and save that configuration (focus distance). Then set the focus to the saved value and disable auto-focus before capturing phase. To find the optimal focus distance you can start with the most close (macro) focus distance and gradualy raise it to maximum, measuring how focused the image is.

SO问题有一个答案,该答案描述了如何测量图像是否聚焦。您可以使用 OpenCV Laplacian()

This SO question has an answer that describes how to measure if the image is focused or not. You can use OpenCV Laplacian() (Emgu.CV) to achieve that.


关键是对焦图像具有更强的渐变和清晰的功能。 。因此,我建议您应用高斯拉普拉斯滤波器,然后查看结果像素值的分布。焦点对准的图像具有更高的值(因为图像具有更清晰的渐变)。

The key is that in-focus image has much more strong gradients and sharp features. So what I suggest is to apply a Gaussian Laplace filter and then look at the distribution of pixel values of the result. The in-focus one has much more high values (because the image has more sharp gradients).

确定最佳焦点的另一种有趣方式在本文中进行了描述。该技术在NASA好奇号火星探测器中使用。这个想法是对帧进行JPEG压缩,并使用jpeg的大小作为焦点的度量。

Another interesting way to determine best focus is described in this article. The technique is used in the NASA Curiosity Mars Rover. The idea is to JPEG-compress the frames and use the size of jpegs as the measure of focus.


自动对焦命令指示相机进行移动到指定的起始马达计数位置并收集图像,移动指定的步数并收集另一幅图像,并一直这样做,直到达到命令的总图像数,每幅图像均以指定的马达计数增量分开。这些图像中的每一个都是JPEG压缩的(Joint Photographic Experts Group;请参阅CCITT(1993)),并应用了相同的压缩质量因子。每个压缩图像的文件大小是场景细节的量度,而细节又是焦点的功能(焦点图像比同一场景的焦点视图模糊而不是模糊显示更多细节)。

The autofocus command instructs the camera to move to a specified starting motor count position and collect an image, move a specified number of steps and collect another image, and keep doing so until reaching a commanded total number of images, each separated by a specified motor count increment. Each of these images is JPEG compressed (Joint Photographic Experts Group; see CCITT (1993)) with the same compression quality factor applied. The file size of each compressed image is a measure of scene detail, which is in turn a function of focus (an in-focus image shows more detail than a blurry, out of focus view of the same scene).

OpenCV imencode() Emgu.CV )可用于以JPEG格式压缩图像。

OpenCV imencode() (Emgu.CV) can be used to compress the image in JPEG.

如果您要关注一些特定的稳定对象或区域,并且您能够计算/识别其固定位置,则只应处理该区域即可确定最佳焦点。在第一种方法中,如果知道对象的形状,则可以将 Laplacian 应用于裁剪的矩形区域,甚至不使用矩形遮罩进行结果焦点值计算。第二种方法也一样-仅压缩要关注的感兴趣区域。如果要使其不处理矩形区域并知道该区域的形状,请首先将未覆盖要聚焦的区域的所有像素设置为相同的颜色。它将使算法不考虑您不需要关注的区域。

If you want to focus on some specific stable object or area and you are able to calculate / recognize its fixed position, you should process only that area to determine best focus. In the first approach you can apply Laplacian to cropped rectangular area or even use not rectangular mask for result "focus value" calculation if you know shape of the object. The same is for the second approach - compress only the region of interest you want to focus at. If you want it to process not rectangular areas and know the shape of the region, first set all pixels which do not cover the region you focus at to same color. It will make the algorithm not to take account of regions you do not need to be focused.

这篇关于如何锁定自动对焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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