如何为 Kinect 生成的点云添加颜色?

时间:2021-03-12 17:42:54

标签: processing kinect point-clouds kinect-sdk openkinect

所以我试图从 Kinect V1 获取带有 RGB 值的点云数据。 我使用了 Daniel Shiffman (https://shiffman.net/p5/kinect/) 制作的 Processing 库来获取点云数据,但是该库没有将 RGB 数据从彩色相机映射到点云。

我找到了 Daniel Shiffman 在他的库中用来生成点云的函数的源代码 (http://graphics.stanford.edu/~mdfisher/Kinect.html),并且我找到了一个将点云转换为 RGB 点云的代码段。我附上了下面的代码。 现在我想在 Processing 中运行这段代码,但我不知道代码片段中发生了什么。如果有人可以解释代码中发生的事情或帮助我将其转换为处理格式。 我相信正在进行一些相机参数计算,以便在 Kinect 中正确地将 RGB 传感器与深度传感器映射。

Vec2i WorldToColor(const Vec3f &pt) \\This function takes Point Cloud in World Coordinates as Input
{
    static const Matrix4 rotationMatrix(
                            Vec3f(9.9984628826577793e-01f, 1.2635359098409581e-03f, -1.7487233004436643e-02f),
                            Vec3f(-1.4779096108364480e-03f, 9.9992385683542895e-01f, -1.2251380107679535e-02f),
                            Vec3f(1.7470421412464927e-02f, 1.2275341476520762e-02f, 9.9977202419716948e-01f));
    static const Vec3f translation(1.9985242312092553e-02f, -7.4423738761617583e-04f, -1.0916736334336222e-02f);
    static const Matrix4 finalMatrix = rotationMatrix.Transpose() * Matrix4::Translation(-translation);
    
    static const double fx_rgb = 5.2921508098293293e+02;
    static const double fy_rgb = 5.2556393630057437e+02;
    static const double cx_rgb = 3.2894272028759258e+02;
    static const double cy_rgb = 2.6748068171871557e+02;

    const Vec3f transformedPos = finalMatrix.TransformPoint(pt);
    const float invZ = 1.0f / transformedPos.z;

    Vec2i result;
    result.x = Utility::Bound(Math::Round((transformedPos.x * fx_rgb * invZ) + cx_rgb), 0, 639);
    result.y = Utility::Bound(Math::Round((transformedPos.y * fy_rgb * invZ) + cy_rgb), 0, 479);
    return result;
}

0 个答案:

没有答案
相关问题