zoukankan      html  css  js  c++  java
  • Qt Load and Save PCL/PLY 加载和保存点云

    Qt可以跟VTK和PCL等其他库联合使用,十分强大,下面的代码展示了如何使用Qt联合PCL库来加载和保存PCL/PLY格式的点云:

    通过按钮加载点云:

    void QMainWindow::on_pb_load_clicked() {
        QString filename = QFileDialog::getOpenFileName (this, tr ("Open point cloud"), "", tr ("Point cloud data (*.pcd *.ply)"));
    
        PCL_INFO("File chosen: %s
    ", filename.toStdString ().c_str ());
        PointCloudT::Ptr cloud_tmp (new PointCloudT);
    
        if (filename.isEmpty ())
            return;
    
        int return_status;
        if (filename.endsWith (".pcd", Qt::CaseInsensitive))
            return_status = pcl::io::loadPCDFile (filename.toStdString (), *cloud_tmp);
        else
            return_status = pcl::io::loadPLYFile (filename.toStdString (), *cloud_tmp);
    
        if (return_status != 0)
        {
            PCL_ERROR("Error reading point cloud %s
    ", filename.toStdString ().c_str ());
            return;
        }
    }

    保存点云:

    void QMainWindow::on_pb_save_clicked() {
        QString filename = QFileDialog::getSaveFileName(this, tr ("Open point cloud"), "", tr ("Point cloud data (*.pcd *.ply)"));
    
        PCL_INFO("File chosen: %s
    ", filename.toStdString ().c_str ());
    
        if (filename.isEmpty ())
            return;
    
        int return_status;
        if (filename.endsWith (".pcd", Qt::CaseInsensitive))
            return_status = pcl::io::savePCDFileBinary (filename.toStdString (), *cloud_);
        else if (filename.endsWith (".ply", Qt::CaseInsensitive))
            return_status = pcl::io::savePLYFileBinary (filename.toStdString (), *cloud_);
        else
        {
            filename.append(".ply");
            return_status = pcl::io::savePLYFileBinary (filename.toStdString (), *cloud_);
        }
    
        if (return_status != 0)
        {
            PCL_ERROR("Error writing point cloud %s
    ", filename.toStdString ().c_str ());
            return;
        }
    }

    注意savePCDFileBinary是以二进制的方式来储存,这样保存出来的点云占的硬盘空间较小,但是使用例如notepad++等软件打开ply文件,无法真长显示数据。我们也可以使用savePLYFileASCII来以ascii码形式来保存点云,这样我们即使使用文本文件打开,也能显示数据了。

  • 相关阅读:
    python yield from (一)
    python yield: send, close, throw
    python I/O多路复用 使用http完成http请求
    python I/O复用
    python 进程间通信
    mac 使用express -e ./
    Object.keys使用整理
    MacBook pro管理员变成普通用户无法解锁问题
    MAC应用无法打开或文件损坏的处理方法
    Redis "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk"问题的解决
  • 原文地址:https://www.cnblogs.com/grandyang/p/5562736.html
Copyright © 2011-2022 走看看