PCL:将两组点合并到一个云中并使用PCL cloudviewer进行可视化

时间:2018-09-18 19:11:49

标签: visualization point-cloud-library

我试图将来自两个不同视图的两组点合并到一个点云中,并使用PCL云查看器将其可视化。

    mPtrPointCloud->points.clear();
    mPtrPointCloud->points.resize(mFrameSize * 2);
    auto it = mPtrPointCloud->points.begin();
    received = PopReceived();
    if(received != nullptr)
    {
        // p_data_cloud = (float*)received->mTransformedPC.data;
        p_data_cloud = (float*)received->mCVPointCloud.data;
        index = 0;
        for (size_t i = 0; i < mFrameSize; ++i) 
        {
            float X = p_data_cloud[index];
            if (!isValidMeasure(X)) // Checking if it's a valid point
            {
                it->x = it->y = it->z = it->rgb = 0;
            }
            else 
            {
                it->x = X;
                it->y = p_data_cloud[index + 1];
                it->z = p_data_cloud[index + 2];
                it->rgb = convertColor(p_data_cloud[index + 3]); // Convert a 32bits float into a pcl .rgb format
            }
            index += 4;
            ++it;
        }
    }

    frame = PopFrame();
    if(frame != nullptr)
    {
        // p_data_cloud = frame->mSLPointCloud.getPtr<float>();
        p_data_cloud = (float*)frame->mCVPointCloud.data;
        index = 0;

        for (size_t i = 0; i < mFrameSize; ++i) 
        {
            float X = p_data_cloud[index];
            if (!isValidMeasure(X)) // Checking if it's a valid point
            {
                it->x = it->y = it->z = it->rgb = 0;
            }
            else 
            {
                it->x = X;
                it->y = p_data_cloud[index + 1];
                it->z = p_data_cloud[index + 2];
                it->rgb = convertColor(p_data_cloud[index + 3]); // Convert a 32bits float into a pcl .rgb format
            }
                index += 4;
                ++it;
            }
        }
mPtrPCViewer->showCloud(mPtrPointCloud);

我想要的是将两组点“融合”到一帧。但是,似乎这两套点仍在一个接一个地显示。

有人可以帮助解释如何将两组点真正合并到一个云中吗?谢谢

1 个答案:

答案 0 :(得分:0)

(1)创建一个新的空点云,最后将其合并为点云

pcl::PointCloud<pcl::PointXYZ>  mPtrPointCloud;

(2)将点云转换为原点

pcl::PointCloud<pcl::PointXYZ> recieved_transformed;
Eigen::Transform<Scalar, 3, Eigen::Affine> recieved_transformation_mat(recieved.sensor_origin_ * recieved.sensor_orientation_);
pcl::transformPointCloud(recieved, recieved_transformed, recieved_transformation_mat);

pcl::PointCloud<pcl::PointXYZ> frame_transformed;
Eigen::Transform<Scalar, 3, Eigen::Affine> frame_transformation_mat(frame.sensor_origin_ * frame.sensor_orientation_);
pcl::transformPointCloud(frame, frame_transformed, frame_transformation_mat);

(3)使用+​​ =运算符

mPtrPointCloud += received_transformed;
mPtrPointCloud += frame_transformed;

(4)可视化合并的点云

mPtrPCViewer->showCloud(mPtrPointCloud);

就是这样。另请参见示例http://pointclouds.org/documentation/tutorials/concatenate_clouds.php http://pointclouds.org/documentation/tutorials/matrix_transform.php