Hi guys I found the problem and solve it. First I forgot to copy the x86 and x64 folders from Emgu\bin to Debug folder of the Visual Studio directory. Moreover, converting
Media.BitmapSource
to
Emgu.CV.Image
isn't the best idea so after reading a book (James Ashley - Beginning Kinect Programming with Microsoft SDK) I could convert
Drawing.Bitmap
to
Emgu.CV.Image
.
private void InitializeKinect()
{
KinectSensor Sensor = KinectSensor.GetDefault();
FrameDescription frameDescription = Sensor.ColorFrameSource.FrameDescription;
ColorFrameReader FrameReader = Sensor.ColorFrameSource.OpenReader();
FrameReader.FrameArrived += FrameReader_FrameArrived;
}
void FrameReader_FrameArrived(object sender, ColorFrameArrivedEventArgs e)
{
using (ColorFrame frame = e.FrameReference.AcquireFrame())
{
if (frame == null)
return;
var width = frame.FrameDescription.Width;
var heigth = frame.FrameDescription.Height;
var data = new byte[width * heigth * System.Windows.Media.PixelFormats.Bgra32.BitsPerPixel / 8];
frame.CopyConvertedFrameDataToArray(data, ColorImageFormat.Bgra);
var bitmap = new System.Drawing.Bitmap(width, height, PixelFormat.Format32bppRgb);
var bitmapData = bitmap.LockBits(
new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.WriteOnly,
bitmap.PixelFormat);
Marshal.Copy(data, 0, bitmapData.Scan0, data.Length);
bitmap.UnlockBits(bitmapData);
Emgu.CV.Image<bgr,> imageFrame = new Image<bgr,>(bitmap);
}
}