2

Alright, so basically I am trying to use openCV with the Kinect (Microsoft's new Kinect 1.0 SDK). I am very new to both C# and Kinect. But what I want to do is use the kinect for facial recognition using EMGU (openCV wrapper for C#). So far I have successfully captured the video stream from the kinect, converted it into an EMGU Image<>, then converted it a Byte[] array so that I can use the BitmapSource to display my image on the screen.

While that works fine, problems seem to arise when I try to actually do some image processing with the Image<> class. It actually seems to be processing fine, but it is not very fast. This wouldn't necessarily be a problem for me, but now the BitmapSource isn't being displayed at all.

Here is an example of my code to detect faces:

img = new Image<Bgr, byte>(clone);
haar = new HaarCascade("directory");

Image<Gray, Byte> gray;
using (HaarCascade face = new HaarCascade("blablabla.xml"))
using (HaarCascade eye = new HaarCascade("blarg.xml"))
{

using ( gray = img.Convert<Gray, Byte>()) //Convert it to Grayscale
{
  MCvAvgComp[] facesDetected = face.Detect(gray, 1.1, 1,  mgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new System.Drawing.Size(img.Width / 8, img.Height / 8));
  foreach (MCvAvgComp f in facesDetected)
  {
    img.Draw(f.rect, new Bgr(System.Drawing.Color.Blue), 2);
    imgDoneProc = img.ToBitmap();
  }
 }
}

Then I use the BitmapSource.Create() :

BitmapSource bmapa = BitmapSource.Create(PImage.Width, PImage.Height, 96, 96, PixelFormats.Bgr32, null, bmpBytes, PImage.Width * PImage.BytesPerPixel);

image1.Source = bmapa;

(PImage is the stream from the Kinect; bmpBytes is a Byte[] converted from the Image<>)

So, if I comment out the code that does the image processing, all of the converting back and forth works fine. When I add the image proc code, I can write to the console some useful data, but the image is not displayed. I have also noticed that the 'bmapa' is not updated quickly. That is the only noticeable difference other than nothing being displayed in image1.

So, am I using BitmapSource incorrectly, or is there are way speed up my code or perhaps slow BitmapSource's "refresh rate"? Because when I am just converting between data structures, I get a steady stream from the kinect and all works fine.

Thanks, Brent

0 Answers0