目录
1、IAMCameraControl::Get method
The IAMCameraControl interface controls camera settings such as zoom, pan, aperture adjustment, or shutter speed. To obtain this interface, query the filter that controls the camera.
IAMCameraControl接口控制相机设置,如缩放,平移,光圈调整,或快门速度。
一、相机有哪些控制属性
typedef enum tagCameraControlProperty {
CameraControl_Pan, //平移
CameraControl_Tilt, //倾斜
CameraControl_Roll, //滚动
CameraControl_Zoom, //缩放
CameraControl_Exposure, //曝光
CameraControl_Iris, //光圈
CameraControl_Focus //焦点
} CameraControlProperty;
就是这里的照相机控制的 基本参数
二、接口方法
1、IAMCameraControl::Get method
HRESULT Get(
long Property, //就是前面提到的相机设置属性CameraControlProperty enumeration
long *lValue, // Receives the value of the property.
long *Flags //Receives a member of the CameraControlFlags enumeration
);
typedef enum tagCameraControlFlags {
CameraControl_Flags_Auto, //The setting is controlled automatically.
CameraControl_Flags_Manual //The setting is controlled manually.
} CameraControlFlags;
2、IAMCameraControl::GetRange
The GetRange method gets the range and default value of a specified camera property.
HRESULT GetRange(
long Property, //Specifies the property to query
long *pMin, //Receives the minimum value of the property.
long *pMax, //Receives the maximum value of the property.
long *pSteppingDelta, //Receives the step size for the property.
long *pDefault, //Receives the default value of the property.
long *pCapsFlags //Receives a member of the CameraControlFlags enumeration
);
示例:
bool getVideoControlRange(long prop, long &min, long &max, long &step, long &dflt,long &flag) {
IAMCameraControl *lpCameraControl = NULL;
HRESULT hr = pInputFilter->QueryInterface(IID_IAMCameraControl, (void**)&lpCameraControl);
if (FAILED(hr)) return false;
hr = lpCameraControl->GetRange(prop, &min, &max, &step, &dflt, &flag);
lpCameraControl->Release();
if (FAILED(hr)) return false;
else return true;
}
又如:
// Query the capture filter for the IAMCameraControl interface.
IAMCameraControl *pCameraControl = 0;
hr = pDeviceFilter->QueryInterface(IID_IAMCameraControl, (void**)&pCameraControl);
if (FAILED(hr))
{
// The device does not support IAMCameraControl
}
else
{
long Min, Max, Step, Default, Flags, Val;
// Get the range and default values
hr = pCameraControl->GetRange(CameraControl_Exposure, &Min, &Max, &Step, &Default, &Flags);
hr = pCameraControl->GetRange(CameraControl_Focus, &Min, &Max, &Step, &Default, &Flags);
if (SUCCEEDED(hr))
{
hr = pCameraControl->Set(CameraControl_Exposure, -11, CameraControl_Flags_Manual ); // Min = -11, Max = 1, Step = 1
hr = pCameraControl->Set(CameraControl_Focus, 12, CameraControl_Flags_Manual );
}
}
再如:
HRESULT hr = 0;
IAMCameraControl *pCameraControl = NULL;
ControlInfo panInfo = { 0 };
ControlInfo tiltInfo = { 0 };
ControlInfo zoomInfo = { 0 };
long value = 0, flags = 0;
printf(" Reading pan/tilt property information ...\n");
// Get a pointer to the IAMCameraControl interface used to control the camera
hr = pBaseFilter->QueryInterface(IID_IAMCameraControl, (void **)&pCameraControl);
if(hr != S_OK)
{
fprintf(stderr, "ERROR: Unable to access IAMCameraControl interface.\n");
return hr;
}
// Retrieve information about the pan and tilt controls
hr = pCameraControl->GetRange(CameraControl_Pan, &panInfo.min, &panInfo.max, &panInfo.step, &panInfo.def, &panInfo.flags);
if(hr != S_OK)
{
fprintf(stderr, "ERROR: Unable to retrieve CameraControl_Pan property information.\n");
return hr;
}
printf(" Pan control:\n");
print_control_info(&panInfo);
hr = pCameraControl->GetRange(CameraControl_Tilt, &tiltInfo.min, &tiltInfo.max, &tiltInfo.step, &tiltInfo.def, &tiltInfo.flags);
if(hr != S_OK)
{
fprintf(stderr, "ERROR: Unable to retrieve CameraControl_Tilt property information.\n");
return hr;
}
printf(" Tilt control:\n");
print_control_info(&tiltInfo);
3、IAMCameraControl::Set
The Set method sets a specified property on the camera.
HRESULT Set(
long Property, //Specifies the property to set
long lValue, //Specifies the new value of the property.
long Flags //Specifies the desired control setting,
);
示例:
bool setVideoControlValue(long prop, long value, long flag){
IAMCameraControl *lpCameraControl = NULL;
HRESULT hr = pInputFilter->QueryInterface(IID_IAMCameraControl, (void**)&lpCameraControl);
if (FAILED(hr)) return false;
hr = lpCameraControl->Set(prop, value, flag);
lpCameraControl->Release();
if (FAILED(hr)) return false;
else return true;
}
4、一个综合例子
CameraControlMap ccToStr = {
{CameraControl_Pan , "Pan" },
{CameraControl_Tilt , "Tilt" },
{CameraControl_Roll , "Roll" },
{CameraControl_Zoom , "Zoom" },
{CameraControl_Exposure, "Exposure"},
{CameraControl_Iris , "Iris" },
{CameraControl_Focus , "Focus" }
};
QVariantList getCameraControls(IBaseFilter *filter) const
{
if (!filter)
return QVariantList();
qint32 min;
qint32 max;
qint32 step;
qint32 defaultValue;
qint32 flags;
qint32 value;
QVariantList controls;
IAMCameraControl *pCameraControl = NULL;
if (SUCCEEDED(filter->QueryInterface(IID_IAMCameraControl,
reinterpret_cast<void **>(&pCameraControl))))
{
for (const CameraControlProperty &cameraControl: ccToStr->keys()) {
if (SUCCEEDED(pCameraControl->GetRange(cameraControl,
reinterpret_cast<LONG *>(&min),
reinterpret_cast<LONG *>(&max),
reinterpret_cast<LONG *>(&step),
reinterpret_cast<LONG *>(&defaultValue),
reinterpret_cast<LONG *>(&flags))))
if (SUCCEEDED(pCameraControl->Get(cameraControl,
reinterpret_cast<LONG *>(&value),
reinterpret_cast<LONG *>(&flags)))) {
QVariantList control;
control << ccToStr->value(cameraControl)
<< QString("integer")
<< min
<< max
<< step
<< defaultValue
<< value
<< QStringList();
controls << QVariant(control);
}
}
pCameraControl->Release();
}
return controls;
}
bool setCameraControls(IBaseFilter *filter,
const QVariantMap &cameraControls) const
{
if (!filter)
return false;
IAMCameraControl *pCameraControl = NULL;
if (SUCCEEDED(filter->QueryInterface(IID_IAMCameraControl,
reinterpret_cast<void **>(&pCameraControl))))
{
for (const CameraControlProperty &cameraControl: ccToStr->keys()) {
QString cameraControlStr = ccToStr->value(cameraControl);
if (cameraControls.contains(cameraControlStr))
pCameraControl->Set(cameraControl,
cameraControls[cameraControlStr].toInt(),
CameraControl_Flags_Manual);
}
pCameraControl->Release();
}
return true;
}
参考资料:IAMCameraControl::GetRange (strmif.h) - Win32 apps | Microsoft Docs