解决PCL和OpenCV中flann库冲突的问题
做视觉处理,尤其是三维视觉和点云处理等,基本都离不开这俩大库,以前要么单独用OpenCV做二维,要么纯用PCL做点云后处理。因为准备把学习期间的代码整合起来,所以需要同时使用两个库,结果发现flann库冲突的问题🤪
查阅了一下网上的方案,基本有几种方案
- 1.建议改调用的flann头文件路径(要改全部的也太夸张了,要改用到的又不确定用到了哪些😅)
- 2.或者用不同的命名空间规避(根本没用到flann相关的函数就冲突了😕)
- 3.修改OpenCV中的flann文件夹名(相对靠谱点🤣)
方法1:修改OpenCV中的flann文件夹名
如果只打算使用PCL的flann库,可以通过修改OpenCV库中的flann文件夹名避免,但是治标不治本, 没有真正解决问题,只是解决了有问题的库 🙃
执行如下两步,进入路径,更改名称,解决!(记得备份或者以后用的时候能想起改回来😶)
cd /usr/local/opencv4/include/opencv4/opencv2
sudo mv flann/ flann2/
方法2:通过增加Cmake文件解决问题
索性直接搜索Ubuntu20.04+PCL+OpenCV
环境的配置经验,还真研究出一些规律,大部分跑起来而且不提到flann库冲突问题的博客或者文章都是增加CMakeLists.txt
文件实现的,然后就是昏天黑地的配置和试错时间😇
首先新建文件结构如下(直接把自己的放上来不是为了偷懒 ,如果有好心人可以推荐更精简或者更方便的文件结构那就太好辣🤡)文章来源:https://www.toymoban.com/news/detail-618968.html
cpp
├── .vscode
│ ├── c_cpp_properties.json
│ ├── launch.json
│ └── tasks.json
├── build
│ └── bin
│ ├── Linx
│ └── data
├── CMakeLists.txt
├── data
├── include
│ ├── func_common.h
│ ├── func_opencv.h
│ └── func_pcl.h
└── src
├── func_common.cpp
├── func_opencv.cpp
├── func_pcl.cpp
└── main.cpp
需要的文件内容如下
1. CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(Linx)
# ========================================
# === 构建静态库以加速
# ========================================
set(COMMON_SOURCES src/func_common.cpp src/func_pcl.cpp src/func_opencv.cpp)
add_library(Func STATIC ${COMMON_SOURCES})
if(UNIX)
target_link_libraries(Func pthread)
endif()
# ========================================
# === PCL库
# ========================================
find_package(PCL 1.8 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
# ========================================
# === OpenCV库
# ========================================
# 记得替换自己的路径
set(OpenCV_DIR "~/libs/opencv-4.5.3/build/")
find_package(OpenCV REQUIRED)
if (NOT OpenCV_FOUND)
message(FATAL_ERROR "OpenCV library not found")
else()
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(${OpenCV2_INCLUDE_DIRS})
link_directories(${OpenCV_LIB_DIR})
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build/bin)
aux_source_directory(./src/ DIR_SRCS)
add_executable(Linx ${DIR_SRCS})
set_target_properties(Linx PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(Linx
${ABSOLUTE_TARGET_LIB} ${PCL_LIBRARIES} libpthread.so ${OpenCV_LIBS} Func ${CLOUD_VIEWER}
)
2. .vscode/c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include",
"/usr/include/**",
"/usr/include/x86_64-linux-gnu/sys",
// 检查pcl路径
"/usr/include/pcl-1.10",
"/usr/include/eigen3",
"/usr/include/eigen3/Eigen/",
"/usr/include/vtk-7.1",
"/usr/include/qhull",
"/usr/include/flann",
"/usr/include/boost",
// 检查opencv路径
"/usr/local/opencv4/include/opencv4"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
3. .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/bin/Linx",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Build",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
4. .vscode/tasks.json
{
"version": "2.0.0",
"options": {
"cwd": "${workspaceFolder}/build"
},
"tasks": [
{
"type": "shell",
"label": "cmake",
"command": "cmake",
"args": [
".."
]
},
{
"label": "make",
"group": {
"kind": "build",
"isDefault": true
},
"command": "make",
"args": [
]
},
{
"label": "Build",
"dependsOrder": "sequence", // 按列出的顺序执行任务依赖项
"dependsOn":[
"cmake",
"make"
]
}
]
}
配置好以上文件之后,就又可以愉快的写BUG啦!(不是 ) 😑文章来源地址https://www.toymoban.com/news/detail-618968.html
到了这里,关于解决PCL和OpenCV中flann库冲突的问题(Ubuntu20.04+VSCode)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!