如何将kinect的深度图像与彩色图像对齐

2024-01-15

Kinect 上的颜色和深度传感器生成的图像略有不对齐。我怎样才能改变它们以使它们对齐?


关键是调用“Runtime.NuiCamera.GetColorPixelCoordinatesFromDepthPixel”

这是 Runtime 类的扩展方法。它返回一个 WriteableBitmap 对象。这个 WriteableBitmap 会随着新帧的进入而自动更新。所以它的用法非常简单:

    kinect = new Runtime();
    kinect.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseDepthAndPlayerIndex);
    kinect.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex);
    kinect.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
    myImageControl.Source = kinect.CreateLivePlayerRenderer(); 

这是代码本身:

public static class RuntimeExtensions
{
   public static WriteableBitmap CreateLivePlayerRenderer(this Runtime runtime)
   {
      if (runtime.DepthStream.Width == 0)
         throw new InvalidOperationException("Either open the depth stream before calling this method or use the overload which takes in the resolution that the depth stream will later be opened with.");
      return runtime.CreateLivePlayerRenderer(runtime.DepthStream.Width, runtime.DepthStream.Height);
   }
   public static WriteableBitmap CreateLivePlayerRenderer(this Runtime runtime, int depthWidth, int depthHeight)
   {
      PlanarImage depthImage = new PlanarImage();
      WriteableBitmap target = new WriteableBitmap(depthWidth, depthHeight, 96, 96, PixelFormats.Bgra32, null);
      var depthRect = new System.Windows.Int32Rect(0, 0, depthWidth, depthHeight);

      runtime.DepthFrameReady += (s, e) =>
            {
                depthImage = e.ImageFrame.Image;
                Debug.Assert(depthImage.Height == depthHeight && depthImage.Width == depthWidth);
            };

      runtime.VideoFrameReady += (s, e) =>
            {
                // don't do anything if we don't yet have a depth image
                if (depthImage.Bits == null) return;

                byte[] color = e.ImageFrame.Image.Bits;

                byte[] output = new byte[depthWidth * depthHeight * 4];

                // loop over each pixel in the depth image
                int outputIndex = 0;
                for (int depthY = 0, depthIndex = 0; depthY < depthHeight; depthY++)
                {
                    for (int depthX = 0; depthX < depthWidth; depthX++, depthIndex += 2)
                    {
                        // combine the 2 bytes of depth data representing this pixel
                        short depthValue = (short)(depthImage.Bits[depthIndex] | (depthImage.Bits[depthIndex + 1] << 8));

                        // extract the id of a tracked player from the first bit of depth data for this pixel
                        int player = depthImage.Bits[depthIndex] & 7;

                        // find a pixel in the color image which matches this coordinate from the depth image
                        int colorX, colorY;
                        runtime.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(
                            e.ImageFrame.Resolution,
                            e.ImageFrame.ViewArea,
                            depthX, depthY, // depth coordinate
                            depthValue,  // depth value
                            out colorX, out colorY);  // color coordinate

                        // ensure that the calculated color location is within the bounds of the image
                        colorX = Math.Max(0, Math.Min(colorX, e.ImageFrame.Image.Width - 1));
                        colorY = Math.Max(0, Math.Min(colorY, e.ImageFrame.Image.Height - 1));

                        output[outputIndex++] = color[(4 * (colorX + (colorY * e.ImageFrame.Image.Width))) + 0];
                        output[outputIndex++] = color[(4 * (colorX + (colorY * e.ImageFrame.Image.Width))) + 1];
                        output[outputIndex++] = color[(4 * (colorX + (colorY * e.ImageFrame.Image.Width))) + 2];
                        output[outputIndex++] = player > 0 ? (byte)255 : (byte)0;
                    }
                }
                target.WritePixels(depthRect, output, depthWidth * PixelFormats.Bgra32.BitsPerPixel / 8, 0);
            };
            return target;
        }
    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将kinect的深度图像与彩色图像对齐 的相关文章

随机推荐

  • OleDb SQL 查询中的两个内部联接[重复]

    这个问题在这里已经有答案了 我正在尝试使用 OleDbCommand 对 Access 数据库 accdb 进行 SQL 查询 虽然这个命令工作正常 在OleDbCommand ExecuteReader string command SE
  • JSF 语言环境:浏览器定义的语言似乎被忽略

    目前 我的团队正在使用 Java 开发 Web 2 0 应用程序 我们使用 JSF 作为表示层 我们从表示层开始 因此尚未添加业务和数据层 我们使用的技术 JSF 莫贾拉 2 0 3 Primefaces 2 1 JSF 组件库 春季安全3
  • 在 .Net Core 应用程序中使用 SharePoint CSOM

    我想通过 Net Core MVC 应用程序上的 CSOM 库从 SharePoint 列表中获取数据 在 Net Framework 应用程序上实现这一点绝对没有问题 因为 Microsoft SharePoint Client 库包含
  • SVN 客户端错误“[...] 的服务器不支持 HTTP/DAV 协议”

    我正在 64 位系统上从 Windows 7 更新到 Windows 10 我在 Windows 7 机器上从 Subversion 服务器更新和签出项目没有任何问题 我下载了最新的 64 位版本并将其安装在 Windows 10 机器上
  • 对 qr.Q() 感到困惑:什么是“紧凑”形式的正交矩阵?

    R has a qr 函数 它使用 LINPACK 或 LAPACK 执行 QR 分解 根据我的经验 后者快 5 返回的主要对象是一个矩阵 qr 其中包含上三角矩阵 R 即R qr upper tri qr 到目前为止 一切都很好 qr 的
  • 将服务注入到类(而不是组件)Angular2

    我正在努力寻找一种将服务注入到 angular2 中的类对象中的方法 注意 这不是一个组件 只是一个类 export class Product id number name string manufacturer string const
  • 为什么自动装箱的整数和 .getClass() 值 ==-相等,而不仅仅是 .equals()-相等?

    也许我在 Java 上工作太久了 却没有真正理解它的一些基础知识 我确实明白 用于对象引用相等并且 equals 是为了对象值相等 比较Integers Integer x 1 y 1 System out println x y true
  • TFS 2015 - 等待请求代理

    因此 度假回来后 我的构建服务器不想再运行任何构建 它只是卡在了等待可用的代理 等待请求代理如果我取消它 我觉得它会卡住正在取消构建 因为在我取消构建后什么也没有发生 等待消息仍然存在 但构建不在构建队列中 代理池中的所有代理均呈绿色 且后
  • 改进 Dinic 算法的动态树数据结构

    我想将 Dinic 算法应用于动态树 但我找到的来源很少 特别是关于动态树 如果有一个带有详细解释的良好源代码或一些使用动态树的简单源代码 那就太好了 有人遇到过类似的事情吗 提前致谢 改进的基本思想是避免 Dinic 算法过早悲观 与预流
  • 在 div 中显示“显示更多”按钮而不是垂直滚动条

    我有一个固定高度的 div 其中包含一些 html 内容 当这个高度溢出时 我不希望出现滚动条 而是在 div 底部出现一个按钮 只有当你按下这个按钮时 所有的内容才会被显示 显然滚动条会自动显示 我知道有一个名为 溢出 的属性 您可以使用
  • 自动完成将值而不是标签应用于文本框

    我在尝试让自动完成功能正常工作时遇到了麻烦 对我来说一切看起来都不错但是
  • PopoverPresentationController 为零

    创建了一个单视图应用程序 我在其中放置了一个按钮 现在单击按钮我需要将 tableView 显示为弹出窗口 TableViewController 是在 xib 中创建的 问题是 tableViewController popoverPre
  • 使用任务管理器生成转储文件

    我知道在 Vista 中 您可以通过 goigg 到任务管理器 gt 进程 gt 右键单击 进程来生成转储文件 此选项在 Windows 7 Windows 2003 Windows 2008 等其他版本的 Windows 中是否可用 它在
  • Kivy - 另一个屏幕上的滑块类值更改

    我有一个滑块 其值会更改标签 这很容易理解 现在的问题是我想使用这个值在另一个屏幕上显示 最终 我希望滑块根据在滑块上选择的值在另一个屏幕上显示 1 16 个图像 下面是我现在所拥有的 它适用于该屏幕 但如何让这个值显示在另一个屏幕上 我知
  • NavUtils.shouldUpRecreateTask 在 JellyBean 上失败

    我有一个应用程序 它会发出通知 选择该通知后将启动一项活动 根据Android文档 我可以使用NavUtils shouldUpRecreateTask来检查活动是否已直接启动 即从通知 或通过正常的活动堆栈启动 然而它给出了错误的答案 我
  • 如何在 laravel 5.3 中显示图像

    我将图像存储在公共文件夹中现在我想显示我给出的路径的图像 但图像不显示任何人帮助我我的代码出了什么问题 我的图像完整路径是 public admin product img src height 30px width 30px 首先 您不应
  • 使用不同的输入参数多次运行 Fortran 代码

    我想使用不同的输入参数集多次运行 Fortran 77 程序 我已经确保输出文件名会根据我使用的不同输入参数而更改 但我不确定如何运行具有不同输入参数集的程序 而不必每次都转到代码来更改参数 为了说明我的问题 这里有一个简单的代码 PROG
  • 带皮肤的 BottomSheetDialogFragment 主题

    如何结合BottomSheetDialogFragment主题与其他主题 我的应用程序具有使用主题制作的皮肤 BottomSheetDialogFragment应该有圆角 我使用以下方法实现这一点 override fun onCreate
  • 为 iPhone 创建组合框 [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 由于没有预先存在的用于创建组合框 或选择框 的组件 如通过 Safari 在网页上看到的那样 有人可以
  • 如何将kinect的深度图像与彩色图像对齐

    Kinect 上的颜色和深度传感器生成的图像略有不对齐 我怎样才能改变它们以使它们对齐 关键是调用 Runtime NuiCamera GetColorPixelCoordinatesFromDepthPixel 这是 Runtime 类的