转换Kinect的ColorImageFrame为位图 [英] Convert Kinect ColorImageFrame to Bitmap

查看:235
本文介绍了转换Kinect的ColorImageFrame为位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm使用的Kinect(微软SDK)用XNA。我想用GRATF的标记识别

如何将数据转换成一个Kinect的 Col​​orImageFrame 到一个 System.Drawing.Bitmap AForge.Imaging.UnmanagedImage ,我可以GRATF处理它们?

 无效kinectSensor_ColorFrameReady(对象发件人,ColorImageFrameReadyEventArgs E)
{
    点阵位图= NULL;
    ColorImageFrame帧= e.OpenColorImageFrame();
    byte []的缓冲区=新的字节[frame.PixelDataLength]
    frame.CopyPixelData(缓冲液);

    //如何把数据转换在缓冲器为位图?

    VAR字形= recognizer.FindGlyphs(位);

    ...
}
 

解决方案

您可以找到答案<一href="http://www.i-programmer.info/ebooks/practical-windows-kinect-in-c/3725-getting-started-with-windows-kinect-sdk-10.html?start=2">in这篇文章的。
要总结一下,这种方法应该做的伎俩:

 位图ImageToBitmap(ColorImageFrame图片)
{
     byte []的PixelData取出=新的字节[Image.PixelDataLength]
     Image.CopyPixelDataTo(PixelData取出);
     位图BMAP =新位图(Image.Width,Image.Height,PixelFormat.Format32bppRgb);
     的BitmapData bmapdata = bmap.LockBits(
         新的Rectangle(0,0,Image.Width,Image.Height)
         ImageLockMode.WriteOnly,
         bmap.PixelFormat);
     IntPtr的PTR = bmapdata.Scan0;
     Marshal.Copy(PixelData取出,0,PTR,Image.PixelDataLength);
     bmap.UnlockBits(bmapdata);
     返回BMAP;
 }
 

I´m using Kinect (Microsoft SDK) with XNA. I want to use GRATF for marker-recognition

How to convert the data of a Kinect ColorImageFrame to a System.Drawing.Bitmap or AForge.Imaging.UnmanagedImage that I can process them with GRATF?

void kinectSensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
{
    Bitmap bitmap = null;
    ColorImageFrame frame = e.OpenColorImageFrame();
    byte[] buffer = new byte[frame.PixelDataLength];
    frame.CopyPixelData(buffer);

    // how to convert the data in buffer to a bitmap?

    var glyphs = recognizer.FindGlyphs(bitmap);

    ...
}

解决方案

You can find the answer in this article.
To summarize it, this method should do the trick:

Bitmap ImageToBitmap(ColorImageFrame Image)
{
     byte[] pixeldata = new byte[Image.PixelDataLength];
     Image.CopyPixelDataTo(pixeldata);
     Bitmap bmap = new Bitmap(Image.Width, Image.Height, PixelFormat.Format32bppRgb);
     BitmapData bmapdata = bmap.LockBits(
         new Rectangle(0, 0, Image.Width, Image.Height),
         ImageLockMode.WriteOnly, 
         bmap.PixelFormat);
     IntPtr ptr = bmapdata.Scan0;
     Marshal.Copy(pixeldata, 0, ptr, Image.PixelDataLength);
     bmap.UnlockBits(bmapdata);
     return bmap;
 }

这篇关于转换Kinect的ColorImageFrame为位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆