环境:
Ubuntu16.04
opencv3.1
cuda10
-
找到自己当时解压后的opencv3.X源码,当时编译时自己新建了一个build文件夹,编译后的文件都放在这个文件夹里面,所以进到该文件夹中,开始操作。
-
sudo apt-get install libvtk6-dev
-
cmake -DWITH_VTK=ON ..
WITH_VTK=ON是安装viz模块 -
cmake时会遇到CUDA_nppi_LIBRARY(ADVANCED)错误
解决办法参考该博客 -
cmake虽然能成功了,但是make时会遇到这个错误
/usr/local/include/vtk-8.2/vtkInteractorObserver.h:198:70: error: ‘nullptr’ was not declared in this scope
解决如下:cmake -D WITH_VTK=ON -D CMAKE_BUILD_TYPE=RELEASE -D PYTHON_DEFAULT_EXECUTABLE=$(python -c "import sys; print(sys.executable)") -D PYTHON3_EXECUTABLE=$(python -c "import sys; print(sys.executable)") -D PYTHON3_NUMPY_INCLUDE_DIRS=$(python -c "import numpy; print (numpy.get_include())") -D PYTHON3_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") -D CMAKE_CXX_FLAGS="-std=c++11" -D CUDA_NVCC_FLAGS="--compiler-options "-std=c++03"" ..
-
make接下来会遇到如下错误
nvcc fatal : Unsupported gpu architecture ‘compute_20’
CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:208 (message):
Error generating
/home/mk/myslam/opencv-3.1.0/build/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o’ failed
解决如下:主要是添加-D CUDA_GENERATION=Keplercmake -D WITH_VTK=ON -D CUDA_GENERATION=Kepler -D CMAKE_BUILD_TYPE=RELEASE -D PYTHON_DEFAULT_EXECUTABLE=$(python -c "import sys; print(sys.executable)") -D PYTHON3_EXECUTABLE=$(python -c "import sys; print(sys.executable)") -D PYTHON3_NUMPY_INCLUDE_DIRS=$(python -c "import numpy; print (numpy.get_include())") -D PYTHON3_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") -D CMAKE_CXX_FLAGS="-std=c++11" -D CUDA_NVCC_FLAGS="--compiler-options "-std=c++03"" ..
-
make遇到新错误
/home/mk/myslam/opencv-3.1.0/modules/viz/src/clouds.cpp:80:13: error: ‘class vtkPolyDataMapper’ has no member named ‘ImmediateModeRenderingOff’
mapper->ImmediateModeRenderingOff();
参考该博客
看到说vtk8.1.0版本之后,就将vtkMapper的ImmediateModeRenderingOff()方法移除了,有两种选择,一是安装低版本的vtk,二是因为ImmediateModeRenderingOff()方法不是必须的操作,直接注释掉 【pcl的安装,也有这个问题,我是通过注释解决的,这次opencv viz模块的安装,通过降低vtk版本解决,之前默认安装,所以安装的最新版本8.2.0】
必须先卸载vtk-8.2.0/usr/local/include下的vtk-8.2.0文件 /usr/local/lib下的。。 sudo rm -rf libvtk*-8.2.so*
https://vtk.org/download/
下载的是VTK-7.1.1.tar.gztar -zxvf VTK-7.1.1.tar.gz mkdir build cd build cmake .. make -j8 sudo make install
-
安装tiff
http://download.osgeo.org/libtiff/
去官网下载的tiff-4.0.9.tar.gztar -zxvf tiff-4.0.9.tar.gz 安装过程: mkdir build_my cd build_my cmake .. make -j8 sudo make install
-
删掉build下面的所有文件,重新编译安装
其中BUILD_TIFF=ON是解决tiff版本问题``` cmake -D WITH_VTK=ON -D CUDA_GENERATION=Kepler -D CMAKE_BUILD_TYPE=RELEASE -D PYTHON_DEFAULT_EXECUTABLE=$(python -c "import sys; print(sys.executable)") -D PYTHON3_EXECUTABLE=$(python -c "import sys; print(sys.executable)") -D PYTHON3_NUMPY_INCLUDE_DIRS=$(python -c "import numpy; print (numpy.get_include())") -D PYTHON3_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") -D CMAKE_CXX_FLAGS="-std=c++11" -D CUDA_NVCC_FLAGS="--compiler-options "-std=c++03"" -D BUILD_TIFF=ON .. sudo make -j8 sudo make install ```
-
然而还是有问题
-
×××××××××××××××××我是分割线××××××××××××××××××
-
把usr/local/include usr/local/lib usr/local/share 以及之前装的opencv2全部卸载掉
-
把vtk也全部卸载掉,然后装成5版本
sudo apt-get install libvtk5-dev
-
然后按步骤4改一下源码
-
重新cmake,一定要vtk变成5版本
cmake -D WITH_VTK=ON -D CUDA_GENERATION=Kepler .. make -j8 然后遇到这个错误 error: ‘NppiGraphcutState’ has not been declared 进入opencv-3.1.0/modules/cudalegacy/src/目录,修改graphcuts.cpp文件,将: #include "precomp.hpp" #if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) 改为 #include "precomp.hpp" #if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000) 然后make编译就可以了
转载:https://blog.csdn.net/ljl1015ljl/article/details/102363139