Kinect:从RGB坐标转换为深度坐标 [英] Kinect: Converting from RGB Coordinates to Depth Coordinates

查看:1021
本文介绍了Kinect:从RGB坐标转换为深度坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows Kinect SDK从传感器获取深度和RGB图像。

I am using the Windows Kinect SDK to obtain depth and RGB images from the sensor.

由于深度图像和RGB图像不对齐,我想找到一种方法将RGB图像的坐标转换为深度图像的坐标,因为我想在我从RGB图像上的一些处理中获得的深度图像上使用图像蒙版。

Since the depth image and the RGB images do not align, I would like to find a way of converting the coordinates of the RGB image to that of the depth image, since I want to use an image mask on the depth image I have obtained from some processing on the RGB image.

已经有一种方法可以将深度坐标转换为色彩空间坐标:

There is already a method for converting depth coordinates to the color space coordinates:

NuiImageGetColorPixelCoordinatesFromDepthPixel

不幸的是,反向不存在。只有在INUICoordinateMapper一个神秘呼叫:

unfortunately, the reverse does not exist. There is only an arcane call in INUICoordinateMapper:

HRESULT MapColorFrameToDepthFrame(
     NUI_IMAGE_RESOLUTION eColorResolution,
     NUI_IMAGE_RESOLUTION eDepthResolution,
     DWORD cDepthPixels,
     NUI_DEPTH_IMAGE_PIXEL *pDepthPixels,
     DWORD cDepthPoints,
     NUI_DEPTH_IMAGE_POINT *pDepthPoints
)

这种方法的工作原理并没有很好的记录。有没有人以前用过它?

How this method works is not very well documented. Has anyone used it before?

我即将自己进行手动校准来计算变换矩阵,所以我很乐意找到解决方案。

I'm on the verge of performing a manual calibration myself to calculate a transformation matrix, so I would be very happy for a solution.

推荐答案

感谢评论员的恐怖主义,我得到了一个msdn的链接,提供了一些有用的信息(感谢T. Chen在msdn上的帮助API)。从T. Chen的帖子中提取,这里是执行从RGB到深度坐标空间的映射的代码:

Thanks to commenter horristic, I got a link to msdn with some useful information (thanks also to T. Chen over at msdn for helping out with the API). Extracted from T. Chen's post, here's the code that will perform the mapping from RGB to depth coordinate space:

INuiCoordinateMapper* pMapper;

mNuiSensor->NuiGetCoordinateMapper(&pMapper);

pMapper->MapColorFrameToDepthFrame(
        NUI_IMAGE_TYPE_COLOR,
        NUI_IMAGE_RESOLUTION_640x480,
        NUI_IMAGE_RESOLUTION_640x480,
        640 * 480, 
        (NUI_DEPTH_IMAGE_PIXEL*)LockedRect.pBits,
        640 * 480, 
        depthPoints);

注意:需要初始化传感器并锁定深度帧这个工作。

Note: the sensor needs to be initialized and a depth frame locked for this to work.

例如,可以按如下方式查询转换后的坐标:

The transformed coordinates can, e.g., be queried as follows:

/// transform RGB coordinate point to a depth coordinate point 
cv::Point TransformRGBtoDepthCoords(cv::Point rgb_coords, NUI_DEPTH_IMAGE_POINT *    depthPoints)
{
    long index = rgb_coords.y * 640 + rgb_coords.x;
    NUI_DEPTH_IMAGE_POINT depthPointAtIndex = depthPoints[index];
    return cv::Point(depthPointAtIndex.x, depthPointAtIndex.y); 
}

这篇关于Kinect:从RGB坐标转换为深度坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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