无论如何我可以获得每个颜色(rgb)图像的像素匹配哪个深度(ir)图像的像素?

Is there anyway I can get every color(rgb) image's pixel matching which depth(ir) image's pixel?

我用的是Kinect2.0。我已经得到了深度相机和彩色相机的内参数,以及它们之间的外参数。

现在我已经知道每个深度(IR)图像的像素与哪个颜色(RGB)图像的像素匹配。

    for (int i = 0; i < 424; i++)
    {
        for (int j = 0; j < 512; j++)
        {
            fscanf(fp_dp, "%lf", &depthValue);

            if (depthValue == 0) continue;

            double Pir[3][1] = { j*depthValue, i*depthValue, depthValue };

            P_ir = Mat(3, 1, CV_64F, Pir);
            P_rgb = Mat(3, 1, CV_64F);
            P_rgb = Intrinsic_rgb*(R_ir2rgb*(Intrinsic_ir_inv*P_ir) + T_ir2rgb);

            int x = P_rgb.at<double>(0, 0) / depthValue;
            int y = P_rgb.at<double>(1, 0) / depthValue;
            //printf("(%d,%d)\n", x, y);

            if (x < 0 || y < 0 || x >= 1920 || y >= 1080)
            {
                continue;
            }
            img_mmap.at<Vec3b>(i, j)[0] = img_rgb.at<Vec3b>(y, x)[0];
            img_mmap.at<Vec3b>(i, j)[1] = img_rgb.at<Vec3b>(y, x)[1];
            img_mmap.at<Vec3b>(i, j)[2] = img_rgb.at<Vec3b>(y, x)[2];

            Color_depth[y][x] = depthValue;
        }
        fscanf(fp_dp, "\n");
    }
    fclose(fp_dp);
    imwrite(ir_name, img_mmap);

如您所见,我想要获取彩色图像的深度数据。但是当我使用这种方法时。我刚得到 512x424 单位的数据。不是 1920x1080。

所以当我已经获得两个相机的内部参数和它们之间的外部参数时,无论如何我可以知道每个颜色(rgb)图像的像素匹配哪个深度(ir)图像的像素?

使用MapColorFrameToDepthSpace.

备注:

Allocate the depthSpacePoints array before calling this method. It should have the same number of elements as the color frame has pixels (1920px by 1080px). Each entry in the filled depthSpacePoints array contains the depth point to which the corresponding pixel belongs.