Kinect 1.8 颜色帧和深度帧不协调

2024-03-22

我的程序存在深度和彩色图像之间协调不佳的问题。

玩家面具与人物不在同一位置(见下图)。

void _AllFreamReady(object sender, AllFramesReadyEventArgs e)
{
    using (ColorImageFrame _colorFrame = e.OpenColorImageFrame())
    {
        if (_colorFrame == null)  //jezeli pusta ramka nie rob nic
        {
            return;
        }
        byte[] _pixels = new byte[_colorFrame.PixelDataLength]; //utworzenie tablicy pixeli dla 1 ramki obrazu o rozmiarach przechwyconej ramki z strumienia 
        _colorFrame.CopyPixelDataTo(_pixels);                   //kopiujemy pixele do tablicy
        int _stride = _colorFrame.Width * 4;                    //Kazdy pixel moze miec 4 wartosci Red Green Blue lub pusty
        image1.Source =
            BitmapSource.Create(_colorFrame.Width, _colorFrame.Height,
            96, 96, PixelFormats.Bgr32, null, _pixels, _stride);

        if (_closing)
        {
            return;
        }

        using (DepthImageFrame _depthFrame = e.OpenDepthImageFrame())
        {
            if (_depthFrame == null)
            {
                return;
            }

            byte[] _pixelsdepth = _GenerateColoredBytes(_depthFrame,_pixels);
            int _dstride = _depthFrame.Width * 4;
            image3.Source =
                BitmapSource.Create(_depthFrame.Width, _depthFrame.Height,
                96, 96, PixelFormats.Bgr32, null, _pixelsdepth, _dstride);
        }
    }               
}

private byte[] _GenerateColoredBytes(DepthImageFrame _depthFrame, byte[] _pixels)
{
    short[] _rawDepthData = new short[_depthFrame.PixelDataLength];
    _depthFrame.CopyPixelDataTo(_rawDepthData);
    Byte[] _dpixels = new byte[_depthFrame.Height * _depthFrame.Width * 4];
    const int _blueindex = 0;
    const int _greenindex = 1;
    const int _redindex = 2;

    for (int _depthindex = 0, _colorindex = 0;
        _depthindex < _rawDepthData.Length && _colorindex < _dpixels.Length;
        _depthindex++, _colorindex += 4)
    {
        int _player = _rawDepthData[_depthindex] & DepthImageFrame.PlayerIndexBitmaskWidth;

        if (_player > 0)
        {
            _dpixels[_colorindex + _redindex] = _pixels[_colorindex + _redindex]; 
            _dpixels[_colorindex + _greenindex] = _pixels[_colorindex + _greenindex];
            _dpixels[_colorindex + _blueindex] = _pixels[_colorindex + _blueindex];

        };
    }

    return _dpixels;
}

RGB 和深度数据未对齐。这是由于深度传感器和 RGB 摄像头在 Kinect 外壳中的位置不同:它们是不同的,因此您不能期望使用不同的视点来对齐图像。

不过你的问题很常见,已经解决了KinectSensor.MapDepthFrameToColorFrame,在 SDK 1.6 后已弃用。现在,您需要的是CoordinateMapper.MapDepthFrameToColorFrame method https://msdn.microsoft.com/en-us/library/jj883690.aspx.

The 坐标映射基础 - WPF C# 示例 https://msdn.microsoft.com/en-us/library/hh973086.aspx展示了如何使用此方法。您可以在下面找到代码的一些重要部分:

// Intermediate storage for the depth data received from the sensor
private DepthImagePixel[] depthPixels;
// Intermediate storage for the color data received from the camera
private byte[] colorPixels;
// Intermediate storage for the depth to color mapping
private ColorImagePoint[] colorCoordinates;
// Inverse scaling factor between color and depth
private int colorToDepthDivisor;
// Format we will use for the depth stream
private const DepthImageFormat DepthFormat = DepthImageFormat.Resolution320x240Fps30;
// Format we will use for the color stream
private const ColorImageFormat ColorFormat = ColorImageFormat.RgbResolution640x480Fps30;

//...

// Initialization
this.colorCoordinates = new ColorImagePoint[this.sensor.DepthStream.FramePixelDataLength];
this.depthWidth = this.sensor.DepthStream.FrameWidth;
this.depthHeight = this.sensor.DepthStream.FrameHeight;
int colorWidth = this.sensor.ColorStream.FrameWidth;
int colorHeight = this.sensor.ColorStream.FrameHeight;
this.colorToDepthDivisor = colorWidth / this.depthWidth;
this.sensor.AllFramesReady += this.SensorAllFramesReady;

//...

private void SensorAllFramesReady(object sender, AllFramesReadyEventArgs e)
{
    // in the middle of shutting down, so nothing to do
    if (null == this.sensor)
    {
        return;
    }

    bool depthReceived = false;
    bool colorReceived = false;

    using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
    {
        if (null != depthFrame)
        {
            // Copy the pixel data from the image to a temporary array
            depthFrame.CopyDepthImagePixelDataTo(this.depthPixels);

            depthReceived = true;
        }
    }

    using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
    {
        if (null != colorFrame)
        {
            // Copy the pixel data from the image to a temporary array
            colorFrame.CopyPixelDataTo(this.colorPixels);

            colorReceived = true;
        }
    }

    if (true == depthReceived)
    {
        this.sensor.CoordinateMapper.MapDepthFrameToColorFrame(
            DepthFormat,
            this.depthPixels,
            ColorFormat,
            this.colorCoordinates);

        // ...

        int depthIndex = x + (y * this.depthWidth);
        DepthImagePixel depthPixel = this.depthPixels[depthIndex];

        // scale color coordinates to depth resolution
        int X = colorImagePoint.X / this.colorToDepthDivisor;
        int Y = colorImagePoint.Y / this.colorToDepthDivisor;

        // depthPixel is the depth for the (X,Y) pixel in the color frame
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Kinect 1.8 颜色帧和深度帧不协调 的相关文章

  • 为什么两个不同的 Base64 字符串的转换会返回相等的字节数组?

    我想知道为什么从 base64 字符串转换会为不同的字符串返回相同的字节数组 const string s1 dg const string s2 dq byte a1 Convert FromBase64String s1 byte a2
  • 不支持将数据直接绑定到存储查询(DbSet、DbQuery、DbSqlQuery)

    正在编码视觉工作室2012并使用实体模型作为我的数据层 但是 当页面尝试加载时 上面提到的标题 我使用 Linq 语句的下拉控件往往会引发未处理的异常 下面是我的代码 using AdventureWorksEntities dw new
  • 为什么当实例化新的游戏对象时,它没有向它们添加标签? [复制]

    这个问题在这里已经有答案了 using System Collections using System Collections Generic using UnityEngine public class Test MonoBehaviou
  • HTTPWebResponse 响应字符串被截断

    应用程序正在与 REST 服务通信 Fiddler 显示作为 Apps 响应传入的完整良好 XML 响应 该应用程序位于法属波利尼西亚 在新西兰也有一个相同的副本 因此主要嫌疑人似乎在编码 但我们已经检查过 但空手而归 查看流读取器的输出字
  • 堆栈溢出:堆栈空间中重复的临时分配?

    struct MemBlock char mem 1024 MemBlock operator const MemBlock b const return MemBlock global void foo int step 0 if ste
  • 将 VSIX 功能添加到 C# 类库

    我有一个现有的单文件生成器 位于 C 类库中 如何将 VSIX 项目级功能添加到此项目 最终目标是编译我的类库项目并获得 VSIX 我实际上是在回答我自己的问题 这与Visual Studio 2017 中的单文件生成器更改 https s
  • 将多个表映射到实体框架中的单个实体类

    我正在开发一个旧数据库 该数据库有 2 个具有 1 1 关系的表 目前 我为每个定义的表定义了一种类型 1Test 1Result 我想将这些特定的表合并到一个类中 当前的类型如下所示 public class Result public
  • 使用 Bearer Token 访问 IdentityServer4 上受保护的 API

    我试图寻找此问题的解决方案 但尚未找到正确的搜索文本 我的问题是 如何配置我的 IdentityServer 以便它也可以接受 授权带有 BearerTokens 的 Api 请求 我已经配置并运行了 IdentityServer4 我还在
  • WPF 绑定 CompositeCollection 中的 MenuItem 不起作用

    我在将命令绑定到复合集合中的菜单项时遇到问题 这MenuItem是其一部分ContextMenu这是定义在UserControl Resources 问题是新标签的绑定不起作用 当我将 MenuItem 放置在复合集合之外时 它将起作用 有
  • 转发声明和包含

    在使用库时 无论是我自己的还是外部的 都有很多带有前向声明的类 根据情况 相同的类也包含在内 当我使用某个类时 我需要知道该类使用的某些对象是前向声明的还是 include d 原因是我想知道是否应该包含两个标题还是只包含一个标题 现在我知
  • 如何在 C 中调用采用匿名结构的函数?

    如何在 C 中调用采用匿名结构的函数 比如这个函数 void func struct int x p printf i n p x 当提供原型的函数声明在范围内时 调用该函数的参数必须具有与原型中声明的类型兼容的类型 其中 兼容 具有标准定
  • 使用 x509 证书签署 json 文档或字符串

    如何使用 x509 证书签署 json 文档或字符串 public static void fund string filePath C Users VIKAS Desktop Data xml Read the file XmlDocum
  • Windows 窗体:如果文本太长,请添加新行到标签

    我正在使用 C 有时 从网络服务返回的文本 我在标签中显示 太长 并且会在表单边缘被截断 如果标签不适合表单 是否有一种简单的方法可以在标签中添加换行符 Thanks 如果您将标签设置为autosize 它会随着您输入的任何文本自动增长 为
  • 覆盖子类中的字段或属性

    我有一个抽象基类 我想声明一个字段或属性 该字段或属性在从该父类继承的每个类中具有不同的值 我想在基类中定义它 以便我可以在基类方法中引用它 例如覆盖 ToString 来表示 此对象的类型为 property field 我有三种方法可以
  • 如何从两个不同的项目中获取文件夹的相对路径

    我有两个项目和一个共享库 用于从此文件夹加载图像 C MainProject Project1 Images 项目1的文件夹 C MainProject Project1 Files Bin x86 Debug 其中有project1 ex
  • 将控制台重定向到 .NET 程序中的字符串

    如何重定向写入控制台的任何内容以写入字符串 对于您自己的流程 Console SetOut http msdn microsoft com en us library system console setout aspx并将其重定向到构建在
  • C# 成员变量继承

    我对 C 有点陌生 但我在编程方面有相当广泛的背景 我想做的事情 为游戏定义不同的 MapTiles 我已经像这样定义了 MapTile 基类 public class MapTile public Texture2D texture pu
  • 测试用例执行完成后,无论是否通过,如何将测试用例结果保存在变量中?

    我正在使用 NUNIT 在 Visual Studio 中使用 Selenium WebDriver 测试用例的代码是 我想在执行测试用例后立即在变量中记录测试用例通过或失败的情况 我怎样才能实现这一点 NUnit 假设您使用 NUnit
  • C# 模拟VolumeMute按下

    我得到以下代码来模拟音量静音按键 DllImport coredll dll SetLastError true static extern void keybd event byte bVk byte bScan int dwFlags
  • IEnumreable 动态和 lambda

    我想在 a 上使用 lambda 表达式IEnumerable

随机推荐

  • Qt:QProcess调用终端+脚本

    我在使用 QProcess 时遇到了真正的麻烦 我已经查看了几个使用它的位置 但每次使用它时我的程序都会冻结 或者它只是不执行我想要它执行的操作 我想从 GUI 应用程序执行以下操作 将目录更改为 Users Tim etc 等 从那里我需
  • 创建一个简单的 VUE.JS 应用程序

    我正在尝试按照以下步骤在应用程序中使用 Vue 中的简单多边形裁剪器article https morioh com p 06b7fc24c8b5 我使用以下方法创建了我的应用程序 vue init webpack myproject 现在
  • 如何在包含 Rust 特征的泛型类型上实现 deref?

    如果能够使用 Deref 从通用容器生成 TraitType 而不是调用 instance as ref 会相当方便 IE my container do thing vs my container as ref do thing 为此 我
  • 防止复制使用 dompdf 创建的 pdf 中的内容

    有没有办法阻止接收者在dompdf中选择和复制pdf文件的内容 像其他打开它时看起来像图片的pdf文件一样 所有字母和图像都无法选择 您可以使用底层 CPDF 引擎来指定用户可以对文档执行哪些操作 根据 CPDF 文档 调用 setEncr
  • 获取设备令牌时发件人 ID 无效

    我正在我的 Android 应用程序中进行 Firebase 云消息传递设置 我不是第一次做 我已经做过很多次了 但这一次 我在尝试获取设备令牌时遇到了一个奇怪的错误 无效的发件人 ID 除了默认情况下存在于 google services
  • 如何使用Java打开和关闭虚拟键盘

    我尝试了这里的所有答案 在Java程序中打开Windows虚拟键盘 https stackoverflow com questions 4948420 open the windows virtual keyboard in a java
  • 抽象类中受保护的抽象或公共抽象方法

    嗨 我有一个抽象类 其中有一些公共方法和一些抽象方法 我有公众 以便他们实现派生类的通用方法 让我困惑的是为什么我想要定义一个公共抽象方法而不是受保护的抽象方法 对我来说 在抽象类中定义公共抽象方法是没有意义的 因为 if 是一个抽象 在派
  • Laravel 5,连接子句中的派生表?

    我有这样的疑问 SELECT FROM blog LEFT JOIN SELECT blog id AVG value as blog rating FROM blog ratings GROUP BY blog id T ON T blo
  • 绘制的 envfit 向量与 NMDS 分数不匹配

    我制作了一个 NMDS 图并绘制了我的环境 如下所示 mytable 的数据框 sites c Site A Site B Site C Site D Site E Site F Site G Site H Site I Site J Si
  • heroku无法安装zbar

    我有一个 Django 应用程序 它使用 zbar 进行条形码识别 它在我的开发人员机器上运行良好 但当我尝试将其部署到 Heroku 时 我的提交被拒绝 并显示以下消息 Installing collected packages zbar
  • 调用 FileWriter 的单元测试方法

    我正在尝试为调用 FileWriter 的方法编写单元测试 我正在使用 JUnit 4 8 Powermock 和 Mockito 我正在测试的方法看起来像这样 public void methodToTest String fileNam
  • 在 pandas 中,按 DatetimeIndex 中的日期进行分组

    考虑以下综合示例 import pandas as pd import numpy as np np random seed 42 ix pd date range 2017 01 01 2017 01 15 freq 1H df pd D
  • Swift 3:将字符串转换为数组

    我在 SWIFT 3 上的应用程序上 我在屏幕上显示一个句子并记录用户的声音以查看是否匹配 我想提取句子中的每个单词来单独比较每个单词 我使用代码 let StringToLearn word text let StringToLearnA
  • 更改 SQL Server 中的用户定义类型

    我在数据库中创建了一些用户定义的类型 如下所示 CREATE TYPE dbo StringID FROM nvarchar 20 NOT NULL 并将它们分配到不同的表中 我的数据库中的表具有各种模式 不仅dbo 但我意识到我需要更大的
  • 使用jquery打开文件浏览器

    我有以下代码 p Select a file p
  • 使用 NavigationLink 将信息传递到另一个视图

    我有以下视图 我需要通过item内容到另一个视图 DetailsEvent swift 我正在使用NavigationLink 我使用的是 Xcode 11 GM struct Events View ObservedObject var
  • HDFS如何计算可用块?

    假设块大小为 128MB 则集群有 10GB 因此大约 80 个可用块 假设我创建了 10 个小文件 这些文件总共占用磁盘上 128MB 块文件 校验和 复制 和 10 个 HDFS 块 如果我想向HDFS添加另一个小文件 那么HDFS使用
  • 谷歌地图API可以进行语音导航吗?

    如何使用 google 地图 api v3 激活基于语音的方向 我已经实现了给出从起点到终点的方向的地图 但现在我想听听我当前所在位置的名称 请帮忙 我在 ios UIWebView 中实现了它 所以我从 GPS 获取当前位置 现在我每 2
  • JavaScript - for循环问题中变量递增

    我试图创建一个 for 循环 递增数字 1 4 并打印它们 但是当我在循环后打印 i 的值时 我的代码输出 5 for i 1 i lt 5 i document write i br Outputs numbers 1 4 documen
  • Kinect 1.8 颜色帧和深度帧不协调

    我的程序存在深度和彩色图像之间协调不佳的问题 玩家面具与人物不在同一位置 见下图 void AllFreamReady object sender AllFramesReadyEventArgs e using ColorImageFram