当前位置: 首页 > news >正文

在Ubuntu24.04中配置开源直线特征提取软件DeepLSD

在Ubuntu24.04中配置开源直线特征提取软件DeepLSD

本文提供在Ubuntu24.04中配置开源直线特征提取软件DeepLSD的基础环境配置、列出需要修改的文件内容,以及报错解决方案集锦。

基础的编译安装环境

  • python3.8.12
  • CUDA12
  • gcc/g++ 9.5(系统自带的g++-13版本太新,会产生额外编译错误)

切换系统默认的gcc/g++版本

Ubuntu24中可以使用update-alternatives命令指定系统当前的gcc/g++版本,命令如下:

sudo apt-get install gcc-9 g++-9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 13
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 13
sudo update-alternatives --config gcc
sudo update-alternatives --config g++

上述命令首先安装gcc-9 g+±9,然后利用--install参数将系统中的两个版本的gcc/g++各自标记为"9"/“13”,最后利用--config选择gcc/g++ 9为默认版本。

安装glog、gflags

DeepLSD全功能中用到了glog和gflags两个库,使用如下命令安装:

sudo apt-get install libgoogle-glog-dev libgflags-dev

编译ceres

ceres solver除了依赖glog和gflags之外,还依赖ATLAS(BLAS和LAPACK)、Eigen和SuiteSparse
因此为编译ceres,还需要运行以下命令安装这些依赖:

sudo apt-get install libatlas-base-dev
sudo apt-get install libeigen3-dev
sudo apt-get install libsuitesparse-dev

后续安装命令:

wget -O ceres-solver-2.2.0.tar.gz http://ceres-solver.org/ceres-solver-2.2.0.tar.gz
tar zxf ceres-solver-2.2.0.tar.gz
mkdir ceres-bin
cd ceres-bin
cmake ../ceres-solver-2.2.0
make -j3
make test
sudo make install

编译OpenCV-Contrib

依赖OpenCV的线提取模块,因此需要编译OpenCV和Contrib。

否则将报错:

DeepLSD/third_party/pytlbd/src/LineBandDescriptor.cpp:9:10: fatal error: opencv2/line_descriptor.hpp: No such file or directory
9 | #include <opencv2/line_descriptor.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [CMakeFiles/tlbd.dir/build.make:79: CMakeFiles/tlbd.dir/src/LineBandDescriptor.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:185: CMakeFiles/tlbd.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2

以opencv4.11.0版本为例,编译命令为:

wget -O https://github.com/opencv/opencv/archive/refs/tags/4.11.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.11.0.zip
unzip opencv_contrib.zip
mkdir opencv_build
cd opencv_build/
conda activate DeepLSD
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.11.0/modules ../opencv-4.11.0
make
sudo make install

源码修改

解决报错:error: ‘unordered_map’ in namespace ‘std’ does not name a template type

修改以下两个文件:

  • flann_neighborhood_graph.h
  • neighborhood_graph.h

在这两个文件的开头包含<unordered_map>

解决报错:error: ‘clamp’ is not a member of ‘std’

在VSCode中搜索包含std::clamp的文件。在所有调用std::clamp的文件开头加上包含语句#include <algorithm>。需要修改的文件包括(可能也不限于):

DeepLSD/third_party/progressive-x/examples/cpp_example.cpp
DeepLSD/third_party/progressive-x/graph-cut-ransac/src/pygcransac/include/GCRANSAC.h
DeepLSD/third_party/progressive-x/graph-cut-ransac/src/pygcransac/include/estimators/essential_estimator.h
DeepLSD/third_party/progressive-x/graph-cut-ransac/src/pygcransac/include/estimators/estimator.h
DeepLSD/third_party/progressive-x/graph-cut-ransac/src/pygcransac/include/estimators/fundamental_estimator.h
DeepLSD/third_party/progressive-x/graph-cut-ransac/src/pygcransac/include/estimators/perspective_n_point_estimator.h
DeepLSD/third_party/progressive-x/graph-cut-ransac/src/pygcransac/include/estimators/solver_p3p.h

除此之外,还要修改.cmake文件的配置使用c++17标准编译,详见下节。

更改cmake配置

将以下两个文件:
DeepLSD/third_party/progressive-x/lib/pybind11/tools/pybind11Tools.cmake
DeepLSD/third_party/progressive-x/graph-cut-ransac/lib/pybind11/tools/pybind11Tools.cmake

关于设置PYBIND11的c++语言标准部分改为:

function(select_cxx_standard)if(NOT MSVC AND NOT PYBIND11_CPP_STANDARD)check_cxx_compiler_flag("-std=c++17" HAS_CPP17_FLAG)check_cxx_compiler_flag("-std=c++11" HAS_CPP11_FLAG)if (HAS_CPP17_FLAG)set(PYBIND11_CPP_STANDARD -std=c++17)elseif (HAS_CPP11_FLAG)set(PYBIND11_CPP_STANDARD -std=c++11)else()message(FATAL_ERROR "Unsupported compiler -- pybind11 requires C++11 support!")endif()set(PYBIND11_CPP_STANDARD ${PYBIND11_CPP_STANDARD} CACHE STRING"C++ standard flag, e.g. -std=c++11 or -std=c++14. Defaults to latest available." FORCE)endif()

删除CMakeCache.txt,重新运行bash install.sh,即可。

CMake最低版本更改

在VSCode中打开DeepLSD文件夹,搜索如下的表达式(正则):

将cmake_minimum_required(VERSION 2.*)或cmake_minimum_required(VERSION 2.8.12)
改为
cmake_minimum_required(VERSION 3.11)

将3.x版本都改为3.11:
搜索:cmake_minimum_required(VERSION 3.[0-5])
替换为:cmake_minimum_required(VERSION 3.11)

报错解决集锦

忽略 /opt/anaconda3 目录及其子目录

Anaconda3中存在一些库如glog/gflags甚至gdal等,可能在cmake配置过程中被当作最高优先级的链接目标,而这是不对的。因此,如果出现链接错误“GLIBCXX_3.4.30”类似的错误:

libopencv_core : undefined reference to std::condition_variable::wait(std::unique_lockstd::mutex&)@GLIBCXX_3.4.30’
std::condition_variable::wait(std::unique_lockstd::mutex&)@GLIBCXX_3.4.30’

则考虑在报错的项目的CMakeLists.txt中添加下面的语句以忽略Anaconda的库目录:

list(APPEND CMAKE_IGNORE_PATH "/opt/anaconda3")

fatal error: arlsmat.h: 没有那个文件或目录 #include <arlsmat.h>

sudo apt install libarpack*

OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root.

一般由于没有安装CUDA导致。运行以下命令安装CUDA:

wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda

python38/bin/…/lib/libstdc++.so.6: version `GLIBCXX_3.4.30’ not found

编译完成后在运行时可能会产生此错误。DeepLSD编译链接时所使用的是系统的libstdc++.so.6,而python运行时加载了Anaconda自带的libstdc++.so.6,其版本比系统的libstdc++.so.6旧,所以找不到符号。

首先,运行下面命令确定系统的libstdc++.so.6具有GLIBCXX_3.4.30版本:

strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX

如果命令行的输出有此版本,则删除python38/bin/…/lib/libstdc++.so.6,并创建符号链接:

rm  ~/miniconda3/envs/python38/lib/libstdc++.so.6
ln -sf  /usr/lib/x86_64-linux-gnu/libstdc++.so.6 ~/miniconda3/envs/python38/lib/libstdc++.so.6

相关文章:

  • Kubernetes排错(十七) :kubelet日志报device or resource busy
  • IIS服务器URL重写配置完整教程
  • Spark 集群配置、启动与监控指南
  • 榕壹云打车系统:基于Spring Boot+MySQL+UniApp的开源网约车解决方案
  • DAX权威指南2:CALCULATE 与 CALCULATETABLE
  • 【Linux笔记】——进程信号的捕捉——从中断聊聊OS是怎么“活起来”的
  • Jmeter变量传递介绍
  • 【Java面试题】——this 和 super 的区别
  • Jmeter对服务端进行压测快速上手
  • 使用IDEA创建Maven版本的web项目以及lombok的使用
  • PyTorch 中神经网络相关要点(损失函数,学习率)及优化方法总结
  • Jmeter -- JDBC驱动连接数据库超详细指南
  • VS打印printf、cout或者Qt的qDebug等传出的打印信息
  • 微服务调试问题总结
  • OpenHarmony 开源鸿蒙南向开发——linux下使用make交叉编译第三方库——wget
  • SPL做量化--DMA(平均差分析指标)
  • 嵌入式Linux Qt开发:2、Qt creator简单配置、Qt Designer使用以及信号槽机制使用
  • 进阶数据结构: AVL树
  • LeetCode 热题 100 114. 二叉树展开为链表
  • 【C++】map和set的模拟实现
  • 万科再获深铁集团借款,今年已累计获股东借款近120亿元
  • 法学联合书单|法庭上的妇女
  • 加拿大总理宣布新内阁名单
  • 耗资10亿潮汕豪宅“英之园”将强拆?区政府:非法占用集体土地
  • 首映|奥斯卡最佳国际影片《我仍在此》即将公映
  • 马上评丨摆摊要交芙蓉王?对吃拿卡要必须零容忍