zoukankan      html  css  js  c++  java
  • Kinect学习笔记(五)——更专业的深度图

           这一节的内容就是把深度图转换为彩色图,然后不再使用硬解码,而是继续采用sdk里面封装好的功能来减少测量的误差,以及避免转换为灰度图时,出现绿巨人时候的掉针的bug.

          下面直接贴代码吧。

    private byte[]convertDepthFrameToColorFrame2(short[] depthFrame,DepthImageStream depthSteam)
            {
                byte[] depthFrame32 = new byte[depthSteam.FrameWidth * depthSteam.FrameHeight * Bgr32BytesPerPixel];
    
                //通过常量获得有效视距,不用硬解码(就是自己定义距离)
                int tooNearDepth = depthSteam.TooNearDepth;
                int tooFarDepth = depthSteam.TooFarDepth;
                int unknownDepth = depthSteam.UnknownDepth;
                for(int i16=0,i32=0;i16<depthFrame.Length&&i32<depthFrame32.Length;i16++,i32+=4)
                {
                    int player = depthFrame[i16] & DepthImageFrame.PlayerIndexBitmask;
                    int realDepth = depthFrame[i16] >> DepthImageFrame.PlayerIndexBitmaskWidth;
                    //通过位运算,将13位的深度图,裁剪为8位,对于显示足够了。
                    byte intensity = (byte)(~(realDepth >> 4));
    
                    if(player==0&&realDepth==0)
                    {
                        //白色
                        depthFrame32[i32 + RedIndex] = 255;
                        depthFrame32[i32 + GreenIndex] = 255;
                        depthFrame32[i32 + BlueIndex] = 255;
                    }
                    else if(player==0&&realDepth==tooFarDepth)
                    {
                        //深紫色
                        depthFrame32[i32 + RedIndex] = 66;
                        depthFrame32[i32 + GreenIndex] = 0;
                        depthFrame32[i32 + BlueIndex] = 66;
                    }
                    else if (player == 0 && realDepth == unknownDepth)
                    {
                        //深棕色
                        depthFrame32[i32 + RedIndex] = 66;
                        depthFrame32[i32 + GreenIndex] = 66;
                        depthFrame32[i32 + BlueIndex] = 33;
                    }
                    else
                    {
                        depthFrame32[i32 + RedIndex] = (byte)(intensity >> IntensityShiftByPlayerR[player]);
                        depthFrame32[i32 + GreenIndex] = (byte)(intensity >> IntensityShiftByPlayerG[player]);
                        depthFrame32[i32 + BlueIndex] = (byte)(intensity >> IntensityShiftByPlayerB[player]);
                    }
                }
    
                return depthFrame32;
    
            }
    void _kinect_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
            {
               using(DepthImageFrame depthFrame = e.OpenDepthImageFrame())
                {
                   if(depthFrame!=null)
                   {
                       short[] depthPixelData = new short[depthFrame.PixelDataLength];
                       depthFrame.CopyPixelDataTo(depthPixelData);
                       byte[] pixels = this.convertDepthFrameToColorFrame2(depthPixelData, ((KinectSensor)sender).DepthStream);
    
                       int stride = depthFrame.Width * 4;
    
                       imageDepth.Source = BitmapSource.Create(depthFrame.Width, depthFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride);
    
                        
    
                   }
                }
            }

    再附上效果图

    image

  • 相关阅读:
    Javascript 公共代码(可重用)
    ExtJs之Ext.data.Store
    delete exists
    c++ builder adoquery sql语句的动态增加
    C++ XML解析之TinyXML篇
    oracle数据类型varchar2和varchar的区别
    adoquery查询结果如何赋给一个变量(delphi和c++ builder)
    没有安装 BCB 的机器上运行会提示 找不到 库之类
    select union 查询出来的结果,如何按指定顺序输出
    oracle 已有 表 增加 列
  • 原文地址:https://www.cnblogs.com/BlueMountain-HaggenDazs/p/4107275.html
Copyright © 2011-2022 走看看