Kinect深度与播放器索引+视频流
本文关键字:视频 索引 播放器 深度 Kinect | 更新日期: 2023-09-27 18:14:13
我正在尝试从kinect生成一个图像,其中所有不代表玩家的像素将被设置为黑色。
我的想法是使用深度流与播放器索引产生的数据以及视频流来完成这项任务。
我的希望是做这样的事情:
byte[] pixelData = video.imageFrame.Bits;
byte[] depthData = depth.imageFrame.Bits;
var depthIndex = 0;
for (var y = 0; y < height; y++)
{
var heightOffset = y * width;
for (var x = 0; x < width; x++)
{
var index = (x + heightOffset) * 4;
var distance = GetDistanceWithPlayerIndex(depthData[depthIndex], depthData[depthIndex + 1]);
if (GetPlayerIndex(depthData[depthIndex]) == 0)
{
pixelData[index + BlueIndex] = 0;
pixelData[index + GreenIndex] = 0;
pixelData[index + RedIndex] = 0;
}
}
}
我目前正在努力使视频流数据具有与deepwithplayerindex相同的分辨率的问题。
我试着从这里的其他帖子中拼凑一些东西,但我不能让它工作:
private byte[] ScaleVideoImage(ImageFrame imageFrame, int newWidth, int newHeight)
{
//convert imageFrame to byte array
Byte[] oPixelData = imageFrame.Image.Bits;
Image tempImage = BytesToImg(oPixelData);
//scale image
Bitmap bmp = new Bitmap(newWidth, newHeight);
using (Graphics graphics = Graphics.FromImage(bmp))
{
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.DrawImage(tempImage, 0, 0, bmp.Width, bmp.Height);
}
//Convert image to byte array
MemoryStream ms1 = new MemoryStream();
bmp.Save(ms1, ImageFormat.Jpeg);
byte[] result = ms1.GetBuffer();
bmp.Dispose();
ms1.Close();
return result;
}
任何想法?
看一下我之前在这里分享的代码:http://channel9.msdn.com/coding4fun/kinect/Display-Kinect-color-image-containing-only-players-aka-background-removal