深度点云,迭代器错了吗?

时间:2016-10-13 08:03:23

标签: c++ point-cloud-library mat

Depth Point cloud 嗨,我正在将深度图像转换为点云,它似乎停在图像宽度的1/3处。也许我在迭代中通过坐标的东西是错误的?

    float* p = (float*)depth.data; // one option to iterate through
    int index1 = 0; // just for counting the points
    for (int y = 0; y < depthImageSize.height; ++y)
    {
        for (int x = 0; x < depthImageSize.width; ++x)
        {
            pcl::PointXYZRGBA pt;
            //float depthValue = static_cast<float>(*p);
            float depthValue = depth.at<float>(y,x);
            //cout << p.pos() << endl;
            //cout << x << ", " << y << ": " << depthValue << endl;
            //++p;
            index1++;

            if (depthValue == -1000.f || depthValue == 0.0f || boost::math::isnan(depthValue))
            {
            }
            else
            {

                pt.x = (static_cast<float>(x) - centerX) * scaleFactorX * depthValue;
                pt.y = (centerY - static_cast<float>(y)) * scaleFactorY * depthValue;
                pt.z = depthValue;

                //bgr has to be resized
                cv::resize(bgr,bgr,depth.size());
                cv::Vec3b colorValue = bgr.at<cv::Vec3b>(y, x);
                RGBValue color;
                color.Red = colorValue[2];
                color.Green = colorValue[1];
                color.Blue = colorValue[0];
                pt.rgba = color.long_value;


            }
            result->points.push_back(pt);
        }

    }

1 个答案:

答案 0 :(得分:0)

我会说它必须是

depth.at<float>(x,y)