Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

c++ - How to programmatically disable the auto-focus of a webcam?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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); 
} 

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...