编译器是:vs2022
pcl版本:1.14.1
1.第一步下载pcl最新版1.14.1,安装后,配置环境变量
2.下载PclSharp源码GitHub - jbruening/PclSharp: Point Cloud Library pinvoke binding for c#,找到src文件夹下的PclSharp.Extern 这个封装c++版本的工程,最终输出pclsharp.extern.dll,这个为c++工程,原本是vs2022工程配置的,使用属性表配置跑出来,设置项目繁琐,这里改为cmake来配置;PclSharp.Extern.Vis这个可视化部分比较简单,也和PclSharp.Extern合并了。
cmake_minimum_required(VERSION 3.0)
project(PclSharp.Extern)
find_package(PCL REQUIRED )
set(CMAKE_BUILD_TYPE Release)
include_directories(${PCL_INCLUDE_DIRS})
include_directories("D:/Program Files/PCL 1.14.1/3rdParty/FLANN/include")
message(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
file(GLOB POINTCLOUD_SRC ./pointcloud/*.cpp)
file(GLOB SAMPLECONSENSUS_SRC ./sampleconsensus/*.cpp)
file(GLOB STD_SRC ./std/*.cpp)
file(GLOB REGISTRATION_SRC ./registration/*.cpp)
file(GLOB SEGMENTATION_SRC ./segmentation/*.cpp)
add_library( PclSharp.Extern SHARED PointSizes.cpp visualizer.cpp
"common/ModelCoefficients.generated.cpp"
"common/PCAOfXYZ.generated.cpp" "common/PclBaseOfXYZ.generated.cpp"
common/PclBaseOfXYZRGBA.generated.cpp
common/PointIndices.generated.cpp
filters/ExtractIndicesXYZ.generated.cpp
filters/Heightmap2DOfXYZ.generated.cpp
filters/StatisticalOutlierRemovalOfXYZ.generated.cpp
filters/VoxelGridOfXYZ.generated.cpp
${POINTCLOUD_SRC}
${SAMPLECONSENSUS_SRC}
${STD_SRC}
${REGISTRATION_SRC}
${SEGMENTATION_SRC}
search/KdTreeOfXYZ.generated.cpp
search/OrganizedNeighborOfXYZ.generated.cpp
features/FPFHEstimationOfPointXYZAndNormal.generated.cpp
features/IntegralImageNormalEstimationOfPointXYZAndNormal.generated.cpp
io/PCDReader.generated.cpp
io/PCDWriter.generated.cpp
"eigen/Matrix4f.generated.cpp"
"eigen/VectorXf.generated.cpp"
algrithom/detectAnomaly.cpp
)
target_link_libraries(PclSharp.Extern ${PCL_LIBRARIES})
使用vscode配置更方便,如果添加自定义的pcl算法,需要编写代码,visual studio 变量提示不太方便,vscode可以配置c_cpp_properties.json文件:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:/Program Files/PCL 1.14.1/include/pcl-1.14",
"D:/Program Files/PCL 1.14.1/3rdParty/Eigen3/include/eigen3",
"D:/Program Files/PCL 1.14.1/3rdParty/Boost/include/boost-1_84",
"C:/Program Files/OpenNI2/Include",
"D:/Program Files/PCL 1.14.1/3rdParty/FLANN/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22000.0",
"compilerPath": "cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
最后生成vs工程,可以到输出目录找到sln工程文件,用vs2022打开,编译即可
其中pcl最新版智能指针已全部使用标准库std::shared_ptr这个了,所以在工程中查找boost::shared_ptr,全部替换为std::shared_ptr
3.编译pclsharp这个csharp工程
4.测试csharp调用
5.高级部分:如何封装自己的算法,并实现调用?
有的是直接想在csharp上开发pcl算法,但存在一定的弊端:(1)源代码得不到保护 (2)托管内存释放存在延时,对程序性能有一定影响
所以最好的方式是使用c++ 进行开发,csharp只负责上位机调用即可。
代码下载地址,包含所有源代码和可以执行的文件