こんにちは、Kinect で行っているプロジェクトにこの方法があります。残念ながら、コードはベータ版であり、1.5 SDK バージョンに更新する必要があります。いくつか試してみましたが、うまくいきません。これが私がこれまでにしなければならないことです。メソッドは nui_DepthFrameReady と呼ばれます。
void nui_DepthFrameReady(object sender, ImageFrameReadyEventArgs e)
{
if (!savedDepth)
{
PlanarImage Image = e.ImageFrame.Image;
byte[] convertedDepthFrame = convertDepthFrame(Image.Bits);
depth.Source = BitmapSource.Create(
Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, convertedDepthFrame, Image.Width * 4);
++totalFrames;
DateTime cur = DateTime.Now;
if (cur.Subtract(lastTime) > TimeSpan.FromSeconds(1))
{
int frameDiff = totalFrames - lastFrames;
lastFrames = totalFrames;
lastTime = cur;
frameRate.Text = frameDiff.ToString() + " fps";
}
if (subscribed)
{
//byte[] ColoredBytes = GenerateColoredBytes(e.ImageFrame);
//create an image based on the colored bytes
BitmapSource myBitmapDepth = BitmapSource.Create(Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, convertedDepthFrame, Image.Width * PixelFormats.Bgr32.BitsPerPixel / 8);
string imageFilePath = @"C:\Temp\kinect\depth\bmpDepthFrame_" + cur.TimeOfDay.ToString().Replace(':', '.') + ".png";
string dataFilePath = @"C:\Temp\kinect\depth\depthFrame_" + cur.TimeOfDay.ToString().Replace(':', '.') + ".dat";
//savePngFrame(myBitmapDepth, imageFilePath);
//Crop frame to size 180x240
byte[] croppedDepthFrame = new byte[180 * 240 * 2];
for (int i = 0; i < 240; i++)
{
for (int j = 0; j < 180 * 2; j += 2)
{
croppedDepthFrame[i * 180 * 2 + j] = Image.Bits[i * 320 * 2 + j + 69 * 2];
croppedDepthFrame[i * 180 * 2 + j + 1] = Image.Bits[i * 320 * 2 + j + 1 + 69 * 2];
//Console.Write((i * 180 * 2 + j) + "-" + (i * 180 * 2 + j + 69*2) +", ");
}
//Console.WriteLine();
}
FileStream fs = new FileStream(dataFilePath, FileMode.Create);
fs.Write(croppedDepthFrame, 0, croppedDepthFrame.Length);
fs.Close();
}
savedDepth = true;
}
}
お手伝いありがとう。これは私がこれまでに持っているものです
void nui_DepthImageReady(object sender, DepthImageFrameReadyEventArgs e)
{
if (!savedDepth)
{
short[] pixelData;
bool receivedData = false;
using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame())
{
if (depthImageFrame != null)
{
if (pixelData == null) //allocate the first time
{
pixelData = new short[depthImageFrame.PixelDataLength];
}
depthImageFrame.CopyPixelDataTo(pixelData);
receivedData = true;
}
else
{
// apps processing of image data took too long; it got more than 2 frames behind.
// the data is no longer avabilable.
}
}
if (receivedData)
{
byte[] convertedDepthFrame = convertDepthFrame(Image.bits);
depth.Source = BitmapSource.Create(Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, convertedDepthFrame, Image.Width * 4);
++totalFrames;
DateTime cur = DateTime.Now;
if (cur.Subtract(lastTime) > TimeSpan.FromSeconds(1))
{
int frameDiff = totalFrames - lastFrames;
lastFrames = totalFrames;
lastTime = cur;
frameRate.Text = frameDiff.ToString() + " fps";
}
if (subscribed)
{
//byte[] ColoredBytes = GenerateColoredBytes(e.ImageFrame);
//create an image based on the colored bytes
BitmapSource myBitmapDepth = BitmapSource.Create(Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, convertedDepthFrame, Image.Width * PixelFormats.Bgr32.BitsPerPixel / 8);
string imageFilePath = @"C:\Temp\kinect\depth\bmpDepthFrame_" + cur.TimeOfDay.ToString().Replace(':', '.') + ".png";
string dataFilePath = @"C:\Temp\kinect\depth\depthFrame_" + cur.TimeOfDay.ToString().Replace(':', '.') + ".dat";
//savePngFrame(myBitmapDepth, imageFilePath);
//Crop frame to size 180x240
byte[] croppedDepthFrame = new byte[180 * 240 * 2];
for (int i = 0; i < 240; i++)
{
for (int j = 0; j < 180 * 2; j += 2)
{
croppedDepthFrame[i * 180 * 2 + j] = Image.Bits[i * 320 * 2 + j + 69 * 2];
croppedDepthFrame[i * 180 * 2 + j + 1] = Image.Bits[i * 320 * 2 + j + 1 + 69 * 2];
//Console.Write((i * 180 * 2 + j) + "-" + (i * 180 * 2 + j + 69*2) +", ");
}
//Console.WriteLine();
}
FileStream fs = new FileStream(dataFilePath, FileMode.Create);
fs.Write(croppedDepthFrame, 0, croppedDepthFrame.Length);
fs.Close();
}
}
savedDepth = true;
}
}
Image.Bits は、kinect または Image.Width、Image.Height の新しい SDK に定義がありません。これらは発生しているエラーであるため、コードを変換して同じ情報を取得する方法がわかりません。