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

时间:2016-02-17 07:33:17

标签: kinect camera-calibration

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

现在我已经知道每个深度(红外)图像的像素匹配哪个颜色(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)图像的像素?

1 个答案:

答案 0 :(得分:1)

使用MapColorFrameToDepthSpace

注:

  

在调用此方法之前分配depthSpacePoints数组。它   应该具有与颜色框具有像素相同数量的元素   (1920px×1080px)。填充的depthSpacePoints数组中的每个条目   包含相应像素所属的深度点。