本文介绍了使用块匹配算法获取纹理点云的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用两张图片的原始图片颜色来纹理生成的点云。为此,我用块匹配计算视差图并进行重建。还为.ply-files编写一个导出函数不是一个大问题。
我的问题是:如何从块匹配算法得到颜色它在整流图像上寻找类似的像素,但没有变量保存找到的位置匹配,参考API。之后,不可能恢复颜色。

I want to texture a generated pointcloud with the original image color from two images. For this I calculated the disparity-map with Block-Matching and did the reconstruction. Also writing an export function for .ply-files wasn't a big deal. My problem is: How do I get the color from block-matching-algorithm? It does look for similar pixels on rectified images, but there is no variable which saves the position of a found matching, referred to API. Afterward it is not possible to recover the color.

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

(我正在使用OpenCV 2.4.8)

(I am working with OpenCV 2.4.8)

推荐答案

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

Yes! The disparity map you are computing is for the Rectified Left Image! You can simply use the Left Image Pixel XY Co-Ordinate values for all the points in 3D. for e.g.

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;

这篇关于使用块匹配算法获取纹理点云的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 16:54