目录
一、cuda
二、 cuda版本的Opencv3.4.13
首先提前安装好显卡驱动,在软件与更新--附加驱动里面直接安装即可,这个很简单,不再赘述。
查看自己应该安装的版本https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html
去官网下载安装
旧版本cuda入口https://developer.nvidia.com/cuda-toolkit-archive
看网上很多博客说用runfile安装比较好
10.2的入口https://developer.nvidia.com/cuda-10.2-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=runfilelocal
一共三个文件,后两个相当于补丁。
下载
wget https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.run
安装
sudo sh cuda_10.2.89_440.33.01_linux.run
(请自动忽略输错密码)
accept
按空格取消选择,因为之前安装了显卡驱动,Install,然后等待即可
waiting............................................................................................
后面两个补丁安装方式相同,不过看一些博客说不安装补丁一般也没有问题。
安装补丁的时候记得把里面安装cuda10.2按空格取消
在.zshrc(我的shell是zsh,bash是.bashrc)添加环境变量
export PATH=/usr/local/cuda-10.2/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64:$LD_LIBRARY_PATH
然后
source .zshrc
或者
source .bashrc
测试是否安装成功
nvcc -V
完成
卸载cuda(我还没用过)
cd /usr/local/cuda/bin
sudo ./cuda-uninstaller
cd /usr/local/cuda-10.2/bin
sudo ./cuda-uninstaller
sudo rm -rf /usr/local/cuda /usr/local/cuda-10.2
多Opencv共存https://blog.csdn.net/learning_tortosie/article/details/80594399
从官网下载源码https://opencv.org/releases/
先安装依赖(参考视觉SLAM十四讲)以及https://blog.csdn.net/chentianting/article/details/86610601
sudo apt-get install build-essential libgtk2.0-dev libvtk5-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev libtbb-dev
出现错误
sudo apt-get install libtiff5-dev
继续安装出现新错误
参考https://blog.csdn.net/weixin_41053564/article/details/81254410
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
之后把未安装的依赖安装了就可以
sudo apt-get install build-essential checkinstall cmake pkg-config yasm
sudo apt-get install git gfortran
sudo apt-get install libjpeg8-dev libjasper-dev libpng12-dev
sudo apt-get install libtiff5-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
sudo apt-get install libxine2-dev libv4l-dev
sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt-get install qt5-default libgtk2.0-dev libtbb-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install libfaac-dev libmp3lame-dev libtheora-dev
sudo apt-get install libvorbis-dev libxvidcore-dev
sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev
sudo apt-get install x264 v4l-utils
# Optional dependencies
sudo apt-get install libprotobuf-dev protobuf-compiler
sudo apt-get install libgoogle-glog-dev libgflags-dev
sudo apt-get install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen
在Opencv中下载contrib模块https://github.com/opencv/opencv_contrib/tree/3.4
下载完了之后记得切换到3.4
在opencv文件夹中
mkdir build
cd build
这里参考https://blog.csdn.net/chentianting/article/details/85677166
先别记得输入进去,看下面的几个参数要改
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules/ \
-D CUDA_CUDA_LIBRARY=/usr/local/cuda/lib64/stubs/libcuda.so \
-D CUDA_ARCH_BIN=6.1 \
-D CUDA_ARCH_PTX="" \
-D WITH_CUDA=ON \
-D WITH_TBB=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D WITH_V4L=ON \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON \
-D WITH_QT=ON \
-D WITH_OPENGL=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D WITH_NVCUVID=ON \
-D BUILD_opencv_cudacodec=OFF ..
其中OPENCV_EXTRA_MODULES_PATH(刚才下的contrib模块)和CMAKE_INSTALL_PREFIX(安装路径)要改成自己的路径。
CUDA_ARCH_BIN查看方式为
cd /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
cmake成功后
sudo make -j8
或者
sudo make -j4
make成功之后
sudo make install
正常来说是结束了,假如你有多个opencv版本,需要在终端配置文件中添加一下环境变量。我终端用的是zsh,如果是bash的话就是.bashrc文件。
里面的路径就是之前CMAKE_INSTALL_PREFIX中设置的
export PKG_CONFIG_PATH=/usr/local/opencv-3.4.13/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/opencv-3.4.13/lib
查看版本,3.2.0是之前安装过的版本,3.4.13是添加环境变量之后终端找到的新安装的opencv。
至此,大概是都完事了(若有后续问题还会更新)