本文介绍了从网络摄像头捕获图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是DirectShow编程的新手.我试图创建一个没有接口的非常基本的应用程序.这个主意 是每10分钟捕获一次(静止)图像,但是我很难从网络摄像头中获取图像.我已经下载了示例,但由于它们具有界面或正在捕获视频而不是图像,因此无法获得更多信息.这是 应该捕获图像的代码,我从那里开始卡住了..:( 我想让这个函数返回一个位图)

Hello, I am quite new to DirectShow programming. I am trying to create a very basic application without an interface. The idea is to capture an (still) image every 10 minutes, but I am having troubles to get a image from my webcam. I've downloaded the samples but am not getting any further since these are having an interface or are capturing videos instead of an image. This is the code that should capture the image, im stuck from there..: (I'd like to have this function return a bitmap)



 

 //Verbinding met de camera
 private void SetupGraph(DsDevice pDevice)
 {
 int hr;
 IBaseFilter capFilter = null;
 IBaseFilter iSmartTee = null;
 ISampleGrabber SampleGrabber = null;
 IBaseFilter SampleGrabberBase = null;

 //Connect Pins
 IPin pCamCapture;
 IPin pSTIn;
 IPin pSTCapture;
 IPin pSTPreview;
 IPin pRIn;
 IPin pSGIn;

 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Graph  ------------------------------------------------     /- Capture (pSTCapture) -> (pRIn) Video Renderer   //
 // Camera -- Capture (pCamCapture) -> (pSTIn) Smart Tee -- Preview (pSTPreview) -> (pSGIn) SampleGrabber -- Output (pSGOut) -> FileWriter. //
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 //Maak een 'holder' voor een filter aan
 m_Filter = new FilterGraph() as IFilterGraph2;

 //voeg de camera filter toe
 hr = m_Filter.AddSourceFilterForMoniker(pDevice.Mon, null, pDevice.Name, out capFilter);
 //Camera Capture Pin
 pCamCapture = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0);

 //splitter maken
 iSmartTee = (IBaseFilter)new SmartTee();
 //Splitter pins
 pSTIn = DsFindPin.ByDirection(iSmartTee, PinDirection.Input, 0);
 pSTCapture = DsFindPin.ByName(iSmartTee, "Capture");
 pSTPreview = DsFindPin.ByName(iSmartTee, "Preview");
 //splitter toevoegen aan de filtergraph
 hr = m_Filter.AddFilter(iSmartTee, "iSmartTee");
 //splitter verbinden met de camera
 hr = m_Filter.Connect(pCamCapture, pSTIn);

 //SampleGrabber maken
 SampleGrabber = new SampleGrabber() as ISampleGrabber;
 //SampleGrabber configureren
 SampleGrabberBase = SampleGrabber as IBaseFilter;
 #region configuration
 AMMediaType media = new AMMediaType();
 media.majorType = MediaType.File;
 media.subType = MediaSubType.RGB32;
 media.formatType = FormatType.VideoInfo;
 SampleGrabber.SetMediaType(media);
 #endregion



 }

推荐答案


这篇关于从网络摄像头捕获图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 22:23