gpt4 book ai didi

c# - 将 Kinect ColorImageFrame 转换为位图

转载 作者:太空狗 更新时间:2023-10-29 17:46:53 24 4
gpt4 key购买 nike

我在 XNA 中使用 Kinect (Microsoft SDK)。我想使用 GRATF 进行标记识别

如何将 Kinect ColorImageFrame 的数据转换为我可以处理的 System.Drawing.BitmapAForge.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);

...
}

最佳答案

你可以找到答案in this article .
总而言之,这种方法应该可以解决问题:

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

关于c# - 将 Kinect ColorImageFrame 转换为位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10848190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com