[Windows Mobile] Capturing Raw Frames or SampleGrabber and DirectShow.NETCF
What is SampleGrabber? this is filter (as a rule Transform or TransInPlace) that goes after filter which samples we are going to grab.
Why do we need SampleGrabber?
1. In windows mobile this is the fastest way to still images, more than that we still uncompressed images (so we dont loose time for encoding/decoding)
2. We can use SampleGrabber to draw text or images on received stream
3. We grab images to memory.
I Think this is enough to say that sample grabber is useful.
The problem is that windows already have sample grabber and we dont need to make any extra moves to use it, but Windows Mobile knows nothing about sample grabber
On www.codeproject.com you can find some articles that explain how to implement SampleGrabber. But there tons limits and problems in every case, so i decided to implement my own.
The main question was “Is it possible to implement SampleGrabber that not need to registered?”. I meant that if i programming on C++ i can use unit (class) that contain samplegrabber code, i if i programming on any other language i can use this unit compiled to dll. Yes its possible (!!!!) we dont need resvrCE and anything else, just unit or dll
I was going to use developed SampleGrabber for barcode reader, but samples that i receive were too blurred to be recognized even by human (may be this is my cam dieing? O,o). anyway that was reason i decided to stop work on it, so here is what i got for this time:
DirectShowNETCF.Native.dll that contain SampleGrabber. How to use it?
[DllImport("DirectShowNETCF.Native.dll")]
private static extern IntPtr GetBaseFilter();
this is method returns IntPtr that equal to IBaseFilter*
how to get IBaseFilter?
IntPtr grabber_ = GetBaseFilter(); IBaseFilter grabber = (IBaseFilter)Marshal.GetTypedObjectForIUnknown(grabber_, typeof(IBaseFilter));
To grab raw frame you have to call
1. getSize(out long size)
2. alloc memory (use DirectShowNETCF.PInvoke.LocalAlloc(0×40, size))
3. call getFrame(IntPtr pBuff)
[ComVisible(true), ComImport,
Guid("2B21644A-D405-4E27-A51C-A4812bE0CE4C"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IGetFrame
{
[PreserveSig]
int getFrame(IntPtr pBuff);
[PreserveSig]
int getSize([Out] out long size);
}
//example of grabbing frame
public IntPtr grabFrame(ref long bufSize)
{
IntPtr res_ = IntPtr.Zero;
long size = 0;
frmGrabber.getSize(out size);
bufSize = size;
res_ = PInvoke.LocalAlloc(0x40, (int)size);
frmGrabber.getFrame(res_);
return res_;
}
last version of DirectShowNETCF you can download here
Filed under: Programming
June 19th, 2009 at 1:13 pm
The method init return false
June 19th, 2009 at 12:31 pm
Color of panel says nothing. methods init and start returns boolean if it false it means that its impossible for some reasons init or start graph
June 19th, 2009 at 11:55 am
The panel is in black, do not worry it will resolve
When made the video capture?
Thanks for reply
Greetings
June 19th, 2009 at 11:49 am
does init and start return true?
June 19th, 2009 at 11:41 am
The camera does not display when I press button Start
Nice work
June 19th, 2009 at 11:19 am
What do you mean by “does not work”? did you put DirectShowNETCF.Native.dll to the folder where executable?
June 19th, 2009 at 10:10 am
AMCamera dont work
¿why?
June 19th, 2009 at 12:15 am
Updated
June 18th, 2009 at 11:37 pm
Oops
Sorry that was debug version
will update soon
June 18th, 2009 at 8:30 pm
Tested DirectShowNETCF.dll enumerating and setting resolution feature - works great. Started to test the sample grabber (AMCamera) by first using your C# example…however your example does not appear to work with the current version of the DLL…am I missing something?