比较深度彩色图像 [英] compare depth-color image

查看:68
本文介绍了比较深度彩色图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想比较C#中深度和彩色相机渲染的数据流,并将它们一起返回到图像中(点云类......就像depthwithcolor c ++示例),这是我的代码。它会打开窗户然后它会粉碎..任何帮助?? 



          private void SensorAllFramesReady(object sender,AllFramesReadyEventArgs e)

        {

           使用(DepthImageFrame depthFrame = e.OpenDepthImageFrame())

           使用(ColorImageFrame colorFrame = e.OpenColorImageFrame())

            {

                OutputImage = new WriteableBitmap(depthFrame.Width,depthFrame.Height,96,96,PixelFormats.Bgr32,null); 

                

                byte [] colorPixels = new byte [colorFrame.PixelDataLength];

                short [] depthPixels = new short [depthFrame.PixelDataLength];

                byte [] output = new byte [sensor.DepthStream.FramePixelDataLength * sizeof(int)];

                int outputIndex = 0; 



                if(depthFrame!= null&& colorFrame!= null)

                {

                    depthFrame.CopyPixelDataTo(depthPixels);

                    colorFrame.CopyPixelDataTo(colorPixels);



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; for(int y = 0; y< depthFrame.Height; y ++)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; for(int x = 0; x< depthFrame.Width; x ++)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var depthIndex = x +(y * depthFrame.Width);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var playerIndex = depthPixels [depthIndex]& DepthImageFrame.PlayerIndexBitmask;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var colorPoint = sensor.MapDepthToColorImagePoint(depthFrame.Format,x,y,depthPixels [depthIndex],colorFrame.Format);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var colorPixelIndex =(colorPoint.X * colorFrame.BytesPerPixel)+(colorPoint.Y * colorFrame.BytesPerPixel * colorFrame.Width);



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; output [outputIndex] = colorPixels [colorPixelIndex + 0];

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;输出[outputIndex + 1] = colorPixels [colorPixelIndex + 1];

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;输出[outputIndex + 2] = colorPixels [colorPixelIndex + 2];

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; output [outputIndex + 3] = playerIndex> 0? (字节)255 :(字节)0; 

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ++ outputIndex;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; OutputImage.WritePixels(new Int32Rect(0,0,depthFrame.Width,depthFrame.Height),output,depthFrame.Width * depthFrame.BytesPerPixel,0);



  ; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Image.Source = OutputImage;



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   

  &NBSP; &NBSP; &NBSP; }&NBSP;

解决方案

什么异常(以及哪一行)崩溃?


我看到的一个错误(虽然我不认为它会导致崩溃),但++ outputIndex可能应该是outputIndex + = 4。


I还建议不要多次调用MapDepthToColorImagePoint ......这可能会非常慢。相反,你应该考虑每帧只调用一次MapDepthFrameToColorFrame。


John

K4W Dev



hello people, I want to compare the data streams rendered by depth and color camera in C# and return them together in an images (sort of point cloud.. like depthwithcolor c++ sample), here is my code. it opens the window but then it crush.. any help?? 

         private void SensorAllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
            {
                OutputImage = new WriteableBitmap(depthFrame.Width, depthFrame.Height, 96, 96, PixelFormats.Bgr32, null); 
                
                byte[] colorPixels = new byte[colorFrame.PixelDataLength];
                short[] depthPixels = new short[depthFrame.PixelDataLength];
                byte[] output = new byte[sensor.DepthStream.FramePixelDataLength * sizeof(int)];
                int outputIndex = 0; 

                if (depthFrame != null && colorFrame != null)
                {
                    depthFrame.CopyPixelDataTo(depthPixels);
                    colorFrame.CopyPixelDataTo(colorPixels);

                    for (int y = 0; y < depthFrame.Height; y++)
                    {
                        for (int x = 0; x < depthFrame.Width; x++)
                        {
                            var depthIndex = x + (y * depthFrame.Width);
                            var playerIndex = depthPixels[depthIndex] & DepthImageFrame.PlayerIndexBitmask;
                            var colorPoint = sensor.MapDepthToColorImagePoint(depthFrame.Format, x, y, depthPixels[depthIndex], colorFrame.Format);
                            var colorPixelIndex= (colorPoint.X*colorFrame.BytesPerPixel)+(colorPoint.Y*colorFrame.BytesPerPixel*colorFrame.Width);

                            output[outputIndex] = colorPixels[colorPixelIndex + 0];
                            output[outputIndex + 1] = colorPixels[colorPixelIndex + 1];
                            output[outputIndex + 2] = colorPixels[colorPixelIndex + 2];
                            output[outputIndex + 3] = playerIndex > 0 ? (byte)255 : (byte)0; 
                            ++outputIndex;
                        }
                    }

                    OutputImage.WritePixels(new Int32Rect(0, 0, depthFrame.Width, depthFrame.Height),output,depthFrame.Width * depthFrame.BytesPerPixel,0);

                    Image.Source = OutputImage;

                }
            }
                    
        } 

解决方案

With what exception (and on which line) does it crash?

One bug I see (though I don't think it would be causing a crash), is that ++outputIndex should probably be outputIndex += 4 instead.

I'd also recommend not calling MapDepthToColorImagePoint so many times... this is likely to be very slow. Instead, you should consider calling MapDepthFrameToColorFrame just once per frame.

John
K4W Dev


这篇关于比较深度彩色图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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