Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Kinect with Emgu CV

Tags:

c#

kinect

emgucv

With EmguCV, to capture an image from a web-cam we use :

Capture cap = new Capture(0);

Image < Bgr, byte > nextFrame = cap.QueryFrame();

...

...

But I don't know how to capture images from my Kinect, I have tried kinectCapture class but it didn't work with me. Thanks

like image 691
Rafik Haceb Avatar asked Dec 11 '22 23:12

Rafik Haceb


2 Answers

Basically , you need to capture and Image from the ColorStream and convert to a EmguCV Image class :

Conversion to EmguCV Image from Windows BitMap (Kinect ColorStream):

You have a Windows Bitmap variable, where holds Kinect Frame.

Bitmap bmap = new Bitmap(weightFrame,HeightFrame,System.Drawing.Imaging.PixelFormat.Format32bppRgb);

...

//Here is the code where you capture the image in the ColorFrameReady....

...

Image<Bgr,Byte> frameActualKinect = bmap.ToOpenCVImage<Bgr, Byte>();

Make the detection:

Resize

currentFrame = frameActualKinect.Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);

//Convert it to Grayscale

gray = currentFrame.Convert<Gray, Byte>();

//Face Detector

MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(face, 1.2, 10, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,new System.Drawing.Size(20, 20));

P.D (The helper method) :

public static Image<TColor, TDepth> ToOpenCVImage<TColor, TDepth>(this Bitmap bitmap)
        where TColor : struct, IColor
        where TDepth : new()
    {
        return new Image<TColor, TDepth>(bitmap);
    }
like image 113
acandaldev Avatar answered Dec 28 '22 02:12

acandaldev


When using EmguCV, you usually use another library to access the Kinect. For example, The Kinect For Windows SDK, or OpenNI. Then after accessing the camera using OpenNI or the SDK, you can edit the image that you project on the screen using EmguCV's tools. Here's some links of how to use EmguCV with OpenNI and the SDK

  • https://groups.google.com/forum/#!topic/openni-dev/I0InsNgIIz4
  • http://www.geek-press.com/?p=23 (beta 2 of SDK)
  • Emgu CV and the official Microsoft Kinect SDK?

Hope this helps!

like image 34
Liam McInroy Avatar answered Dec 28 '22 02:12

Liam McInroy