Image processing(Convolution Filter)
Image processing(Convolution Filter)
Image processing(Convolution Filter)
Image processing(Convolution Filter)
Image processing(Convolution Filter)
Image processing(Convolution Filter) Image processing(Convolution Filter) Image processing(Convolution Filter) Image processing(Convolution Filter) Image processing(Convolution Filter) Image processing(Convolution Filter) Image processing(Convolution Filter) Image processing(Convolution Filter)
Image processing(Convolution Filter) Image processing(Convolution Filter)
Image processing(Convolution Filter)
Go Back  Xtreme Visual Basic Talk > > > > Image processing(Convolution Filter)


Reply
 
Thread Tools Display Modes
  #1  
Old 09-08-2008, 02:18 PM
Richard87 Richard87 is offline
Junior Contributor
 
Join Date: Sep 2004
Posts: 235
Default Image processing(Convolution Filter)


Hello, I have a directshow graf that is returning a image into a callback funtion wich in turn gives me a Bitmap, wich I then run a series og calculations on, but it is terrible slow, and I would like to speed things up..

Right now I am running a convolution filter on the image stram, but each run takes about 1300ms, and that is way to slow, I belive it is possible to run convolution filters with DirectDraw/3d.

1. My first question is how can I create a 'background' DirectX device that does not controll any of my screen

then I would copy my image to a new surface

2. The second, what/how is the fastest way to run a convolution filter on a surface in DirectX


I read somewhere that DirectDraw was on its way out, and all functions in DD in VB2008 is considered 'depreciated':S

Btw, I am using VS 2008 with .Net framework 3.5, writing in VB and using DX 9...

Some background:
The DirectShow is returning a live feed from my webcam, wich I would like to run som motion detection on(hopefully multiple objects)



Any Advice or pointers to where I can learn more about this is wery apreciated
Reply With Quote
  #2  
Old 09-11-2008, 02:40 PM
Richard87 Richard87 is offline
Junior Contributor
 
Join Date: Sep 2004
Posts: 235
Default

Ok, so I went with Dirext3D and just used a picture box, I have gotten the image from the webcam and into a texture (via a bitmap), but it is _extremly_ slow, like a delay at 4-5 sec:S

Any idea how I can make this code faster(f.eks how can I use IO.Stream???)

here is the code:
Code:
Public Function BufferCB(ByVal SampleTime As Double, ByVal pBuffer As System.IntPtr, ByVal BufferLen As Integer) As Integer Implements DirectShowLib.ISampleGrabberCB.BufferCB SyncLock Me b = New Bitmap(m_videoWidth, m_videoHeight) Dim bm As BitmapData = b.LockBits(New Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb) CopyMemory(bm.Scan0, pBuffer, BufferLen - 1) b.UnlockBits(bm) 'DirectX Stuff Try 'pPanel = Direct3D.Texture.FromBitmap(Display, b, Usage.Dynamic, Pool.Default) Dim dm As IO.Stream pPanel = New Texture(Display, dm, Usage.Dynamic, Pool.Default) Display.Clear(ClearFlags.Target, Color.Black, 1, 0) Display.BeginScene() 'Sett opp 'viewport' SetupMatrices() Display.SetTexture(0, pPanel) 'Tegn Display.Material = mat Display.VertexFormat = CustomVertex.PositionTextured.Format 'Display.VertexFormat = CustomVertex.PositionColored.Format Display.SetTexture(0, pPanel) Display.SetStreamSource(0, m_VertexBuffer, 0) Display.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2) Display.EndScene() Display.Present() Catch ex As Exception MsgBox(ex.Message) Application.Exit() End Try End SyncLock End Function

All help would be apreciated
Reply With Quote
  #3  
Old 09-12-2008, 09:42 AM
jo0lsImage processing(Convolution Filter) jo0ls is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Feb 2005
Location: London
Posts: 1,050
Default

I was interested in doing the same thing myself, after figuring out how convolution filters work. To get any sort of speed you have to offload the CPU, which means the graphics card will do the convolution filter. And I couldn't figure out how to do that. Copying the pixels out of a bitmap into main memory means that you are going to be using the CPU, and it will be slow.

The other day I was reading about the new HLSL stuff that is available (requires .Net 3.5 SP1). Here you can use the WPF to do per-pixel filters, but the beauty of it is that it uses the pixel shaders on the graphics card, and so it should be much faster.

http://blogs.microsoft.co.il/blogs/t...-tutorial.aspx

I'm not sure then how you bring it all together. The problem with webcams is that they rely on old code - DirectShow isn't updated with DirectX anymore - it gets dumped in with the platform SDK. WPF doesn't have a way to capture from webcams either. I believe then that you have to use DirectShow, or windows media encoder to get the data from the camera. Then you would need to either code DirectX HLSL to do the pixel filter (is this possible - or is the filter too complex for an HLSL filter?) or use WPF. And how do you get the webcam stream into WPF in a format that can be used anyway?

I would probably first try to do a convolution filter with WPF/HLSL and then work out how to get the webcam stream available in a suitable format, if it is possible.
Reply With Quote
  #4  
Old 09-12-2008, 02:18 PM
Rockoon's Avatar
Rockoon Rockoon is offline
Joseph Koss

* Guru *
 
Join Date: Aug 2003
Location: Unfashionable End
Posts: 3,615
Default

A simple pixel shader something on the order of:

output = output + input * k

not sure how that will look in actual shader code (never used shaders), the idea here is that input and output are the source and distination surfaces, and k is a tunable constant

With such a pixel shader, a 3x3 convolution filter can be performed with 9 draw calls which leverage it

lets take a simple BOX filter:

0.111, 0.111, 0.111
0.111, 0.111, 0.111
0.111, 0.111, 0.111

here, the constant will be 0.111 for each of the draw calls

the source rectangle is the same for all draw calls, but the destination rectangle shifts around.. X-1, Y-1 for the top left corner, X, Y-1 for the northern constant, X+1, Y-1 for the top right corner, and so forth
Reply With Quote
  #5  
Old 09-12-2008, 02:46 PM
Richard87 Richard87 is offline
Junior Contributor
 
Join Date: Sep 2004
Posts: 235
Default

Thanks for all the replys, I will look into that soon. Right know I want to get the Webcam texture painted correctly(I want to accomplish what I started, this is just as much a learning project than anything else).

I got it to render more quickly by using LockRect like this:
Code:
'Init m_text = New Texture(Display, rect.Width, rect.Height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed) 'Renderer Dim bm2() As Byte bm2 = m_text.LockRectangle(GetType(Byte), 0, rect, Microsoft.DirectX.Direct3D.LockFlags.None, IPA) Marshal.Copy(pBuffer, bm2, 0, bm2.Length) m_text.UnlockRectangle(0)

Now the code is fast enough, but the image is distorted:S the image from the webcam is 640x480p, 32BppARGB. But I cant seem to find the correct PixelFormat for this image, does anyone have any idea? I tried using the old bitmap(b) like b.PixelFormat, but that didnt work:S...

[EDIT]
A Prn Scr is attached, the yellow area is the D3D World, and the black/image is the surface(2 triangles), the image is only printed on the lower half...
Attached Images
File Type: jpg test.jpg (39.2 KB, 8 views)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Image processing(Convolution Filter)
Image processing(Convolution Filter)
Image processing(Convolution Filter) Image processing(Convolution Filter)
Image processing(Convolution Filter)
Image processing(Convolution Filter)
Image processing(Convolution Filter) Image processing(Convolution Filter) Image processing(Convolution Filter) Image processing(Convolution Filter) Image processing(Convolution Filter) Image processing(Convolution Filter) Image processing(Convolution Filter)
Image processing(Convolution Filter)
Image processing(Convolution Filter)
 
Image processing(Convolution Filter)
Image processing(Convolution Filter)
 
-->