Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Overlay bitmap on live video options

405 views
Skip to first unread message

xray

unread,
Apr 19, 2005, 12:30:33 PM4/19/05
to
Hi,

I'm new to using DirectX for displaying live video.
I'm trying to create a video app that not only displays live video but
also allows me to draw a couple of lines onto the video as a refernce
point. These lines will be used to properly install the video camera.

I have read thru many postings and have gone thru many DXSDK samples
but I'm not sure of the best approach. I've tried to combine the live
capture sample app (amcap) with the apps that use
CLSID_VideoMixingRenderer to mix bitmaps but am having problems when
calling SetAlphaBitmap (0x80004005). I've also read that I can use a
filter based on PushSource, EZRGB24 etc. to accomplish this. I think I
can even use an OverlayMixer too but am not clear. Is there a right
way to do this?

Can someone please point me in the right direction?

Thanks!

The March Hare [MVP]

unread,
Apr 19, 2005, 12:40:02 PM4/19/05
to

The easiest way is with SetAlphaBitmap.

The best way to see how to implement it is to examine how the samples use
it. For example, see the Watermark, Ticker and Text samples.

--
Please read this before replying:
1. Dshow & posting help: http://tmhare.mvps.org/help.htm
2. Trim & respond inline (please don't top post or snip everything)
3. Benefit others: follow up if you are helped or you found a solution

xray

unread,
Apr 19, 2005, 2:19:47 PM4/19/05
to
Thanks for the quick response.

Well it sounds like I'm on the right path as I have been using the
examples (Ticker, Watermark) you've mentioned.

I've been trying to integrate these samples with a capture sample that
works well, however I am having some problems when calling
SetAlphaBitmap. I'm not sure the order of the filters. Do I add the
video capture source filter and then the rendering filter or
vice-versa? Can you point me to a good reference for this?

Thanks again.

The March Hare [MVP]

unread,
Apr 19, 2005, 3:13:58 PM4/19/05
to
On 19 Apr 2005 11:19:47 -0700, xray wrote:

> I've been trying to integrate these samples with a capture sample that
> works well, however I am having some problems when calling
> SetAlphaBitmap. I'm not sure the order of the filters. Do I add the
> video capture source filter and then the rendering filter or
> vice-versa? Can you point me to a good reference for this?

You add the capture filter to the filter graph, create a VMR filter and
render the capture filter using ICaptureGraphBuilder2::RenderStream with
the renderer as the last parameter. The mixer must be loaded before
setting the bitmap. As noted in the docs:

"Internally, the VMR uses its mixer component to perform the blending
operation. Therefore the VMR must be configured correctly prior to
commencing video playback. Even if only a single video stream is present,
applications should call IVMRFilterConfig::SetNumberOfStreams with a value
of "1" to cause the VMR to load the mixer and compositor. The image can
contain embedded per pixel alpha information; this allows the image to
contain regions that are transparent. Transparent areas can also be
identified by a color key value. Changes in the image are only shown on the
screen while the filter graph is running."

xray

unread,
Apr 27, 2005, 8:02:29 AM4/27/05
to
Thanks for your help, this worked.

Here is what i did for anyone who needs to do something similar.

I started with the
Extras\DirectShow\Samples\C++\DirectShow\Capture\PlayCapMoniker sample
and added this block of code to the AddCaptureMonikerToGraph method.

// Create the VMR filter, add it and use it to render the stream.
// This allows us to mix with bitmap data
CComPtr <IBaseFilter> pVmr = NULL;
hr = CoCreateInstance(CLSID_VideoMixingRenderer, NULL,
CLSCTX_INPROC, IID_IBaseFilter, (void**)&pVmr);
if (SUCCEEDED(hr))
{
hr = g_pGraph->AddFilter(pVmr, L"Video Mixing Renderer");
if (FAILED(hr))
{
Msg(TEXT("Couldn't add Video Mixing Renderer! AddFileter
failed hr=0x%x"), hr);
}

// Set the rendering mode and number of streams.
CComPtr <IVMRFilterConfig> pConfig;
hr = pVmr->QueryInterface(IID_IVMRFilterConfig,
(void**)&pConfig);
if( SUCCEEDED(hr))
{
// Set one stream - video and alpha-blended bitmap
hr = pConfig->SetNumberOfStreams(1);
}

hr =
pVmr->QueryInterface(IID_IVMRMixerBitmap,(void**)(&g_pMixerBitmap));
if (FAILED(hr))
{
Msg(TEXT("Couldn't get VMRMixerBitmap interface! hr=0x%x"),
hr);
}
}

// Render the preview pin on the video capture filter
// Use this instead of g_pGraph->RenderFile
hr = g_pCapture->RenderStream (&PIN_CATEGORY_PREVIEW,
&MEDIATYPE_Video,
pBaseFilter, NULL, pVmr);


I then added this function and called it just before the
SetupVideoWindow() and Run() calls. Note the g_hbm bitmap was loaded
on startup.


HRESULT Blend()
{
HRESULT hr = S_OK;
// Get the window client area rectangle
RECT rcClient;
GetClientRect(ghApp, &rcClient);

BITMAP bm;
HBITMAP hbmOld;
HDC hdc = GetDC(ghApp);
HDC hdcBmp = CreateCompatibleDC(hdc);
ReleaseDC(ghApp, hdc);

GetObject(g_hbm, sizeof(bm), &bm);
hbmOld = (HBITMAP)SelectObject(hdcBmp, g_hbm);

VMR9AlphaBitmap alphaBitmap;
if( g_pMixerBitmap == NULL )
{
return E_FAIL;
}

ZeroMemory( &alphaBitmap, sizeof VMR9AlphaBitmap);

// Initialize VMR9AlphaBitmap structure
alphaBitmap.dwFlags = VMR9AlphaBitmap_hDC |
VMR9AlphaBitmap_SrcColorKey;
alphaBitmap.hdc = hdcBmp;
alphaBitmap.pDDS = NULL;
alphaBitmap.clrSrcKey = RGB(255,255,255);

RECT rc;
SetRect(&rc, 0, 0, bm.bmWidth, bm.bmHeight);
alphaBitmap.rSrc = rc;

// Position the bitmap within the VMR's composition space (0.0 -
1.0).
// Use the whole space [0,0,1,1]
alphaBitmap.rDest.top = 0.0;
alphaBitmap.rDest.left = 0.0;
alphaBitmap.rDest.bottom = 1.0;
alphaBitmap.rDest.right = 1.0;
alphaBitmap.fAlpha = config.m_alpha;
hr = g_pMixerBitmap->SetAlphaBitmap( &alphaBitmap );
if (FAILED(hr))
{
Msg(TEXT("Failed to set bitmap! SetAlphaBitmap hr=0x%x"), hr);
}

return hr;
}

The March Hare [MVP]

unread,
Apr 27, 2005, 10:22:04 AM4/27/05
to
On 27 Apr 2005 05:02:29 -0700, xray wrote:

> Thanks for your help, this worked.

You're welcome.



> Here is what i did for anyone who needs to do something similar.

<snip>

Thanks for sharing your solution. It will probably help someone else :)

Sijith

unread,
Apr 6, 2010, 3:17:20 AM4/6/10
to
I did the same but getting some errors

Error List

Error 2 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int
Error 6 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int
Error 8 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int
Error 9 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int
Error 21 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int
Error 22 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int
Error 26 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int
Error 27 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int Error 36 error C2228: left of '.m_alpha' must have
class/struct/union
Error 38 error C2227: left of '->SetAlphaBitmap' must point to
class/struct/union/generic type
Error 7 error C2146: syntax error : missing ';' before identifier 'Pool'
Error 4 error C2146: syntax error : missing ';' before identifier 'Format'
c:\Program Files\Microsoft Platform SDK\include\Vmr9.h 368 PlayCapMoniker
Error 1 error C2143: syntax error : missing ';' before ''
Error 20 error C2143: syntax error : missing ';' before ''
Error 25 error C2143: syntax error : missing ';' before '*'
Error 30 error C2065: 'g_pMixerBitmap' : undeclared identifier
Error 33 error C2065: 'g_pMixerBitmap' : undeclared identifier
Error 37 error C2065: 'g_pMixerBitmap' : undeclared identifier
Error 31 error C2065: 'g_hbm' : undeclared identifier
Error 32 error C2065: 'g_hbm' : undeclared identifier
Error 35 error C2065: 'config' : undeclared identifier
Error 10 error C2061: syntax error : identifier 'IDirect3DSurface9'
Error 11 error C2061: syntax error : identifier 'IDirect3DSurface9'
Error 12 error C2061: syntax error : identifier 'IDirect3DSurface9'
Error 13 error C2061: syntax error : identifier 'IDirect3DSurface9'
Error 16 error C2061: syntax error : identifier 'IDirect3DSurface9'
Error 19 error C2061: syntax error : identifier 'IDirect3DSurface9'
Error 23 error C2061: syntax error : identifier 'IDirect3DSurface9'
Error 24 error C2061: syntax error : identifier 'IDirect3DSurface9'
Error 28 error C2061: syntax error : identifier 'IDirect3DSurface9'
Error 29 error C2061: syntax error : identifier 'IDirect3DSurface9'
Error 14 error C2061: syntax error : identifier 'IDirect3DDevice9'
Error 15 error C2061: syntax error : identifier 'IDirect3DDevice9' Error 17
error C2061: syntax error : identifier 'IDirect3DDevice9'
Error 18 error C2061: syntax error : identifier 'IDirect3DDevice9'
Error 34 error C2039: 'pDDS' : is not a member of '_VMR9AlphaBitmap'
SDK\Samples\Multimedia\DirectShow\Capture\PlayCapMoniker\PlayCapMoniker.cpp
263 PlayCapMoniker

url:http://www.ureader.com/msg/1471251.aspx

sandy1985

unread,
Mar 27, 2012, 1:34:55 PM3/27/12
to
xray wrote on 04/27/2005 08:02 ET :
> Thanks for your help, this worked.
>
> Here is what i did for anyone who needs to do something similar.
>
> I started with the
> ExtrasDirectShowSamplesC++DirectShowCapturePlayCapMoniker sample
> and added this block of code to the AddCaptureMonikerToGraph method.
>
> // Create the VMR filter, add it and use it to render the stream.
> // This allows us to mix with bitmap data
> CComPtr <IBaseFilter> pVmr = NULL;
> hr = CoCreateInstance(CLSID_VideoMixingRenderer, NULL,
> CLSCTX_INPROC, IID_IBaseFilter, (void**)&pVmr);
> if (SUCCEEDED(hr))
> {
> hr = g_pGraph->AddFilter(pVmr, L"Video Mixing Renderer");
> if (FAILED(hr))
> {
> Msg(TEXT("Couldn't add Video Mixing Renderer! AddFileter
> failed hr=0x%x"), hr);
> }
>
> // Set the rendering mode and number of streams.
> CComPtr <IVMRFilterConfig> pConfig;
> hr = pVmr->QueryInterface(IID_IVMRFilterConfig,
> (void**)&pConfig);
> if( SUCCEEDED(hr))
> {
> // Set one stream - video and alpha-blended bitmap
> hr = pConfig->SetNumberOfStreams(1);
> }
>
> hr pVmr->QueryInterface(IID_IVMRMixerBitmap,(void**)(&g_pMixerBitmap));
Hi,
I need same thing what you did. Can you able to share source code with me?
My email is id : sand...@gmail.com.
Waiting for your positive reply.
Regards,
Sandip
0 new messages