2

I have a hi-resolution camera connected via firewire. An SDK lets me grab frames into a byte buffer. E.g.:

unsigned char *buffer = new unsigned char[size];
GetFrameBuffer(cameraHandle, buffer);

Due to the nature of the API, frames need to be grabbed continuously (20+ fps) to show a live view. Now, I want to display this in my WPF UI. I can think of several approaches, but I need help determine which method to choose!

Ideas

  1. Continuously update the Source of the Image element through a property updated via interop.
  2. Host a custom HWND based control in a HwndHost. The image will be updated when the message pump is idle.
  3. Write a source filter in DirectShow that, using some kind of timing logic, reads the buffer continuously - making it possible to show the live view using MediaElement.

Obviously, I want to minimize the CPU load.

The question boils down to this:

In WPF, how do I show a live stream from a firewire connection with primitive APIs like GetFrameBuffer?

l33t
  • 18,692
  • 16
  • 103
  • 180
  • Which solution have you used? Have you tried more then one? The image pixel data is written in a byte array? I'm tring to do the same thing, take a look at: http://stackoverflow.com/questions/16220472/how-to-create-a-bitmapimage-from-a-pixel-byte-array/16220704?noredirect=1#comment23200282_16220704 – Pedro77 Apr 26 '13 at 12:16
  • I got the frame as a byte array and then created a `BitmapImage` from it. – l33t Apr 26 '13 at 22:51
  • It seems like you get a bmp or jpeg file byte array, not a raw pixel byte array right? :) – Pedro77 Apr 27 '13 at 19:52
  • The width and height are known and the buffer contains whatever format you tell the camera to produce. So the byte array does indeed contain pixel bytes, but together with it comes the necessary information to build the bitmap. – l33t Apr 29 '13 at 07:18
  • Can you add the image creation code to your question fallowup? What is the camera API? Do you create a new Bitmap or you just update the pixel data of the same object? – Pedro77 Apr 29 '13 at 13:45
  • 1
    Obviously, your buffer must come together with necessary data. `var bitmap = BitmapSource.Create(width, height, 96.0, 96.0, pixelFormat, null, myFrame.pBuffer, (int)myFrame.bufferSize, stride); bitmap.Freeze();` – l33t Apr 29 '13 at 15:42

1 Answers1

0

I think the easiest way is the first one. Just update the image source. If you just want to display it, you don't need a directshow filter for this. But if you also want to capture it, the DirectShow filter is the best way!

Updating the image-source is an easy task. A good example for this is the Mjpeg decoder for .net. You just need to replace the Mjpeg reader/parser with your own grabber logic.

CPlusSharp
  • 881
  • 5
  • 15