pcl vscode
时间: 2025-01-12 17:40:54 浏览: 33
配置和使用 PCL 点云库
安装依赖项
为了在 Ubuntu 上成功配置 PCL 库,在 VSCode 中开发 C++ 或 Python 项目前,需确保已安装必要的依赖包。对于基于 Linux 的操作系统如 Ubuntu18.04,可以利用 apt-get 来简化这一过程[^1]。
sudo apt-get update
sudo apt-get install build-essential cmake git pkg-config
sudo apt-get install libusb-1.0-0-dev libudev-dev
下载并构建 PCL
获取最新版本的 PCL 源代码可以通过 Git 克隆仓库完成;而对于特定版本比如 PCL 1.9,则可以从 GitHub 发布页面下载压缩包或者通过其他途径获得预编译二进制文件[^2]。
如果选择源码编译方式:
git clone https://github.com/PointCloudLibrary/pcl.git
cd pcl
mkdir build && cd build
cmake ..
make -j$(nproc)
sudo make install
设置 VSCode 开发环境
VSCode 是一款轻量级编辑器,支持多种编程语言插件扩展。针对 C/C++ 和 PCL 使用场景,推荐安装 Microsoft 提供的官方 C/C++ 扩展以及 CMake Tools 插件来辅助管理项目结构与构建流程。
创建 .vscode
文件夹用于存放 IDE 特定设置文件,包括但不限于 c_cpp_properties.json
, launch.json
, tasks.json
及 CMakeLists.txt
.
c_cpp_properties.json 示例
此 JSON 文件定义了 IntelliSense 对于 C/C++ 项目的理解上下文,特别是包含路径、宏定义等内容。
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/eigen3",
"/usr/local/include/pcl-1.9"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
launch.json 示例
该文件描述调试会话参数,允许开发者指定启动目标及其选项。
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/my_program",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "cmake-build-debug",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
tasks.json 示例
这个任务配置文件指定了如何执行命令行操作,例如调用 CMake 构建解决方案。
{
"version": "2.0.0",
"tasks": [
{
"label": "cmake-build-debug",
"type": "shell",
"command": "cmake --build ./build --target all --config Debug",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$gcc"],
"detail": "Generated task from external source."
}
]
}
CMakeLists.txt 示例
这是 CMake 脚本的核心部分,用来指导工具链生成 Makefile 并控制整个工程架构。
cmake_minimum_required(VERSION 3.10)
project(PointCloudExample VERSION 1.0 LANGUAGES CXX)
find_package(PCL 1.9 REQUIRED COMPONENTS common io visualization)
add_executable(my_program main.cpp)
target_link_libraries(my_program PRIVATE ${PCL_LIBRARIES})
set_target_properties(my_program PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
install(TARGETS my_program DESTINATION bin)
编写测试程序验证安装效果
编写简单的 C++ 测试案例可以帮助确认 PCL 是否正常工作。下面是一个读取 .pcd 文件并将点云可视化的小例子。
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/cloud_viewer.h>
int main(int argc, char** argv){
if (argc != 2){
std::cerr << "Usage: " << argv[0] << " input.pcd" << std::endl;
return (-1);
}
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
if(pcl::io::loadPCDFile<pcl::PointXYZ>(argv[1], *cloud) == -1){
PCL_ERROR ("Couldn't read file\n");
return (-1);
}else{
std::cout << "Loaded "
<< cloud->width * cloud->height
<< " data points from test_pcd.pcd with the following fields: "
<< std::endl;
pcl::visualization::CloudViewer viewer("Simple Cloud Viewer");
viewer.showCloud(cloud);
while (!viewer.wasStopped()){
}
}
return 0;
}
相关推荐


















