2012-06-01 11 views
9

私はKinect(Microsoft SDK)をXNAで使用しています。 GRATFをマーカー認識に使用したいKinect ColorImageFrameをビットマップに変換する

Kinect ColorImageFrameのデータをSystem.Drawing.BitmapまたはAForge.Imaging.UnmanagedImageに変換するにはどうすれば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); 

    ... 
} 
+0

外観:http://www.codeproject.com/Articles/730842/Kinect-for-Windows-version-Color-depth-それを要約する
は、この方法は、トリックを行う必要がありますand-infra (私はこれが古いと知っていますが、今見ている人は誰でも) – ThunderWiring

答えて

11

回答はin this articleです。

この記事で
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; 
} 
+0

ありがとうございました!すごい仕事! –

+0

これはいつもA = 255に与えるのですか? –

関連する問題