COLMAP可以作为独立的app,通过命令行或者图形交互界面使用,也可以作为一个库被包含到其他源代码中。
这里记录一下编译安装colmap的过程,首先需要安装好CUDA,CUDA具体安装过程这里就不赘述了。在GitHub上下载源代码,我这里就是下载的主干的源码:
源码下载地址:GitHub - colmap/colmap: COLMAP - Structure-from-Motion and Multi-View Stereo
源码编译说明:Installation — COLMAP 3.9-dev documentation
一、安装依赖库
sudo apt-get install \
git \
cmake \
build-essential \
libboost-program-options-dev \
libboost-filesystem-dev \
libboost-graph-dev \
libboost-system-dev \
libboost-test-dev \
libeigen3-dev \
libsuitesparse-dev \
libfreeimage-dev \
libmetis-dev \
libgoogle-glog-dev \
libgflags-dev \
libglew-dev \
qtbase5-dev \
libqt5opengl5-dev \
libcgal-dev \
libcgal-qt5-dev \
libflann-dev \
libsqlite3-dev \
libatlas-base-dev
二、安装Ceres优化库
先解压源码的压缩包,然后进入解压后的文件夹:
unzip colmap.zip
cd colmap
git clone https://ceres-solver.googlesource.com/ceres-solver
cd ceres-solver
mkdir build
cd build
cmake .. -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF
make -j
sudo make install
三、修改文件
在编译前需要修改一些文件,否则编译的时候会报错。
1.CUDA配置错误
修改源码文件夹中的Cmake文件,加一句:
set(CMAKE_CUDA_ARCHITECTURES "native")
如果不修改的话,编译时会报下面的错误:
CMake Error at cmake/FindDependencies.cmake:125 (message):
You must set CMAKE_CUDA_ARCHITECTURES to e.g. 'native', 'all-major', '70',
etc. More information at
https://cmake.org/cmake/help/latest/prop_tgt/CUDA_ARCHITECTURES.html
Call Stack (most recent call first):
CMakeLists.txt:87 (include)
2.glog相关报错
编译时报下面的错:
CMake Error at /usr/local/lib/cmake/Ceres/FindGlog.cmake:349 (add_library):
add_library cannot create imported target "glog::glog" because another
target with the same name already exists.
Call Stack (most recent call first):
/usr/local/lib/cmake/Ceres/CeresConfig.cmake:247 (find_package)
cmake/FindDependencies.cmake:33 (find_package)
CMakeLists.txt:87 (include)
修改报错提示里的/usr/local/lib/cmake/Ceres/FindGlog.cmake文件,第349行:
把红框圈起来的部分改成下面的代码(直接注释掉也无妨):
if(NOT TARGET glog::glog)
add_library(glog::glog INTERFACE IMPORTED)
target_include_directories(glog::glog INTERFACE ${GLOG_INCLUDE_DIRS})
target_link_libraries(glog::glog INTERFACE ${GLOG_LIBRARY})
endif()
四、编译colmap
cd colmap
mkdir build
cd build
cmake ..
make -j
sudo make install
编译完成后,运行起来colmap:
// 查看colmap的帮助
colmap -h
// 显示colmap的gui图形界面
colmap gui
五、在云服务器上使用colmap图形界面到本机
我使用的autodl的云服务器,在vscode上通过ssh访问云服务器,安装了colmap后,想运行colmap的gui图形界面。由于服务器并没有界面,所以想把colmap的图形界面显示到自己的电脑屏幕上,网上查试了很长时间都没弄好,最后看了autodl的官方文档终于把colmap的图形界面显示到自己电脑了,这里记录一下。
安装VNC:AutoDL帮助文档
ssh隧道:AutoDL帮助文档
按照文档执行完export DISPLAY=:1后,可以使用xclock命令查看是否已经调通了,xclock所在的软件包是x11-apps,执行下面的命令,可以看到VNC客户端中显示了一个时钟:
sudo apt-get install x11-apps
xclock
接着运行colmap显示colmap的图形界面,报了下面的错误:
(base) root@autodl-container-18e111b408-aed6fb9f:/# colmap gui
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
The X11 connection broke: No error (code 0)
XIO: fatal IO error 0 (Success) on X server ":1"
after 449 requests (449 known processed) with 0 events remaining.
解决办法: 在/etc/profile末尾增加两句
export XDG_RUNTIME_DIR=/usr/lib/
export RUNLEVEL=3
然后刷新全局变量:
source /etc/profile
再执行colmap gui,VNC客户端中可以正常显示colmap图形界面了,大功告成!