您现在的位置是:首页 >其他 >Windows上通过CMake编译COLMAP源码操作步骤网站首页其他
Windows上通过CMake编译COLMAP源码操作步骤
COLMAP源码:https://github.com/colmap/colmap ,最新的稳定版本位于master分支,最新的开发版本位于dev分支,这里使用master分支进行编译,commit id为1555ff0。官方推荐使用vs2019,使用vs2022有一些已知bugs会导致crash,这里使用vs2019.
1.安装vcpkg,依次执行如下命令:将vcpkg源码clone到C:/dev目录下
vcpkg.exe integrate install
vcpkg.exe install ceres:x64-windows
vcpkg.exe install boost:x64-windows
vcpkg.exe install freeimage:x64-windows
vcpkg.exe install flann:x64-windows
vcpkg.exe install glew:x64-windows
vcpkg.exe install qt5:x64-windows
vcpkg.exe install metis:x64-windows
关于vcpkg的介绍,参考:https://blog.csdn.net/fengbingchun/article/details/131145117
2.解决编译过程中的error:
(1).src/estimators/generalized_relative_pose.cc: fatal error C1128: 节数超过对象文件格式限制:
在主CMakeLists.txt中,在各种option设置语句后,添加如下语句:
if(MSVC)
add_compile_options(/bigobj)
endif()
(2).src/estimators/pose.cc: error C2065: "qvec_data", "tvec_data":未声明的标识符
在此文件的RefineAbsolutePose函数的前部添加如下语句:
double* qvec_data = qvec->data();
double* tvec_data = tvec->data();
3.编写build.sh,内容如下:注:编译debug时,需要再额外从vcpkg中拷贝一些库到colmap.exe下,脚本中已添加;release不需要
#! /bin/bash
usage() {
echo "An input parameter is required, and only one of the following parameters can be supported: debug release"
echo "For example: $0 debug"
exit -1
}
if [ $# != 1 ]; then
usage
fi
echo "==== build $1 ===="
common_options=" -DCUDA_ENABLED=OFF
-DCMAKE_TOOLCHAIN_FILE=C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake"
vcpkg_path=C:/dev/vcpkg/installed/x64-windows
if [ $1 == "debug" ]; then
if [[ ! -d "build_debug" ]]; then
mkdir build_debug
cd build_debug
else
cd build_debug
fi
cmake
-G"Visual Studio 16 2019" -A x64
${common_options}
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_CONFIGURATION_TYPES=Debug
..
cmake --build . --config debug --target colmap_exe --parallel 24
echo "==== copy dynamic libraries ===="
colmap_exe_path=src/exe/Debug
cp ${vcpkg_path}/bin/lz4.dll ${colmap_exe_path}
cp ${vcpkg_path}/bin/FreeImage.dll ${colmap_exe_path}
cp ${vcpkg_path}/bin/zlib1.dll ${colmap_exe_path}
cp ${vcpkg_path}/bin/libpng16.dll ${colmap_exe_path}
cp ${vcpkg_path}/bin/tiff.dll ${colmap_exe_path}
cp ${vcpkg_path}/bin/raw.dll ${colmap_exe_path}
cp ${vcpkg_path}/bin/OpenEXR-3_1.dll ${colmap_exe_path}
cp ${vcpkg_path}/bin/Imath-3_1.dll ${colmap_exe_path}
cp ${vcpkg_path}/bin/Iex-3_1.dll ${colmap_exe_path}
cp ${vcpkg_path}/bin/lcms2.dll ${colmap_exe_path}
cp ${vcpkg_path}/bin/IlmThread-3_1.dll ${colmap_exe_path}
cp ${vcpkg_path}/bin/Iex-3_1.dll ${colmap_exe_path}
cp ${vcpkg_path}/debug/bin/openjp2.dll ${colmap_exe_path}
cp ${vcpkg_path}/debug/bin/libwebpdecoder.dll ${colmap_exe_path}
elif [ $1 == "release" ]; then
if [[ ! -d "build_release" ]]; then
mkdir build_release
cd build_release
else
cd build_release
fi
cmake
-G"Visual Studio 16 2019" -A x64
${common_options}
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_CONFIGURATION_TYPES=Release
..
cmake --build . --config release --target colmap_exe --parallel 24
else
echo "Error: $1 is not supported"
usage
exit -1
fi
执行脚本生成colmap.exe:此脚本与主CMakeLists.txt位于同一目录下
(1).debug:./build.sh debug
(2).release: ./build.sh release ,执行结果如下所示:
以debug为例,执行./build.sh debug后,会在build_debug目录下生成COLMAP.sln工程,在build_debug/src/exe/Debug目录下生成colmap.exe
COLMAP.sln工程界面如下:
打开colmap gui:打开cmd,执行:colmap.exe gui,结果如下所示: