写在前面
-
本文内容
以PCL 1.14.0,Open3D0.14.1为例,对基于PCL、Open3D开发的代码进行源码debug;
如何学习、上手点云算法系列:
如何学习、上手点云算法(一):点云基础
如何学习、上手点云算法(二):点云处理相关开源算法库、软件、工具
如何学习、上手点云算法(三):用VsCode、Visual Studio来debug基于PCL、Open3D的代码
更多点云基础、算法相关内容请关注专栏:
点云处理基础
点云配准(PointCloud Registration)
Open3D点云处理
PCL点云处理
点云算法 -
平台/环境
Windows10, CMake, Open3D, PCL -
转载请注明出处:
https://blog.csdn.net/qq_41102371/article/details/136504094
目录
- 写在前面
- PCL
- 准备
- 编译debug版本
- 配置launch.json
- Visual Studio
- Open3D
- 准备
- 添加open3d测试
- 调试
- 参考
- 完
PCL
准备
安装PCL1.14.0: PCL1.14.0安装、使用教程
VsCode配置PCL: VsCode配置PCL、Open3D自动补全
在此基础上,下载debug需要的pdb文件:https://github.com/PointCloudLibrary/pcl/releases
打开压缩包
将pdb文件复制到之前装PCL的bin路径下,我这里是
D:\carlos\install\PCL 1.14.0\bin
注:PDB文件的作用见vs2019配置opencv+contrib-440 + PCL1.10.0 + 源码单步调试
编译debug版本
在VsCode配置PCL、Open3D自动补全和的基础上,新建一个compile_debug.bat:
cmake -DCMAKE_BUILD_TYPE=Debug ^
-DPCL_DIR="D:/carlos/install/PCL 1.14.0/cmake" ^
-S ./ -B ./build_debugcmake --build ./build_debug --config Debug --target ALL_BUILD
然后使用compile_debug.bat进行编译,完了会自动生成build_debug
配置launch.json
创建launch
添加配置
修改配置
"program"就是我们debug的程序对象,"environment"就是为当前程序添加PCL的环境变量,让其能找到PCL、VTK、FLANN等的动态库(.dll)
示例:
{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "(Windows) Launch","type": "cppvsdbg","request": "launch","program": "${workspaceFolder}/build_debug/Debug/statistical_removal.exe","args": [],"stopAtEntry": false,"cwd": "${fileDirname}","environment": [{"name": "PATH","value": "D:/carlos/install/PCL 1.14.0/bin;D:/carlos/install/PCL 1.14.0/3rdParty/FLANN/bin;D:/carlos/install/PCL 1.14.0/3rdParty/VTK/bin;D:/carlos/install/PCL 1.14.0/3rdParty/Qhull/bin;D:/carlos/install/PCL 1.14.0/3rdParty/OpenNI2/Tools;$(PATH)"}],"console": "externalTerminal"}]
}
在statistical_removal.cpp中随便加一个断点,然后使用F5或者右上角的Debug C/C++ File, 开始debug
然后就可以看到程序运行到了断点处,左侧有变量状态,自己添加监控,线程的显示
Visual Studio
打开文件夹,找到.sln文件双击打开
鼠标右键,将statistical_removal设置为启动项目
再点开最下面的属性,Debug–调试–环境–编辑,输入
PATH=;D:\carlos\install\PCL 1.14.0\bin;
D:\carlos\install\PCL 1.14.0\3rdParty\FLANN\bin;
D:\carlos\install\PCL 1.14.0\3rdParty\VTK\bin;
D:\carlos\install\PCL 1.14.0\3rdParty\Qhull\bin;
D:\carlos\install\PCL 1.14.0\3rdParty\OpenNI2\Tools;
$(PATH)
确定
Open3D
准备
Open3D没有像PCL提供Debug版的lib和对应的pdb文件,需要自己编译,在Open3D0.14.1编译、安装、demo使用教程中我们已经编译好了debug版本,现在需要去build_debug/lib/Debug中找到pdb文件
然后将pdb文件复制到install的目录中
添加open3d测试
在上面PCL示例project中,我们添加一个open3d的测试,在编译脚本中添加open3d的debug版的路径
compile_debug.bat:
cmake -DCMAKE_BUILD_TYPE=Debug ^
-DPCL_DIR="D:/carlos/install/PCL 1.14.0/cmake" ^
-DOpen3D_DIR="D:/carlos/install/open3d141_d/CMake" ^
-S ./ -B ./build_debugcmake --build ./build_debug --config Debug --target ALL_BUILD
添加一个测试代码test_open3d.cpp,该代码作用是平面拟合,并把拟合出的平面与剩下点云用不同颜色显示
#include <open3d/Open3D.h>int main()
{std::shared_ptr<open3d::geometry::PointCloud> pcd(new open3d::geometry::PointCloud);open3d::io::ReadPointCloud("./table_scene_lms400.pcd", *pcd);pcd->SegmentPlane();pcd->PaintUniformColor({1, 0, 0});open3d::visualization::DrawGeometries({pcd});return 0;
}
修改CMakeLists.txt
cmake_minimum_required(VERSION 3.18)project(statistical_removal)# PCL
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
# PCL test
add_executable(statistical_removal statistical_removal.cpp)
target_link_libraries(statistical_removal ${PCL_LIBRARIES})# Open3D
option(STATIC_WINDOWS_RUNTIME "Use static (MT/MTd) Windows runtime" ON)
if(STATIC_WINDOWS_RUNTIME)set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else()set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
find_package(Open3D REQUIRED)
include_directories(${Open3D_INCLUDE_DIRS})# Open3D test
add_executable(test_open3d test_open3d.cpp)
target_link_libraries(test_open3d ${Open3D_LIBRARIES})
然后使用compile_debug.bat进行编译
调试
修改launch.json
{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "(Windows) Launch","type": "cppvsdbg","request": "launch",// "program": "${workspaceFolder}/build_debug/Debug/statistical_removal.exe","program": "${workspaceFolder}/build_debug/Debug/test_open3d.exe","args": [],"stopAtEntry": false,"cwd": "${fileDirname}","environment": [{"name": "PATH","value": "D:/carlos/install/PCL 1.14.0/bin;D:/carlos/install/PCL 1.14.0/3rdParty/FLANN/bin;D:/carlos/install/PCL 1.14.0/3rdParty/VTK/bin;D:/carlos/install/PCL 1.14.0/3rdParty/Qhull/bin;D:/carlos/install/PCL 1.14.0/3rdParty/OpenNI2/Tools;$(PATH)"}],"console": "externalTerminal"}]
}
在源码添加断点,开始调试
平面分割结果可视化
用Visual Studio debug参照上面PCL示例,打开.sln,设置启动项
但是Open3D是静态库,所以不用设置环境变量就可以了,另外用Visual Studio调试前把代码中点云读取路径改成绝对路径再重新编译一下,不然会找不到点云
参考
https://code.visualstudio.com/docs/cpp/launch-json-reference
其余文中已列出
完
主要做激光/影像三维重建,配准、分割等常用点云算法,熟悉open3d、pcl等开源点云库,技术交流、咨询可私信