c# - 将Kinect深度图像捕获到png文件

标签 c# image kinect

我正在尝试将 kinect 深度传感器图像保存到 png 文件。我试着用我的 RGB 相机拍这个,没有任何问题。我错过了什么吗? 附言我正在使用 Kinect ToolKit 的功能来显示 rgb 和深度图像。

WriteableBitmap depthBitmap;
DepthStreamManager dsm;
dsm = new DepthStreamManager();
kinect.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
kinect.DepthFrameReady += kinect_DepthFrameReady;
depthBitmap = new WriteableBitmap(kinect.DepthStream.FrameWidth,this.kinect.DepthStream.FrameHeight, 96.0, 96.0, PixelFormats.Gray16, null);
private string TakeImage(int x)
    {
        if (x == 0)
        {
            BitmapEncoder encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(this.depthBitmap));
            string myPhotos = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string path = System.IO.Path.Combine(myPhotos, "Image 1.png");
            try
            {
                using (FileStream fs = new FileStream(path, FileMode.Create))
                {
                    encoder.Save(fs);
                }


            }
            catch (IOException details)
            {
                Console.Write(details.ToString());

            }
            if (path == null)
                return "Image was not taken.";
            else
                return path;
        }}

最佳答案

如果您使用 Coding4Fun Kinect toolkit ,我相信你可以使用 ImageFrame 对象。您可以转换 ImageFrame object to Bitmap从那里你应该能够save it as a PNG没有问题。

解决方案有点冗长,但我目前没有使用装有我的 Kinect 东西的机器。

编辑:如果您使用的是 WinForms,您可以简单地使用 Coding4Fun 工具包方法 ImageFrame.ToBitmap(),然后从那里另存为 PNG。

代码应该是这样的:

private void saveAsPNG(ImageFrame myImageFrame, string path)
{
   Bitmap bmp = myImageFrame.ToBitmap();

   bmp.Save(path, System.Drawing.Imaging.ImageFormat.Png);

   bmp.Dispose();
}

关于c# - 将Kinect深度图像捕获到png文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12211233/

相关文章:

image - 在 macOS 上删除本地 Docker 镜像

kinect - Kinect V2 中主动红外图像和深度图像之间的主要区别

c++ - kinect 作为网络摄像头

c# - 跨不同 Web 浏览器的单点登录

c# - Windows Phone 7 隐藏应用程序栏

c# - MVVM - 从各种 View 更新 StatusBar

c# - HttpClient 从不在 IIS 上发送请求

css - 将文本对齐到与中间对齐的图像的左侧

iphone - 像素配色估计

algorithm - 从数据构建 HMM