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

[复制链接]
发表于 2025-8-18 23:04:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
在Ubuntu24.04中设置开源直线特性提取软件DeepLSD

本文提供在Ubuntu24.04中设置开源直线特性提取软件DeepLSD的底子情况设置、列出需要修改的文件内容,以及报错解决方案集锦。
底子的编译安装情况


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

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

Ubuntu24中可以使用update-alternatives下令指定体系当前的gcc/g++版本,下令如下:
  1. sudo apt-get install gcc-9 g++-9
  2. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9
  3. sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9
  4. sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 13
  5. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 13
  6. sudo update-alternatives --config gcc
  7. sudo update-alternatives --config g++
复制代码
上述下令起首安装gcc-9 g+±9,然后利用--install参数将体系中的两个版本的gcc/g++各自标记为"9"/“13”,最后利用--config选择gcc/g++ 9为默认版本。
安装glog、gflags

DeepLSD全功能中用到了glog和gflags两个库,使用如下下令安装:
  1. sudo apt-get install libgoogle-glog-dev libgflags-dev
复制代码
编译ceres

ceres solver除了依赖glog和gflags之外,还依赖ATLAS(BLAS和LAPACK)、Eigen和SuiteSparse
因此为编译ceres,还需要运行以下下令安装这些依赖:
  1. sudo apt-get install libatlas-base-dev
  2. sudo apt-get install libeigen3-dev
  3. sudo apt-get install libsuitesparse-dev
复制代码
后续安装下令:
  1. wget -O ceres-solver-2.2.0.tar.gz http://ceres-solver.org/ceres-solver-2.2.0.tar.gz
  2. tar zxf ceres-solver-2.2.0.tar.gz
  3. mkdir ceres-bin
  4. cd ceres-bin
  5. cmake ../ceres-solver-2.2.0
  6. make -j3
  7. make test
  8. 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版本为例,编译下令为:
  1. wget -O https://github.com/opencv/opencv/archive/refs/tags/4.11.0.zip
  2. wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.11.0.zip
  3. unzip opencv_contrib.zip
  4. mkdir opencv_build
  5. cd opencv_build/
  6. conda activate DeepLSD
  7. cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.11.0/modules ../opencv-4.11.0
  8. make
  9. 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>。需要修改的文件包罗(大概也不限于):
  1. DeepLSD/third_party/progressive-x/examples/cpp_example.cpp
  2. DeepLSD/third_party/progressive-x/graph-cut-ransac/src/pygcransac/include/GCRANSAC.h
  3. DeepLSD/third_party/progressive-x/graph-cut-ransac/src/pygcransac/include/estimators/essential_estimator.h
  4. DeepLSD/third_party/progressive-x/graph-cut-ransac/src/pygcransac/include/estimators/estimator.h
  5. DeepLSD/third_party/progressive-x/graph-cut-ransac/src/pygcransac/include/estimators/fundamental_estimator.h
  6. DeepLSD/third_party/progressive-x/graph-cut-ransac/src/pygcransac/include/estimators/perspective_n_point_estimator.h
  7. 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++语言标准部门改为:
  1. function(select_cxx_standard)
  2.   if(NOT MSVC AND NOT PYBIND11_CPP_STANDARD)
  3.     check_cxx_compiler_flag("-std=c++17" HAS_CPP17_FLAG)
  4.     check_cxx_compiler_flag("-std=c++11" HAS_CPP11_FLAG)
  5.     if (HAS_CPP17_FLAG)
  6.       set(PYBIND11_CPP_STANDARD -std=c++17)
  7.     elseif (HAS_CPP11_FLAG)
  8.       set(PYBIND11_CPP_STANDARD -std=c++11)
  9.     else()
  10.       message(FATAL_ERROR "Unsupported compiler -- pybind11 requires C++11 support!")
  11.     endif()
  12.     set(PYBIND11_CPP_STANDARD ${PYBIND11_CPP_STANDARD} CACHE STRING
  13.         "C++ standard flag, e.g. -std=c++11 or -std=c++14. Defaults to latest available." FORCE)
  14.   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的库目录:
  1. list(APPEND CMAKE_IGNORE_PATH "/opt/anaconda3")
复制代码
fatal error: arlsmat.h: 没有那个文件或目录 #include <arlsmat.h>
  1. sudo apt install libarpack*
复制代码
OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root.

一般由于没有安装CUDA导致。运行以下下令安装CUDA:
  1. wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.0-1_all.deb
  2. sudo dpkg -i cuda-keyring_1.0-1_all.deb
  3. sudo apt-get update
  4. 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版本:
  1. strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX
复制代码
如果下令行的输出有此版本,则删除python38/bin/…/lib/libstdc++.so.6,并创建符号链接:
  1. rm  ~/miniconda3/envs/python38/lib/libstdc++.so.6
  2. ln -sf  /usr/lib/x86_64-linux-gnu/libstdc++.so.6 ~/miniconda3/envs/python38/lib/libstdc++.so.6
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

×
登录参与点评抽奖,加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表