如何以编程方式禁用网络摄像头的自动对焦? [英] How to programmatically disable the auto-focus of a webcam?

查看:174
本文介绍了如何以编程方式禁用网络摄像头的自动对焦?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用网络摄像头(型号为Hercules Dualpix)进行计算机视觉。我知道这不是理想的相机,但是我在这里别无选择。

I am trying to do computer vision using a webcam (the model is Hercules Dualpix). I know it is not the ideal camera to use, but I have no choice here.

问题是自动对焦使相机难以校准。任何人都知道禁用自动对焦功能的方法。或者,如果有人有想法要解决并通过自动对焦来校准相机。

The problem is the auto-focus makes it hard/impossible to calibrate the camera. Anyone knows a way to disable the auto-focus feature. Or, if someone has an idea to deal with it and calibrate the camera with the auto-focus.

推荐答案

Hercules相机是符合UVC,因此它们应与DirectShow接口配合使用 IAMCameraControl 。您可以将焦点设置为特定值,并使用标志来设置您不希望它是自动的。您可以使用 IAMCameraControl :: Get 轮询当前状态,因为并非所有相机都支持关闭焦点。

The Hercules cameras are UVC compliant, so they should work with the DirectShow Interface IAMCameraControl. You can set the focus to a specific value, and use the flags to set that you do not want it to be automatic. You can use IAMCameraControl::Get to poll the current state, because not all cameras do support turning off the focus.

IAMCameraControl *pCameraControl; 
HRESULT hr; 
hr = pFilter->QueryInterface(IID_IAMCameraControl, (void **)&pCameraControl); 
if (hr == S_OK) {
  long defaultFocusValue;
  hr = pCameraControl->GetRange(CameraControl_Focus,
                                NULL, // min
                                NULL, // max
                                NULL, // minstep
                                &defaultFocusValue, // default
                                NULL); // capflags
  hr = pCameraControl->Set(CameraControl_Focus, // property
                           defaultFocusValue, // value
                           CameraControl_Flags_Manual); 
} 

焦点有一个范围,该范围由每个摄像机分别定义,因此您应该查询如图所示,可以找到默认值和最小值,最大值。
在此示例中, pFilter 是指向DirectShow中的输入过滤器的指针。您可以通过
枚举设备并找到它来获取它您想要的那个。

Focus has a range which is defined by each camera separately, so you should query it as shown to find the default value and the min, max if you want. In this example the pFilter is a pointer to the input filter that you have from DirectShow. You can get it by enumerating the devices and finding the one you want.

这篇关于如何以编程方式禁用网络摄像头的自动对焦?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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