XP下采用DirectShow采集摄像头.docx

上传人:b****3 文档编号:4990915 上传时间:2023-05-07 格式:DOCX 页数:38 大小:59.89KB
下载 相关 举报
XP下采用DirectShow采集摄像头.docx_第1页
第1页 / 共38页
XP下采用DirectShow采集摄像头.docx_第2页
第2页 / 共38页
XP下采用DirectShow采集摄像头.docx_第3页
第3页 / 共38页
XP下采用DirectShow采集摄像头.docx_第4页
第4页 / 共38页
XP下采用DirectShow采集摄像头.docx_第5页
第5页 / 共38页
XP下采用DirectShow采集摄像头.docx_第6页
第6页 / 共38页
XP下采用DirectShow采集摄像头.docx_第7页
第7页 / 共38页
XP下采用DirectShow采集摄像头.docx_第8页
第8页 / 共38页
XP下采用DirectShow采集摄像头.docx_第9页
第9页 / 共38页
XP下采用DirectShow采集摄像头.docx_第10页
第10页 / 共38页
XP下采用DirectShow采集摄像头.docx_第11页
第11页 / 共38页
XP下采用DirectShow采集摄像头.docx_第12页
第12页 / 共38页
XP下采用DirectShow采集摄像头.docx_第13页
第13页 / 共38页
XP下采用DirectShow采集摄像头.docx_第14页
第14页 / 共38页
XP下采用DirectShow采集摄像头.docx_第15页
第15页 / 共38页
XP下采用DirectShow采集摄像头.docx_第16页
第16页 / 共38页
XP下采用DirectShow采集摄像头.docx_第17页
第17页 / 共38页
XP下采用DirectShow采集摄像头.docx_第18页
第18页 / 共38页
XP下采用DirectShow采集摄像头.docx_第19页
第19页 / 共38页
XP下采用DirectShow采集摄像头.docx_第20页
第20页 / 共38页
亲,该文档总共38页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

XP下采用DirectShow采集摄像头.docx

《XP下采用DirectShow采集摄像头.docx》由会员分享,可在线阅读,更多相关《XP下采用DirectShow采集摄像头.docx(38页珍藏版)》请在冰点文库上搜索。

XP下采用DirectShow采集摄像头.docx

XP下采用DirectShow采集摄像头

XP下采用DirectShow采集摄像头

分类:

TCPMP/DDShow/音视频编解码技术2012-05-2416:

426602人阅读评论(14)收藏举报

xpnullgraphfilterinterfacefunction

目录(?

)[+]

1.一初始化工作

1.DirctShow环境初始化

2.搜索Video源

2.二选择某个摄像设备

1.先停止原有的Media

2.删除Graph

3.根据选择的设备的moniker来创建Graph

3.四开始播放

4.五pin特征的查看

5.六查询包含的filter信息

 

转载请标明是引用于 

欢迎大家提出意见,一起讨论!

需要示例源码的请独自联系我.

前提:

摄像头能正常工作、摄像头有创建directshowfilter

 

大家可以对比我的另一篇文章学习:

   wince系统下DirectShow采集摄像头

一、初始化工作

1、DirctShow环境初始化

[cpp]viewplaincopyprint?

1.bool  

2.uEye_DirectShow_Demo_Dlg:

:

DirectShow_Init()  

3.{  

4.    // initialize the COM library on the current thread  

5.    HRESULT err= CoInitialize(NULL);  

6.  

7.    if( FAILED(err))  

8.    {  

9.        MessageBoxEx( NULL, "Initializing COM library failed!

", __FUNCTION__, MB_ICONERROR, 0);  

10.    }  

11.  

12.    return err == S_OK;  

13.}  

bool

uEye_DirectShow_Demo_Dlg:

:

DirectShow_Init()

{

//initializetheCOMlibraryonthecurrentthread

HRESULTerr=CoInitialize(NULL);

if(FAILED(err))

{

MessageBoxEx(NULL,"InitializingCOMlibraryfailed!

",__FUNCTION__,MB_ICONERROR,0);

}

returnerr==S_OK;

}

2、搜索Video源

如果没有设备接入,那么CreateClassEnumerator会返回失败

[cpp]viewplaincopyprint?

1.bool  

2.uEye_DirectShow_Demo_Dlg:

:

VideoSourcesList_Fill()  

3.{  

4.    HRESULT status= S_OK;  

5.  

6.    // create System Device Enumerator  

7.    ICreateDevEnum *pSystemDeviceEnumerator= NULL;  

8.    status= CoCreateInstance(  CLSID_SystemDeviceEnum,  

9.                                NULL,  

10.                                CLSCTX_INPROC,  

11.                                IID_ICreateDevEnum,  

12.                                (void**)&pSystemDeviceEnumerator);  

13.    if( FAILED(status))  

14.    {  

15.        MessageBoxEx( NULL, "Creating System Device Enumerator failed!

", __FUNCTION__, MB_ICONERROR, 0);  

16.        return false;  

17.    }  

18.  

19.    // create Class Enumerator that lists alls video input devices among the system devices  

20.    IEnumMoniker *pVideoInputDeviceEnumerator= NULL;  

21.    status= pSystemDeviceEnumerator->CreateClassEnumerator( CLSID_VideoInputDeviceCategory,  

22.                                                            &pVideoInputDeviceEnumerator,  

23.                                                            0);  

24.  

25.    // release the System Device Enumerator which is not needed anymore  

26.    pSystemDeviceEnumerator->Release();  

27.    pSystemDeviceEnumerator= NULL;  

28.  

29.    if( status !

= S_OK)  

30.    {  

31.        MessageBoxEx( NULL, "Creating Class Enumerator failed!

", __FUNCTION__, MB_ICONERROR, 0);  

32.        return false;  

33.    }  

34.  

35.    // add entry '[no device selected]' to list  

36.    m_comboVideoSources.AddString( "[no device selected]");  

37.    m_comboVideoSources.SetItemDataPtr( 0, NULL);  

38.  

39.    // for each enumerated video input device:

 add it to the list  

40.    IMoniker *pMoniker= NULL;  

41.    while( pVideoInputDeviceEnumerator->Next( 1, &pMoniker, NULL) == S_OK )  

42.    {  

43.        VARIANT var;  

44.        VariantInit(&var);  

45.  

46.        // make filters properties accessible  

47.        IPropertyBag *pPropBag= NULL;  

48.        status= pMoniker->BindToStorage( 0, 0, IID_IPropertyBag, (void**)&pPropBag);  

49.        if( FAILED(status))  

50.        {  

51.            pPropBag= NULL;  

52.            MessageBoxEx( NULL, "Accessing filter properties failed!

", __FUNCTION__, MB_ICONERROR, 0);  

53.            // continue with the next filter  

54.        }  

55.        else  

56.        {  

57.            // add a reference to the storage object  

58.            pPropBag->AddRef();  

59.  

60.            // get the name of this filter  

61.            status= pPropBag->Read( L"FriendlyName", &var, 0);  

62.            if( FAILED(status))  

63.            {  

64.                MessageBoxEx( NULL, "Reading filter name failed!

", __FUNCTION__, MB_ICONERROR, 0);  

65.                // continue with the next filter  

66.            }  

67.            else  

68.            {  

69.                // if uEye Capture Device:

  

70.                // add filtername to the list and link the moniker pointer to the list entry  

71.                CString sTemp(var.bstrVal);  

72.#if (0) /* jma [04/08/2010] add devices named UI... too */  

73.                if( sTemp.Find( "uEye Capture Device", 0) !

= -1)  

74.#endif  

75.                if ((sTemp.Find( "uEye Capture Device", 0) !

= -1) || (sTemp.Find( "UI", 0) !

= -1))  

76.                {  

77.                    int index = m_comboVideoSources.AddString( sTemp);  

78.                    // dont forget to release the moniker later!

  

79.                    m_comboVideoSources.SetItemDataPtr( index, pMoniker);  

80.                }  

81.                else  

82.                {  

83.                    pMoniker->Release();  

84.                    pMoniker= NULL;  

85.                }  

86.            }  

87.  

88.            // release the reference to the storage object  

89.            pPropBag->Release();  

90.            pPropBag= NULL;  

91.        }  

92.  

93.        VariantClear(&var);  

94.    }  

95.  

96.    // release the class enumerator  

97.    pVideoInputDeviceEnumerator->Release();  

98.    pVideoInputDeviceEnumerator= NULL;  

99.  

100.    // select first list entry  

101.    m_comboVideoSources.SetCurSel( 0);  

102.  

103.    return false;  

104.}  

bool

uEye_DirectShow_Demo_Dlg:

:

VideoSourcesList_Fill()

{

HRESULTstatus=S_OK;

//createSystemDeviceEnumerator

ICreateDevEnum*pSystemDeviceEnumerator=NULL;

status=CoCreateInstance(CLSID_SystemDeviceEnum,

NULL,

CLSCTX_INPROC,

IID_ICreateDevEnum,

(void**)&pSystemDeviceEnumerator);

if(FAILED(status))

{

MessageBoxEx(NULL,"CreatingSystemDeviceEnumeratorfailed!

",__FUNCTION__,MB_ICONERROR,0);

returnfalse;

}

//createClassEnumeratorthatlistsallsvideoinputdevicesamongthesystemdevices

IEnumMoniker*pVideoInputDeviceEnumerator=NULL;

status=pSystemDeviceEnumerator->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,

&pVideoInputDeviceEnumerator,

0);

//releasetheSystemDeviceEnumeratorwhichisnotneededanymore

pSystemDeviceEnumerator->Release();

pSystemDeviceEnumerator=NULL;

if(status!

=S_OK)

{

MessageBoxEx(NULL,"CreatingClassEnumeratorfailed!

",__FUNCTION__,MB_ICONERROR,0);

returnfalse;

}

//addentry'[nodeviceselected]'tolist

m_comboVideoSources.AddString("[nodeviceselected]");

m_comboVideoSources.SetItemDataPtr(0,NULL);

//foreachenumeratedvideoinputdevice:

addittothelist

IMoniker*pMoniker=NULL;

while(pVideoInputDeviceEnumerator->Next(1,&pMoniker,NULL)==S_OK)

{

VARIANTvar;

VariantInit(&var);

//makefilterspropertiesaccessible

IPropertyBag*pPropBag=NULL;

status=pMoniker->BindToStorage(0,0,IID_IPropertyBag,(void**)&pPropBag);

if(FAILED(status))

{

pPropBag=NULL;

MessageBoxEx(NULL,"Accessingfilterpropertiesfailed!

",__FUNCTION__,MB_ICONERROR,0);

//continuewiththenextfilter

}

else

{

//addareferencetothestorageobject

pPropBag->AddRef();

//getthenameofthisfilter

status=pPropBag->Read(L"FriendlyName",&var,0);

if(FAILED(status))

{

MessageBoxEx(NULL,"Readingfilternamefailed!

",__FUNCTION__,MB_ICONERROR,0);

//continuewiththenextfilter

}

else

{

//ifuEyeCaptureDevice:

//addfilternametothelistandlinkthemonikerpointertothelistentry

CStringsTemp(var.bstrVal);

#if(0)/*jma[04/08/2010]adddevicesnamedUI...too*/

if(sTemp.Find("uEyeCaptureDevice",0)!

=-1)

#endif

if((sTemp.Find("uEyeCaptureDevice",0)!

=-1)||(sTemp.Find("UI",0)!

=-1))

{

intindex=m_comboVideoSources.AddString(sTemp);

//dontforgettoreleasethemonikerlater!

m_comboVideoSources.SetItemDataPtr(index,pMoniker);

}

else

{

pMoniker->Release();

pMoniker=NULL;

}

}

//releasethereferencetothestorageobject

pPropBag->Release();

pPropBag=NULL;

}

VariantClear(&var);

}

//releasetheclassenumerator

pVideoInputDeviceEnumerator->Release();

pVideoInputDeviceEnumerator=NULL;

//selectfirstlistentry

m_comboVideoSources.SetCurSel(0);

returnfalse;

}

二、选择某个摄像设备

1、先停止原有的Media

[cpp]viewplaincopyprint?

1.bool  

2.uEye_DirectShow_Demo_Dlg:

:

FilterGraph_Stop()  

3.{  

4.    Invalidate();  

5.  

6.    // proceed only if filter graph manager object present  

7.    if( m_pActiveFilterGraphManager == NULL)  

8.    {  

9.        return true;  

10.    }  

11.  

12.    HRESULT status= S_OK;  

13.  

14.    // get the MediaControl interface of the graph  

15.    IMediaControl* pMediaControl= NULL;  

16.    status= m_pActiveFilterGraphManager->QueryInterface( IID_IMediaControl, (void**)&pMediaControl);  

17.    if( FAILED(status) || pMediaControl == NULL)  

18.    {  

19.        MessageBoxEx( NULL, "Querying MediaControl interface of the filter graph manager failed!

", __FUNCTION__, MB_ICONERROR, 0);  

20.        return false;  

21.    }  

22.  

23.    //// check for graph to be executing before allowing to stop  

24.  

25.    //OAFilterState filterState= 0;   // OAFilterState is actually a long  

26.    //status= pMediaControl->GetState( 100, &filterState);  

27.    //if( FAILED(status))  

28.    //{  

29.    //    // cleanup  

30.  

31.    //    // release the MediaControl interface object  

32.    //    pMediaControl->Release();  

33.    //    pMediaControl= NULL;  

34.  

35.    //    MessageBoxEx( NULL, "Querying gra

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 工程科技 > 信息与通信

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2