txt以及pcd格式的点云文件在linux系统上如何查看

本文介绍了如何利用CloudCompare工具高效地可视化点云数据,并解决在Ubuntu系统中遇到的显示和文件格式问题。此外,还提供了一个用于将.pcd点云文件转换为.txt的C++程序,以及相应的CMakeLists.txt配置。通过这个程序,用户可以轻松地在不同格式之间转换点云数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

介绍一个特别好用的工具来可视化点云文件

cloudcompare

比用代码或者matlab来可视化真的方便太多

直接打开终端输入

sudo snap install cloudcompare

安装完毕后,打开

cloudcompare.ccViewer

或者

cloudcompare.CloudCompare

如果报错

  1. 第一种错误

QXcbConnection: Could not connect to display :0 Aborted (core dumped)

则需要安装

sudo snap install meshlab

2. 第二种错误
Error occurred while loading pcd file [Load] Can't guess file format: unhandled file extension'pcd'

解决,The stable version of CC can not open pcd file.

Switch it to edge version by

sudo snap refresh --edge cloudcompare

但是这种方法有个问题
NOTE: Edge verstion dosen’t stable when saving .pcd files

所以我们用下面的解决方法

git clone --recursive https://github.com/cloudcompare/trunk.git
cd trunk
mkdir build
cd build
cmake ..
make -j4
sudo make install

Launch

./qCC/CloudCompare

如何将pcd转换成txt文件
pcd2txt.cpp

#include <string>
#include <iostream>
#include <fstream>

#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>

#include <Eigen/Geometry>
#include <Eigen/Core>

void pcd2txt(pcl::PointCloud<pcl::PointXYZI>::Ptr pcdPtr)
{
    /*------------------ output pointcloud xyz as txt ----------------*/
    /*----------------------------------------------------------------*/
    std::ofstream xyz_txt("/home/gordon/feelEnvironment/data/segByCloudCompare/raw_pointcloud/pointcloud_xyz.txt", std::ios::out); 
    for(int i = 0; i < pcdPtr->points.size(); i++)
    {
        xyz_txt << std::fixed << std::setprecision(6) << pcdPtr->points[i].x << ' ' << pcdPtr->points[i].y << ' ' << pcdPtr->points[i].z << std::endl;
    }
    xyz_txt.close();
}


void txt2pcd(pcl::PointCloud<pcl::PointXYZ>::Ptr pcdPtr){
    std::ifstream fin("/home/gordon/feelEnvironment/data/segByCloudCompare/ganjian.txt", std::ios::in);
    int row;
    fin >> row;
    std::cout << "row size = " << row << std::endl;
    
    double temp;
    pcl::PointXYZ point;
    for(int i = 0; i < row; i++){
        fin >> temp;
        point.x = temp;
        
        fin >> temp;
        point.y = temp;
        
        fin >> temp;
        point.z = temp;
        
        pcdPtr->points.push_back(point);
    }
    
    if(row == pcdPtr->size())
        std::cout << "Success!" << std::endl;
    
}

int main (int argc, char** argv)
{
//     pcd to txt
    pcl::PCDReader reader;
    pcl::PointCloud<pcl::PointXYZI>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZI>);
    
    std::string fileLocation = "/home/gordon/feelEnvironment/data/segByCloudCompare/raw_pointcloud/1574588098460847.pcd";
    reader.read(fileLocation,*cloud);
    
    std::cout << "ori_pointcloud size = "<< cloud->points.size() << std::endl;
    std::cout << "width = " << cloud->width << "; height = " << cloud->height << std::endl;
    std::cout << "sensor origin : " << cloud->sensor_origin_ << std::endl;
    std::cout << "sensor orientation : " << cloud->sensor_orientation_.coeffs() << std::endl;
    
    pcd2txt(cloud);


    // txt to pcd
    // pcl::PCDWriter writer;
    
    // pcl::PointCloud<pcl::PointXYZ>::Ptr segCloud(new pcl::PointCloud<pcl::PointXYZ>);
    // txt2pcd(segCloud);
    // segCloud->width = segCloud->size();
    // segCloud->height = 1;
    
    // writer.write("/home/gordon/feelEnvironment/data/segByCloudCompare/xyz.pcd", *segCloud);
    

    return 0;
}

The CMakeLists.txt looks like this

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(pcd2txt)

find_package(PCL 1.5 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable(pcd2txt pcd2txt.cpp)
target_link_libraries (pcd2txt ${PCL_LIBRARIES})

NOTE: When saving .txt make sure to check number of points (seperate line)

**References:

[1] CloudCompare - Open Source project [2] Ubuntu18.04 cloudcompare安装 - 写东西仪式感极强(其实拖延症晚期晚期)的大龄小白 [3] ubuntu - QxcbConnection error - CloudCompare won’t launch - Stack Overflow [4] Still cannot open PCD files on Linux · Issue #536 · CloudCompare/CloudCompare · GitHub [5 经过CloudCompare保存的点云视点改变导致的问题_旅行在明天之前昨天之后的博客-优快云博客**

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Laney_Midory

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值