c++ - 使用 block 匹配算法获取纹理点云

标签 c++ opencv stereo-3d stereoscopy disparity-mapping

我想用两个图像的原始图像颜色对生成的点云进行纹理处理。为此,我用 block 匹配计算了视差图并进行了重建。为 .ply-files 编写导出函数也没什么大不了的。 我的问题是:如何从 block 匹配算法中获取颜色?它确实在校正后的图像上寻找相似像素,但是没有变量保存找到的匹配位置,引用应用程序接口(interface)。之后无法恢复颜色。

StereoBM sbm;
sbm(left_rectfied_image, right_rectified_image, disparity, CV_32F);

(我正在使用 OpenCV 2.4.8)

最佳答案

是!您正在计算的视差图是针对校正左图像的!您可以简单地为 3D 中的所有点使用左图像像素 XY 坐标值。例如

reprojectImageTo3D(disp_32, xyz, Q, true);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>); 
const double max_z = 1.0e4;

for (int Row = 0; Row < xyz.rows; Row++)
{
    for (int Col = 0; Col < xyz.cols; Col++)
    {
        pcl::PointXYZRGB point;
        vec3b Pix;
        //Just taking the Z Axis alone
        Vec3f Depth= xyz.at<Vec3f>(Row,Col);
        point.x = Depth[0];
        point.y = Depth[1];
        point.z = Depth[2];

        if(fabs(Depth[2] - max_z) < FLT_EPSILON || fabs(Depth[2]) > max_z|| Depth[2] > 0) 
            continue;

        Pix= mCamFrame_Left.at<vec3b>(Row,Col);

        uint32_t rgb = (static_cast<uint32_t>(Pix.val[0]) << 16 |static_cast<uint32_t>(Pix.val[1]) << 8 | static_cast<uint32_t>(Pix.val[2]));
        point.rgb = *reinterpret_cast<float*>(&rgb);
        point_cloud_ptr->points.push_back (point);
    }
}
point_cloud_ptr->width = (int) point_cloud_ptr->points.size();
point_cloud_ptr->height = 1;

关于c++ - 使用 block 匹配算法获取纹理点云,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33668659/

相关文章:

c++ - cout不是std的成员,其他关于c++的问题

python - 如何使用Opencv缩小/扩大面部特征?

opencv - cvReprojectImageTo3D - 从 2d 图像问题进行 3d 建模-

opencv - 在给定R和T的情况下,立体整流能否始终成功

C++ Visual Studio : Uninitialized local variable 'response' used

c++ - 删除引用调用 vector 的重复项

opencv - 如何在 ubuntu 12.04 中安装 OpenCV

c++ - 使用不同样本多次调用 OpenCV trainEM 函数

opencv - 整改摄像头未使用一行代码

c++ - 为什么我不能在信号上启动QThread?