将颜色和深度数据保存为png到文件流 [英] Saving Color and Depth data as png to filestream

查看:116
本文介绍了将颜色和深度数据保存为png到文件流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用PngBitmapEncoder将颜色和深度数据保存为单独的文件,但保存的深度帧比颜色少得多。

I try to save both color and depth data to separate files as PNGs using PngBitmapEncoder but I get much less depth frames saved than color.

如果我将颜色保存为Jpeg使用PpeBitmapEncoder使用JpegBitmapEncoder和深度为PNG我从两个流中获得相同数量的帧。

If I save color as Jpeg with JpegBitmapEncoder and depth as PNG using PngBitmapEncoder I get the same amount of frames from both streams.

任何人都可以解释我为什么?

Can anyone explain me why?

private void myKinectSensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame color = e.OpenColorImageFrame())
            {
                if (color != null)
                {
                    colorbits = new byte[color.PixelDataLength];
                    color.CopyPixelDataTo(colorbits);
                    PngBitmapEncoder enc = new PngBitmapEncoder();
                    enc.Frames.Add(BitmapFrame.Create(BitmapSource.Create(color.Width, color.Height, 96, 96, PixelFormats.Bgr32, null, colorbits, color.Width * color.BytesPerPixel)));
                        
                    if (StartSavingFrames)
                    {
                        string temppath = System.IO.Path.Combine(@"../output/kinect1/color/", colorcnt.ToString() + ".jpeg");
                        FileStream fs = new FileStream(temppath, FileMode.Create);
                        enc.Save(fs);
                        fs.Close();
                        fs = null;
                        colorcnt++;
                    }
                    else { colorcnt = 0; }
                }
            }
        }





private void myKinectSensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
        {
            using (DepthImageFrame depth = e.OpenDepthImageFrame())
            {
                
                if (depth != null)
                {
                    frame = new short[depth.PixelDataLength];
                    depth.CopyPixelDataTo(frame);
                    for (int i = 0; i < depth.PixelDataLength; i++)
                    {
                        frame[i] = (short)(((ushort)frame[i]) >> 3);
                    }
                    PngBitmapEncoder enc = new PngBitmapEncoder();
                    enc.Frames.Add(BitmapFrame.Create(BitmapSource.Create(depth.Width, depth.Height, 96, 96, PixelFormats.Gray16, null, frame, depth.Width * depth.BytesPerPixel)));
           
                    if (StartSavingFrames)
                    {
                        string temppath = System.IO.Path.Combine(@"../output/kinect1/depth/", cnt.ToString() + ".png");
                        FileStream fs = new FileStream(temppath, FileMode.Create);
                        enc.Save(fs);
                        fs.Close();
                        fs = null;
                        cnt++;
                    }
                    else { cnt = 0; }
                }
            }
        }

推荐答案

写入操作的性能以及系统在调用它们时的操作。您需要确保您的函数返回并释放(处置)帧的速度比回调时间更快。当您持有数据到
long时,这只会阻止您的应用程序获取新数据。

performance of the write operations and the operations of the system at the time you are calling them. You need to ensure your functions are returning and releasing(disposing) of the frames faster than the callback times. When you hold onto data to long, that just prevents your application from getting new data.

查看工具包中的坐标映射示例,以便同时复制这两种数据。深度和颜色同时。从那里你需要创建一个新的线程来保存这些数据,因为写入速度非常慢。

Have a look at the coordinate mapping sample from the toolkit for a way to copy both the depth and color at the same time. From there you need to create a new thread to save that data since write speeds are very slow.


这篇关于将颜色和深度数据保存为png到文件流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆