本文承接于我的上篇3DGS在ubuntu下的环境配置:3D gaussian-splatting代码在ubuntu20.04 & CUDA11.8下的配置_3dgs cuda11.8-CSDN博客
参考&致谢
以下是我的参考文章,可能会对你们的问题有帮助,感谢他们:
【3DGS】Ubuntu20.04系统搭建3D Gaussian Splatting及可视化环境_ubuntu 3dgs安装-CSDN博客
Linux Ubuntu 20.04LTS安装OpenSSL步骤_ubuntu安装openssl-CSDN博客
ubuntu安装cmake的三种方法(超方便!)-CSDN博客
opencv编译与anaconda下lib冲突,屏蔽anaconda编译opencv_anaconda opencv冲突 lib-CSDN博客
在ubuntu下安装opencv4.1.0详细步骤_ubuntu22.04安装opencv4.10-CSDN博客
【已解决】Ubuntu 20.04 编译OpenCV 动态链接库指向版本不一致导致出错_ubuntu opencv ffi-CSDN博客
【已解决】ubuntu 16.04 源码编译opencv4.5.1 报错 “../../lib/libopencv_imgcodecs.so.4.5.0: undefined reference t”_ubuntu16.04 undefined reference to libfdt-CSDN博客
Ubuntu中安装openCV3.4.12编译过程中与Anaconda冲突_编译opencv-4.6之前我安装了anaconda3,系统库的路径被覆盖掉-CSDN博客
Linux Ubuntu 20.04LTS安装OpenSSL步骤_ubuntu安装openssl-CSDN博客
本文环境
my@test:~$ hostnamectl
Icon name: computer-desktop
Chassis: desktop
Operating System: Ubuntu 20.04.6 LTS
Kernel: Linux 5.15.0-117-generic
Architecture: x86-64
退出conda环境
建议退出conda环境,conda环境的libtiff.so等动态链接库可能会影响到opencv的安装
conda deactivate
(base) my@test:~/下载$ conda deactivate
my@test:~/下载$
Ubuntu中安装openCV3.4.12编译过程中与Anaconda冲突_编译opencv-4.6之前我安装了anaconda3,系统库的路径被覆盖掉-CSDN博客
openssl的安装
cmake的安装需要OpenSSL 的头文件和库文件,Ubuntu 20.04LTS 系统自带 OpenSSL ,但是这个OpenSSL 是没有<头文件.h>和<动态库文件.so及静态库文件.a>的,所以需要手动下载。
sudo apt-get install libssl-dev
my@test:~/下载$ sudo apt-get install libssl-dev
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
...
此方法会把OpenSSL的头文件放在 “/usr/include/openssl” ,动态库文件(libssl.so、libcrypto.so)、静态库文件(libssl.a、libcrypto.a)均放在 “/lib/x86_64-linux-gnu”
未下载OpenSSL头文件、库文件,cmake安装会报以下错误:Could not find OpenSSL
cmake的安装
1. cmake下载
Download CMake cmake网址
点击上述链接进入gitlab页面可下载cmake指定版本,以及可查看安装过程的指令CMake / CMake · GitLabCMake, the cross-platform, open-source build system.https://gitlab.kitware.com/cmake/cmake
本文使用cmake3.30.4 source源码版本
2. 解压
tar -xvzf cmake-3.30.4.tar.gz
my@test:~/下载$ tar -xvzf cmake-3.30.4.tar.gz
cmake-3.30.4/
cmake-3.30.4/.clang-format
cmake-3.30.4/.clang-tidy
cmake-3.30.4/Auxiliary/
cmake-3.30.4/Auxiliary/CMakeLists.txt
cmake-3.30.4/Auxiliary/bash-completion/
...
当然,如果是ubuntu桌面版,可以直接右击“提取到...”
3. 执行“文件检查&编译&安装”
cd cmake-3.30.4/./bootstrap && make -j8 && sudo make install
my@test:~/下载$ cd cmake-3.30.4/
my@test:~/下载/cmake-3.30.4$ ./bootstrap && make -j8 && sudo make install
---------------------------------------------
CMake 3.30.4, Copyright 2000-2024 Kitware, Inc. and Contributors
Found GNU toolchain
C compiler on this system is: gcc
C++ compiler on this system is: g++
Makefile processor on this system is: make
g++ has setenv
g++ has unsetenv
...
---------------------------------------------
CMake has bootstrapped. Now run make.
[ 0%] Building C object Source/kwsys/CMakeFiles/cmsys.dir/ProcessUNIX.c.o
[ 0%] Building C object Source/kwsys/CMakeFiles/cmsys.dir/Base64.c.o
[ 0%] Building C object Source/kwsys/CMakeFiles/cmsys.dir/EncodingC.c.o
...
[ 1%] Built target cmsys
[ 2%] Built target cmsys_c
[ 3%] Built target cmsysTestsC
[ 3%] Built target testConsoleBufChild
cmake安装到了/usr/local/share/cmake-3.30路径
报错
CMake Error at /home/my/anaconda3/lib/cmake/Qt5Gui/Qt5GuiConfigExtras.cmake:9 (message):
Failed to find "GL/gl.h" in
"/home/my/anaconda3/include;/croot/qt-main_1693210824277/_build_env/x86_64-conda-linux-gnu/sysroot/usr/include;/croot/qt-main_1693210824277/_build_env/x86_64-conda-linux-gnu/sysroot/usr/include/libdrm;/croot/qt-main_1693210824277/_build_env/x86_64-conda-linux-gnu/sysroot/usr/include".
Call Stack (most recent call first):
/home/my/anaconda3/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:233 (include)
/home/my/anaconda3/lib/cmake/Qt5Widgets/Qt5WidgetsConfig.cmake:100 (find_package)
Tests/CMakeLists.txt:280 (find_package)
会看到链接动态库到anaconda了,是由于没退出anaconda base环境造成的,先conda deactivate,再删除CMakeCache.txt,重新./bootstrap && make -j8 && sudo make install
5. 软链接
sudo ln -sf /usr/local/bin/cmake /usr/bin/
6. 验证版本
my@test:~/下载/cmake-3.30.4$ cmake --version
cmake version 3.30.4
CMake suite maintained and supported by Kitware (kitware.com/cmake).
opencv的安装
1. 下载依赖
sudo apt-get install build-essential unzip pkg-configsudo apt-get install libjpeg-dev libpng-dev libtiff-devsudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-devsudo apt-get install libxvidcore-dev libx264-devsudo apt-get install libgtk-3-devsudo apt-get install libatlas-base-dev gfortransudo apt-get install python3-dev
2. opencv下载
https://opencv.org/releases/ opencv下载
https://github.com/opencv/opencv_contrib/releases/tag/4.10.0 opencv_contrib下载
3. 解压
unzip opencv-4.10.0.zipunzip opencv_contrib-4.10.0.zip
my@test:~/下载$ unzip opencv-4.10.0.zip
Archive: opencv-4.10.0.zip
71d3237a093b60a27601c20e9ee6c3e52154e8b1
creating: opencv-4.10.0/
inflating: opencv-4.10.0/.editorconfig
...
当然,如果是ubuntu桌面版,可以直接右击“提取到...”
4.移动opencv_contrib
将opencv_contrib-4.10.0移到opencv-4.10.0文件夹下
5. cmake链接
cmake opencv_contrib-4.10.0会下载外网额外的组件,注意网速慢
cd opencv-4.10.0/mkdir buildcd buildcmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.10.0/modules ..
my@test:~/下载/opencv-4.10.0/build$ cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.10.0/modules ..
CMake Warning (dev) at CMakeLists.txt:127 (enable_language):
project() should be called prior to this enable_language() call.
This warning is for project developers. Use -Wno-dev to suppress it.
-- The CXX compiler identification is GNU 9.4.0
-- The C compiler identification is GNU 9.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /bin/c++ - skipped
如果有报错信息如下:
CMake Error at CMakeLists.txt:10 (message):
FATAL: In-source builds are not allowed.
You should create a separate directory for build files.
-- Configuring incomplete, errors occurred!
则需要先删除cmake缓存
rm ../CMakeCache.txt
6. 编译
make -j8
my@test:~/下载/opencv-4.10.0/build$ make -j8
[ 0%] Built target opencv_videoio_plugins
[ 0%] Built target opencv_dnn_plugins
[ 0%] Built target opencv_highgui_plugins
...
报错1
报错信息:
fatal error: openjpeg.h: No such file or directory
原因是找不到openjpeg文件,我的解决是修改报错信息中给的.hpp文件:
先locate openjpeg.h,输出/usr/include/openjpeg-2.3/openjpeg.h
修改.hpp文件的引入
//#include <openjpeg.h>
#include </usr/include/openjpeg-2.3/openjpeg.h>
报错2
/usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFReadDirectory@LIBTIFF_4.0'
//usr/lib/libgdal.so.20: undefined reference to `TIFFLastDirectory@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFWriteEncodedStrip@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFIsTiled@LIBTIFF_4.0'
//usr/lib/libgdal.so.20: undefined reference to `TIFFSwabArrayOfShort@LIBTIFF_4.0'
在确保libtiff-dev已安装的情况下,sudo apt-get install libtiff4-dev
cmake指令增加 -D BUILD_TIFF=ON
7. 安装opencv
sudo make install
my@test:~/下载/opencv-4.10.0/build$ sudo make install
[ 0%] Built target opencv_dnn_plugins
[ 0%] Built target opencv_highgui_plugins
[ 2%] Built target libopenjp2
[ 2%] Built target opencv_videoio_plugins
...
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/share/licenses/opencv4/ippicv-readme.htm
SIBR_viewers的安装
GitHub - graphdeco-inria/gaussian-splatting: Original reference implementation of "3D Gaussian Splatting for Real-Time Radiance Field Rendering"
gs谈到了SIBR的安装,但是我的安装过程有报错
1. 依赖安装
sudo apt install -y libglew-dev libassimp-dev libboost-all-dev libgtk-3-dev libopencv-dev libglfw3-dev libavdevice-dev libavcodec-dev libeigen3-dev libxxf86vm-dev libembree-dev
my@test:~/postg/thesis/gaussian-splatting/SIBR_viewers$ sudo apt install -y libglew-dev libassimp-dev libboost-all-dev libgtk-3-dev libopencv-dev libglfw3-dev libavdevice-dev libavcodec-dev libeigen3-dev libxxf86vm-dev libembree-dev
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
2. 切换SIBR的分支
如果是ubuntu20.04,还需要切换SIBR的分支,如果是ubuntu22.04则不需要
cd SIBR_viewersgit checkout fossa_compatibility
my@test:~/postg/thesis/gaussian-splatting/SIBR_viewers$ git checkout fossa_compatibility
M CMakeLists.txt
M src/projects/remote/CMakeLists.txt
已经位于 'fossa_compatibility'
您的分支与上游分支 'origin/fossa_compatibility' 一致。
3. cmake链接
cmake -Bbuild . -DCMAKE_BUILD_TYPE=Release
报错1
中途可能卡顿,是因为在下载其他依赖组件。我的解决方法是换一个cmake版本(比如使用sudo apt-get install cmake),就成功了
--Populating library imgui...
报错2
报错信息:
CMake Error in src/core/system/CMakeLists.txt:
Imported target "Boost::system" includes non-existent path
"/include"
in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
* The path was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and references files it does not
provide.”
直接有效的解决方法是创建/include文件夹,并将boot文件夹复制到include文件夹下
locate boost/version.hpp ##定位boost文件夹,我的boost文件是在 /usr/include/boost
sudo mkdir /include
sudo cp -r /usr/include/boost/ /include/ ##复制文件夹
4. 编译安装
cmake --build build -j24 --target install
报错
报错信息:
In file included from /home/my/postg/thesis/gaussian-splatting/SIBR_viewers/src/./core/graphics/Utils.hpp:15,
from /home/my/postg/thesis/gaussian-splatting/SIBR_viewers/src/core/graphics/Utils.cpp:14:
/home/my/postg/thesis/gaussian-splatting/SIBR_viewers/src/./core/graphics/Config.hpp:29:12: fatal error: opencv2/opencv.hpp: 没有那个文件或目录
29 | # include <opencv2/opencv.hpp>
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
解决方法:c++ 中——fatal error: opencv2/opencv.hpp: No such file or directory #include <opencv2/opencv.hpp>_opencv2: no such file or directory #include <openc-CSDN博客
至此,SIBR安装完毕
SIBR运行
将3D gaussian-splatting代码在ubuntu20.04 & CUDA11.8下的配置_3d gaussian splatting 环境搭建 ubuntu-CSDN博客
中的训练结果运行,训练结果的目录结构如下:
my@test:~/postg/thesis/gaussian-splatting/data$ tree output
output
├── cameras.json
├── cfg_args
├── input.ply
└── point_cloud
├── iteration_30000
│ └── point_cloud.ply
└── iteration_7000
└── point_cloud.ply
4 directories, 5 files
1. 运行SIBR
cd install/bin./SIBR_gaussianViewer_app -m /home/my/thesis/gaussian-splatting/data/output/
报错1
报错信息:
my@test:~/thesis/gaussian-splatting/SIBR_viewers/install/bin$ ./SIBR_gaussianViewer_app -m /home/my/thesis/gaussian-splatting/output/
./SIBR_gaussianViewer_app: error while loading shared libraries: libwebp.so.7: cannot open shared object file: No such file or directory
(1)查看依赖的动态链接库,发现部分没链接上
ldd ./SIBR_gaussianViewer_app
my@test:~/thesis/gaussian-splatting/SIBR_viewers/install/bin$ ldd ./SIBR_gaussianViewer_app
libwebp.so.7 => not found
libLerc.so => not found
libjpeg.so.9 => not found
libdeflate.so.0 => not found
(2)手动创建链接,先找到动态链接库,如果没有就sudo apt-get install ...
locate libwebp.so.7
my@test:~/thesis/gaussian-splatting/SIBR_viewers/install/bin$ locate libwebp.so.7
/home/my/anaconda3/lib/libwebp.so.7
(3)然后将.so复制到lib中
cp /home/my/anaconda3/lib/libwebp.so.7 /home/my/thesis/gaussian-splatting/SIBR_viewers/install/lib/
my@test:~/thesis/gaussian-splatting/SIBR_viewers/install/bin$ cp /home/my/anaconda3/lib/libwebp.so.7 /home/my/thesis/gaussian-splatting/SIBR_viewers/install/lib/
(4)再调用 ldd ./SIBR_gaussianViewer_app 查看动态库是否链接上
报错2
报错信息:
my@test:~/thesis/gaussian-splatting/SIBR_viewers/install/bin$ ./SIBR_gaussianViewer_app -m /home/my/thesis/gaussian-splatting/data/output/
./SIBR_gaussianViewer_app: /usr/local/lib/libtiff.so.5: no version information available (required by /lib/x86_64-linux-gnu/libopencv_imgcodecs.so.4.2)
./SIBR_gaussianViewer_app: /usr/local/lib/libtiff.so.5: no version information available (required by /lib/libgdal.so.26)
./SIBR_gaussianViewer_app: /usr/local/lib/libtiff.so.5: no version information available (required by /lib/x86_64-linux-gnu/libpoppler.so.97)
./SIBR_gaussianViewer_app: /usr/local/lib/libtiff.so.5: no version information available (required by /lib/x86_64-linux-gnu/libgeotiff.so.5)
[SIBR] -- INFOS --: Initialization of GLFW
[SIBR] ## ERROR ##: FILE /home/my/thesis/gaussian-splatting/SIBR_viewers/src/core/graphics/Window.cpp
LINE 30, FUNC glfwErrorCallback
GLX: Failed to create context: GLXBadFBConfig
terminate called after throwing an instance of 'std::runtime_error'
what(): See log for message errors
已放弃 (核心已转储)
(1)是因为OpenGL的版本问题,解决如下,查看OpenGL的版本:
sudo apt install mesa-utils -yglxinfo | grep OpenGL
my@test:~/thesis/gaussian-splatting/SIBR_viewers/install/bin$ glxinfo | grep OpenGL
OpenGL vendor string: Mesa/X.org
OpenGL renderer string: llvmpipe (LLVM 12.0.0, 256 bits)
OpenGL core profile version string: 4.5 (Core Profile) Mesa 21.2.6
OpenGL core profile shading language version string: 4.50
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.1 Mesa 21.2.6
OpenGL shading language version string: 1.40
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 21.2.6
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:
其中OpenGL core profile version string: 4.5,则直接指令带上MESA_GL_VERSION_OVERRIDE=4.5即可
MESA_GL_VERSION_OVERRIDE=4.5 ./SIBR_gaussianViewer_app -m /home/my/thesis/gaussian-splatting/output/
可视化结果
键位:qweasd控制平移,uiojkl控制旋转
q下,e上,w前进,s后退
选择trackball,可以用鼠标进行旋转
这个ubuntu环境下的可视化配置耗费我很多时间,直接在windows上可视化更方便,也早已实现。我也深刻理解了奥卡姆剃刀原则--“如无必要,勿增实体”,谨记。