[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

50 Responses to “[Windows Mobile] Capturing Raw Frames or SampleGrabber and DirectShow.NETCF”

Pages: [5] 4 3 2 1 » Show All

  1. 50
    fakepoo Says:

    Alex - Thank you for your examples. It appears that I need the DirectShowNETCF.Native.dll in order to PInvoke the GetBaseFilter() function but it is not provided in the download. Is there a separate location where I could download this?

  2. 49
    mbeg Says:

    Hey alex..thanks for the post..i have ru into a problem though..the camera never captures any frames…says “cannot init camera” when i press start..whats going wrong?please help!
    thanks!

  3. 48
    vito Says:

    Hi Alex, sorry for all my questions. your blog helps me a lot. I can’t understand how to use the next code you developed.

    //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(0×40, (int)size);
    frmGrabber.getFrame(res_);
    return res_;
    }

    can you show me a mothod calling it?
    thanks!

  4. 47
    vito Says:

    hi!, where is DirectShowNETCF.Native.dll located? I downloaded the DirectShowNetCF libraries, but I have:

    -DirectShowNETCF.dll
    -AMCameraEx.Native.dll
    -AMCamera.Native.dll
    -NullRenderer.dll

    I don’t have DirectShowNETCF.Native.dll. thanks

  5. 46
    Rui Says:

    Hey thanks, that worked on the device. It doesn’t work on the simulator however, but solved my problem :)

  6. 45
    admin Says:

    you should put DirectShowNETCF.dll on device where executable deployed

  7. 44
    Rui Says:

    Sorry to bother you again with this issue… I copied both DirectShowNETCF.dll and DirectShowNETCF.Native.dll to \AMCamera\bin\Debug, the folder where the executable is placed and I still receive MissingMethodException was unhandled: Can’t find PInvoke DLL ‘DirectShowNETCF.Native.dll’ in the Init method.
    Am I missing something?
    In the Output window in VS 2008 all references are loaded except for this one.
    Sorry and thanks for your help.

  8. 43
    admin Says:

    seems like HTC cant render rgb24, i`m working on custom renderer now

  9. 42
    Andre Says:

    Same here: “Cannot init camera! Result: ConnectGrabberError_2 ”

    Also DirectShowNETCF.Camera.Camera works fine, but not the others.

    It’s a HTC-8900 - Win 6.0

    Any ideas?

  10. 41
    admin Says:

    2vinay: its not implemented yet, but if you want you can buy samplegrabber sources and draw image you need on raw frame

Pages: [5] 4 3 2 1 » Show All

Leave a Reply