gpt4 book ai didi

c# - 如何将 Kinect v2 保留的 WriteableBitmap 对象保存到 Windows 应用商店应用程序中的图像文件

转载 作者:太空宇宙 更新时间:2023-11-03 15:40:51 26 4
gpt4 key购买 nike

我有一个 Windows 应用程序 C# 程序,它通过 Kinect v2 红外摄像头检测用户的头部位置。

红外数据保存在WriteableBitmap中,我想将检测到的头部作为图像文件保存在我的硬盘上。

我尝试了很多解决方案,例如 this没有运气。

这是我的头部跟踪代码。 irBitmap 是我的 WritableBitmap,一旦检测到头部,我想将其保存为图像文件。

      void msfr_MultiSourceFrameArrived(MultiSourceFrameReader sender, MultiSourceFrameArrivedEventArgs args)
{
using (MultiSourceFrame msf = args.FrameReference.AcquireFrame()) //acquiring frame.
{
if (msf != null)
{
using (BodyFrame bodyFrame = msf.BodyFrameReference.AcquireFrame()) //acquire the body frame now in the msf.
{
using (InfraredFrame irFrame = msf.InfraredFrameReference.AcquireFrame())
{
if (bodyFrame != null && irFrame != null)
{
irFrame.CopyFrameDataToArray(irData);

for (int i = 0; i < irData.Length; i++)
{
byte intensity = (byte)(irData[i] >> 8);
irDataConverted[i * 4] = intensity;
irDataConverted[i * 4 + 1] = intensity;
irDataConverted[i * 4 + 2] = intensity;
irDataConverted[i * 4 + 3] = 255;
}
irDataConverted.CopyTo(irBitmap.PixelBuffer);
irBitmap.Invalidate();

bodyFrame.GetAndRefreshBodyData(bodies);
bodyCanvas.Children.Clear();

foreach (Body body in bodies) //now we go trough each of our bodies (in order to look for head)
{
if (body.IsTracked) //Chek if the body is tracked
{
Joint headJoint = body.Joints[JointType.Head]; //If body is tracked we will get the head joint
if (headJoint.TrackingState == TrackingState.Tracked) //We need to make sure with this bool that the head is tracked.
{
DepthSpacePoint dps = sensor.CoordinateMapper.MapCameraPointToDepthSpace(headJoint.Position); //We create a debthspace point so we can draw that into our image. This is drawin in the image. It is the cameraspace point that goes to debthspace.
Ellipse headCircle = new Ellipse() {Width = 100, Height = 100, Fill = new SolidColorBrush(Color.FromArgb(255,255,0,0))}; //Ellispe to draw the new heads.
bodyCanvas.Children.Add(headCircle); //Add the headcircle drawn circle to the canvas.
Canvas.SetLeft(headCircle, dps.X-50); //and now we tell the canvas where to draw this shit.
Canvas.SetTop(headCircle, dps.Y-50); //



}
}
}
}
}
}
}
}
}

对于如何将 WritableBitmap 保存为我的硬盘驱动器上的图像文件的任何建议/帮助/建议,我将不胜感激。

最佳答案

我在类似的项目中使用了以下代码。这里,data 是来自 kinect 的原始图像流。

MemoryStream ms = new MemoryStream(data);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
img.Save("./image" + (++imageSerial) + ".png", System.Drawing.Imaging.ImageFormat.Png);

关于c# - 如何将 Kinect v2 保留的 WriteableBitmap 对象保存到 Windows 应用商店应用程序中的图像文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30324848/

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