全景图像的球面映射

struct Sphere
{
    float centerX;
    float centerY;
    float centerZ;
    float radius;
};


void panoramaToSphere()
{
    Sphere sphere;
    sphere.centerX = 0.0;
    sphere.centerY = 0.0;
    sphere.centerZ = 0.0;
    sphere.radius = 2.0;

    const double PI = 3.1415926;
    cv::Mat mat = imread("R0012130_aligned_rgb.raw.png");
    //cv::Mat mat_temp(545, 1024, CV_8UC3, Scalar(255, 255, 255));

    //定义球面坐标表示的角度Sigma为点与z轴夹角[0 PI]   Theta为点在xy的投影与x轴夹角[0 2PI]。
    PointCloudT::Ptr cloud_in(new PointCloudT);  // 原始点云
    for (int row = 0; row < 545; row++) {
        for (int col = 0; col < 1024; col++) {
            Vec3b bgr = mat.at<Vec3b>(row, col);

            double Sigma_ = PI * row / 545.0;    // 0-PI
            double Theta_ = PI * col / 512.0;   //0-2PI

            PointT points;
            points.x = sin(Sigma_)*sphere.radius*cos(Theta_);
            points.y = sin(Sigma_)*sphere.radius*sin(Theta_);
            points.z = cos(Sigma_)*sphere.radius + sphere.centerZ;
            points.r = bgr[2];
            points.g = bgr[1];
            points.b = bgr[0];
            points.a = 255;
            points.rgba = (int)(255) << 24 | (int)(points.r) << 16 | (int)(points.g) << 8 | (int)(points.b);

            cloud_in->points.push_back(points);
        }
    }

    cloud_in->height = 1;
    cloud_in->width = cloud_in->points.size();
    pcl::io::savePCDFile("./cloud_in.pcd", *cloud_in);

    return;
}

效果: 

猜你喜欢

转载自www.cnblogs.com/lovebay/p/12421473.html