becheras86 wrote:
> [mod-- What have you tried so far? --mod PN]
> 
> Dear all,
> 
> I would like to capture live images through a webcam using a GUI but I dunno 
> how.
> 
> I have basic knowledge in OpenCV and I'm currently using visual studio 2010.
> 
> Can anyone guide me pls :)

VS 2010 is in Beta.  I don't touch that stuff.  If you want to risk 
destroying your Windows install, be my guest.

I recently answered a similar question, so you should search the c-prog 
archives.  Most webcams utilize DirectShow (a small piece of DirectX) to 
do the live feed.  To do DirectShow programming, you will need the 
DirectX SDK.  You may also get some mileage from Windows Image 
Acquisition (WIA).  A couple links:

http://www.codeproject.com/KB/cs/WebCamService.aspx

You'll have to rip out the relevant code.


http://www.experts-exchange.com/Programming/Languages/CPP/Q_22118650.html

I hate the Experts Exchange website, but at the very bottom of the 
article looks like some promising code:

---
You can use Sample Grabber filter to acomplish this.

Using the Sample Grabber
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directshow/htm/usingthesamplegrabber.asp

This sample shows how to add Sample Grabber filter:

//============
// Create the Sample Grabber.
IBaseFilter *pGrabberF = NULL;
hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
     IID_IBaseFilter, (void**)&pGrabberF);
if (FAILED(hr))
{
     // Return an error.
}
hr = pGraph->AddFilter(pGrabberF, L"Sample Grabber");
if (FAILED(hr)
{
     // Return an error.
}
//============

To add source filter representing you web camera you will need some 
replacement code that enumerates capture devices in system and uses 
monikers:
http://msdn2.microsoft.com/en-us/library/ms787871.aspx

//============
// Create the System Device Enumerator.
HRESULT hr;
ICreateDevEnum *pSysDevEnum = NULL;
hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
     IID_ICreateDevEnum, (void **)&pSysDevEnum);
if (FAILED(hr))
{
     return hr;
}

// Obtain a class enumerator for the video compressor category.
IEnumMoniker *pEnumCat = NULL;
hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoCompressorCategory, 
&pEnumCat, 0);

if (hr == S_OK)
{
     // Enumerate the monikers.
     IMoniker *pMoniker = NULL;
     ULONG cFetched;
     while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
     {
         IPropertyBag *pPropBag;
         hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
             (void **)&pPropBag);
         if (SUCCEEDED(hr))
         {
             // To retrieve the filter's friendly name, do the following:
             VARIANT varName;
             VariantInit(&varName);
             hr = pPropBag->Read(L"FriendlyName", &varName, 0);
             if (SUCCEEDED(hr))
             {
                 // Display the name in your UI somehow.            // 
<========= varName will contain you web camera name as seen in GraphEdit

             }
             VariantClear(&varName);

             // To create an instance of the filter, do the following:
             IBaseFilter *pFilter;
             hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, 
        //<====== when you have correct moniker create source filter object
                 (void**)&pFilter);
             // Now add the filter to the graph.
             //Remember to release pFilter later.
             pPropBag->Release();
         }
         pMoniker->Release();
     }
     pEnumCat->Release();
}

pSysDevEnum->Release();
//============
---


-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to