Click here to Skip to main content
15,879,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to write a text or a label on Preview Window that is showing the webcam preview using directshow.
-> Text will be on window when there will be preview or frames on screen.
Is here anyone having idea about this, how to do it?

Thanks!
Posted
Comments
Sergey Alexandrovich Kryukov 12-Feb-13 11:25am    
Are you using GDI, GDI+? It's is not compatible with DirectShow. You would need to do it with DirectX, layout manager, etc. Not a very pleasant work.
—SA

What you normally do is overlay text on a video - you don't need to add a label.
There are some filters that would allow you to do this for e.g. Pure .NET DirectShow Filters in C#[^] describes a filter that adds text to a video.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Feb-13 12:47pm    
Of course, a 5. I explained my opinion in my comment under my answer.
—SA
Abhinav S 12-Feb-13 12:57pm    
Thanks for the 5.
Read your comment.
Espen Harlinn 12-Feb-13 14:48pm    
Very nice, Abhinav :-D
Abhinav S 12-Feb-13 22:02pm    
Thank you.
Sachin k Rajput 12-Feb-13 23:57pm    
Thanks Abhinav!
for your answer, I really appreciate it.
But the thing is I'm implementing my application in VC++.
Its a webcam preview over which I want a text.
Another option is to render bot the video and the text to a texture, and an example on how to render the video to a texture is included with the SDK:
Source: (SDK root)\Samples\C++\DirectShow\Players\Texture3D[^]

To render the text you do something like this:

Enable transparency:
device.RenderState.AlphaTestEnable = true;
device.RenderState.AlphaFunction = Compare.Greater;
device.RenderState.ReferenceAlpha = 0;

Create font and sprite:
D3DX10CreateFont(device, 16, 0, FW_BOLD, 0, FALSE, 
           DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, ANTIALIASED_QUALITY, 
           DEFAULT_PITCH | FF_DONTCARE, L"Verdana", &font);

D3DX10CreateSprite(device, 256, &sprite);

Render:
hr = sprite->Begin(0);
std::wstring left = L"Hurray, text on a sprite!";

RECT r;
r.top = 0;
r.bottom = window->height;
r.left = 0;
r.right = window->width;

hr = font->DrawTextW(sprite, left.c_str(), -1, &r, 
              DT_LEFT | DT_TOP, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f));
hr = sprite->End();


Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Feb-13 11:49am    
Sure, a 5.
But note that OP successfully implemented my idea based on my quite stupid answer :-)
Because I expected that it could be just enough, and everything else might be too difficult to OP...
—SA
Espen Harlinn 13-Feb-13 14:38pm    
Thanks, Sergey - I did notice both yours and Abhinavs replies yestrday, and thought this would be an interesting alternative :-D
Please see my comment to the question.

Could you simply place a label control over the video? Not fancy, but simple.

Otherwise, dig in DirectX; but it will need time and nerve…

—SA
 
Share this answer
 
Comments
Abhinav S 12-Feb-13 11:49am    
I would add an overlay filter instead of a label.
Sergey Alexandrovich Kryukov 12-Feb-13 12:47pm    
Of course you would do it; and it would make a neat powerful way of doing things. I just suggest a simplest alternative.
You see, it depends on requirements and what OP is doing. If OP is already into DirectShow, of course it can be done, but if OP is just using some ready to use DirectShow component, which is the most usual case, the label is simpler.
—SA
Sachin k Rajput 12-Feb-13 23:59pm    
Its an app that is being done in VC++ win32 environment.
So put_Caption is failed,
Textout is failed and childwindow is also failed.
That's why the thing is how to write a simple text over preview.
Sergey Alexandrovich Kryukov 13-Feb-13 0:32am    
This and that failed is... not informative...
—SA
Sachin k Rajput 13-Feb-13 1:03am    
in directshow its a IVIDEOWINDOW and after render we can put caption there as I have seen from few examples and something like this http://www.geekpage.jp/en/programming/directshow/ivideowindow-1.php, but its not working.
And Textout is to call some text on paint event of window but that's not working too.
Additionally, to all answers:

1. In my articles there is an example to drawing text over the video, yes it is in C# but in old DirectX SDK you can find similar examples in C++.

2. Another way you can capture frames with Sample Grabber and draw text this way.

3. Easy way is to use VMR and makes bitmap from text and draw it as overlay Ticker Sample[^].

4. You can use RenderToTexture example but easy is to make Custom Allocator presenter for VMR[^] and draw text in there. The example of that you can see on MSDN or in C# in my articles.

Regards,
Maxim.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900