在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++版本,命令如下:

bash 复制代码
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两个库,使用如下命令安装:

bash 复制代码
sudo apt-get install libgoogle-glog-dev libgflags-dev

编译ceres

ceres solver除了依赖glog和gflags之外,还依赖ATLAS(BLAS和LAPACK)、Eigen和SuiteSparse

因此为编译ceres,还需要运行以下命令安装这些依赖:

bash 复制代码
sudo apt-get install libatlas-base-dev
sudo apt-get install libeigen3-dev
sudo apt-get install libsuitesparse-dev

后续安装命令:

bash 复制代码
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版本为例,编译命令为:

bash 复制代码
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++语言标准部分改为:

cmake 复制代码
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的库目录:

cmake 复制代码
list(APPEND CMAKE_IGNORE_PATH "/opt/anaconda3")

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

bash 复制代码
sudo apt install libarpack*

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

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

bash 复制代码
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版本:

bash 复制代码
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX

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

bash 复制代码
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
相关推荐
陈苏同学18 分钟前
[已解决] VS Code / Cursor / Trae 的 PowerShell 终端 conda activate 进不去环境的常见问题
linux·windows·conda
我不是秃头sheep25 分钟前
Ubuntu 安装 Docker(镜像加速)完整教程
linux·ubuntu·docker
靡樊37 分钟前
网络基础概念
linux·服务器·网络·c++·学习
Kusunoki_D1 小时前
速查 Linux 常用指令 II
linux·运维·服务器
xmweisi022 小时前
Ansible内置模块之 group
linux·运维·ansible·rhce·rhca·红帽认证
小猪写代码2 小时前
Ubuntu 系统默认已安装 python,此处只需添加一个超链接即可
linux·python·ubuntu
孤寂大仙v2 小时前
【Linux笔记】——Linux线程理解与分页存储的奥秘
linux·运维·笔记
有谁看见我的剑了?3 小时前
ubuntu 22.04 wifi网卡配置地址上网
linux·运维·ubuntu
码农新猿类3 小时前
Ubuntu摄像头打开失败
linux·运维·ubuntu
PWRJOY4 小时前
Ubuntu磁盘空间分析:du命令及常用组合
linux·运维·ubuntu