摄像头参数的设置

F项目进行到最终界面设计阶段了。在把320x240分辨率的摄像头图像放到640x480的视窗之后,解析度很低,决定添加让用户选择分辨率的界面。

先看了DirectX自带的AmCap Sample,在里面找到这样一段代码:

                IAMStreamConfig  * pSC;
                hr 
=  gcap.pBuilder -> FindInterface( & PIN_CATEGORY_CAPTURE,
                    
& MEDIATYPE_Interleaved, gcap.pVCap,
                    IID_IAMStreamConfig, (
void   ** ) & pSC);

                
if (hr  !=  NOERROR)
                    hr 
=  gcap.pBuilder -> FindInterface( & PIN_CATEGORY_CAPTURE,
                        
& MEDIATYPE_Video, gcap.pVCap,
                        IID_IAMStreamConfig, (
void   ** ) & pSC);

                ISpecifyPropertyPages 
* pSpec;
                CAUUID cauuid;

                hr 
=  pSC -> QueryInterface(IID_ISpecifyPropertyPages,
                    (
void   ** ) & pSpec);

                
if (hr  ==  S_OK)
                
{
                    hr 
= pSpec->GetPages(&cauuid);
                    hr 
= OleCreatePropertyFrame(ghwndApp, 3030, NULL, 1,
                        (IUnknown 
**)&pSC, cauuid.cElems,
                        (GUID 
*)cauuid.pElems, 00, NULL);

                    
// !!! What if changing output formats couldn't reconnect
                    
// and the graph is broken?  Shouldn't be possible

                    
if(gcap.pVSC)
                    
{
                        AM_MEDIA_TYPE 
*pmt;
                        
// get format being used NOW
                        hr = gcap.pVSC->GetFormat(&pmt);

                        
// DV capture does not use a VIDEOINFOHEADER
                        if(hr == NOERROR)
                        
{
                            
if(pmt->formattype == FORMAT_VideoInfo)
                            
{
                                
// resize our window to the new capture size
                                ResizeWindow(HEADER(pmt->pbFormat)->biWidth,
                                    abs(HEADER(pmt
->pbFormat)->biHeight));
                            }

                            DeleteMediaType(pmt);
                        }

                    }


                    CoTaskMemFree(cauuid.pElems);
                    pSpec
->Release();
                }


                pSC
-> Release();

先是用ICaptureGraphBuilder2::FindInterface将Capture Filter的属性读到IAMStreamConfig中,再通过QueryInterface将IAMStreamConfig与 ISpecifyPropertyPages关联起来,然后利用OLE自带的OleCreatePropertyFrame来生成属性页面,供用户选取。
后面的代码是根据读到的信息调整UI,并作些结束处理。

以上实地一种方法,但是每次都要选择才能达到640x480的分辨率,感觉很不人性化,假如用户希望定义默认值为640x480而不是320x240,那就需要别的方法了。
在DirectX的文档中看到这样一篇文章:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/anch_directx.asp

先把Capture Filter的属性读到IAMStreamConfig:
IAMStreamConfig  * pConfig  =  NULL;
hr 
=  pBuild -> FindInterface(
    
& PIN_CATEGORY_PREVIEW,  //  Preview pin.
     0 ,     //  Any media type.
    pCap,  //  Pointer to the capture filter.
    IID_IAMStreamConfig, ( void ** ) & pConfig);

然后将属性中的每个AM_MEDIA_TYPE读出,处理。
int  iCount  =   0 , iSize  =   0 ;
hr 
=  pConfig -> GetNumberOfCapabilities( & iCount,  & iSize);

//  Check the size to make sure we pass in the correct structure.
if  (iSize  ==   sizeof (VIDEO_STREAM_CONFIG_CAPS)
{
    
// Use the video capabilities structure.

    
for (int iFormat = 0; iFormat < iCount; iFormat++)
    
{
        VIDEO_STREAM_CONFIG_CAPS scc;
        AM_MEDIA_TYPE 
*pmtConfig;
        hr 
= pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc);
        
if (SUCCEEDED(hr))
        
{
            
/* Examine the format, and possibly use it. */

            
// Delete the media type when you are done.
            DeleteMediaType(pmtConfig);
        }

}

在这里我要做的是,在众多支持的AM_MEDIA_TYPE中挑选一种合适的,作为默认选项。
                 if  ((pmtConfig -> majortype  ==  MEDIATYPE_Video)  &&
                    (pmtConfig
-> subtype  ==  MEDIASUBTYPE_RGB24)  &&
                    (pmtConfig
-> formattype  ==  FORMAT_VideoInfo)  &&
                    (pmtConfig
-> cbFormat  >=   sizeof  (VIDEOINFOHEADER))  &&
                    (pmtConfig
-> pbFormat  !=  NULL))
                
{
                    VIDEOINFOHEADER 
*pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat;
                    
// pVih contains the detailed format information.
                    LONG lWidth = pVih->bmiHeader.biWidth;
                    LONG lHeight 
= pVih->bmiHeader.biHeight;
                    
if(lWidth == 640)
                        pSC
->SetFormat(pmtConfig);
                }
以上代码放在 /* Examine the format, and possibly use it. */ 后。

这样,初始模式就设在了640x480上,但是如果设备不支持640,就不会更改了。

第二种方法也成功了。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值