相机控制 IAMCameraControl 接口

目录

一、相机有哪些控制属性

二、接口方法

1、IAMCameraControl::Get method

2、IAMCameraControl::GetRange 

3、IAMCameraControl::Set

4、一个综合例子


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清水迎朝阳

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值