gpt4 book ai didi

c++ - Kinect v2 将颜色坐标映射到相机空间

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:01:57 25 4
gpt4 key购买 nike

我正在尝试将坐标从颜色空间映射到相机空间。我使用的代码如下:

HRESULT ModelRecognizer::MapColorToCameraCoordinates(const std::vector<ColorSpacePoint>& colorsps, std::vector<CameraSpacePoint>& camerasps)
{
//Access frame
HRESULT hr = GetDepthFrame();

if (SUCCEEDED(hr))
{
ICoordinateMapper* pMapper;
hr = m_pKinectSensor->get_CoordinateMapper(&pMapper);
if (SUCCEEDED(hr))
{
CameraSpacePoint* cameraSpacePoints = new CameraSpacePoint[cColorWidth * cColorHeight];
hr = pMapper->MapColorFrameToCameraSpace(nDepthWidth * nDepthHeight, depthImageBuffer, cColorWidth * cColorHeight, cameraSpacePoints);
if (SUCCEEDED(hr))
{
for (ColorSpacePoint colorsp : colorsps)
{
long colorIndex = (long)(colorsp.Y * cColorWidth + colorsp.X);
CameraSpacePoint csp = cameraSpacePoints[colorIndex];
camerasps.push_back(csp);
}
}
delete[] cameraSpacePoints;
}
}
ReleaseDepthFrame();
return hr;
}

我没有收到任何错误,但是,结果似乎旋转了 180 度并且有一个偏移量。有没有人建议我做错了什么?感谢您的帮助。

只是为了更全面地说明为什么我需要这个:

我正在使用开放式简历从彩色图像中跟踪粘贴在 table 上的彩色胶带。然后我在 3D 网格中的胶带位置创建墙。此外,我正在使用 KinectFusion 生成 table 上其他对象的网格。但是,当我在 Meshlab 中打开两个网格时,可以清楚地看到错位。由于我假设 KinectFusion 的网格是在 CameraSpace 中正确创建的,并且我在上述函数返回的 CameraSpacePoints 处准确创建了墙壁的网格,所以我很确定错误出在 CoordinateMapping 过程中。

可以在 http://imgur.com/UsrEdZb,ZseN2br#0 找到显示错位的图像, http://imgur.com/UsrEdZb,ZseN2br#1

最佳答案

我终于弄明白了:无论出于何种原因,返回的 CameraSpacePoints 在 X 和 Y 的原点处进行了镜像,而不是在 Z 中。如果有人对此有解释,我仍然很感兴趣。

现在可以使用以下代码:

/// <summary>
/// Maps coordinates from ColorSpace to CameraSpace
/// Expects that the Points in ColorSpace are mirrored at x (as Kinects returns it by default).
/// </summary>
HRESULT ModelRecognizer::MapColorToCameraCoordinates(const std::vector<ColorSpacePoint>& colorsps, std::vector<CameraSpacePoint>& camerasps)
{
//Access frame
HRESULT hr = GetDepthFrame();

if (SUCCEEDED(hr))
{
ICoordinateMapper* pMapper;
hr = m_pKinectSensor->get_CoordinateMapper(&pMapper);
if (SUCCEEDED(hr))
{
CameraSpacePoint* cameraSpacePoints = new CameraSpacePoint[cColorWidth * cColorHeight];
hr = pMapper->MapColorFrameToCameraSpace(nDepthWidth * nDepthHeight, depthImageBuffer, cColorWidth * cColorHeight, cameraSpacePoints);
if (SUCCEEDED(hr))
{
for (ColorSpacePoint colorsp : colorsps)
{
int colorX = static_cast<int>(colorsp.X + 0.5f);
int colorY = static_cast<int>(colorsp.Y + 0.5f);
long colorIndex = (long)(colorY * cColorWidth + colorX);
CameraSpacePoint csp = cameraSpacePoints[colorIndex];
camerasps.push_back(CameraSpacePoint{ -csp.X, -csp.Y, csp.Z });
}
}
delete[] cameraSpacePoints;
}
}
ReleaseDepthFrame();
return hr;
}

关于c++ - Kinect v2 将颜色坐标映射到相机空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27889646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com