ubuntu编译opencv-contrib分为五步:
上述步骤1,2,3参考:https://blog.csdn.net/m0_37201243/article/details/103439613
如果sudo apt update报错:
The repository 'http://ppa.launchpad.net/nemh/systemback/ubuntu bionic Release' does not have a Release file.
输入:
sudo apt-add-repository -r ppa:nemh/systemback
sudo apt update
sudo apt-get update
第1步就是禁用nouveau,然后安装nvidia驱动即可。
第2步下载cuda地址:https://developer.nvidia.com/cuda-downloads?target_os=Linux
或者直接运行以下代码下载:
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.run
如果下载出现报错:wget: unable to resolve host address ‘developer.download.nvidia.com’
修改域名服务器:
sudo vim /etc/resolv.conf
nameserver 223.5.5.5 #阿里域名服务器
nameserver 223.6.6.6 #阿里域名服务器
# nameserver 8.8.8.8 #google域名服务器
# nameserver 8.8.4.4 #google域名服务器
安装完cuda后,需要配置环境变量:
sudo vim ~/.bashrc
# 第3行的CUDA-10.0需要根据实际版本修改
export PATH=/usr/local/cuda-11.8/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
source ~/.bashrc
查看cuda是否安装成功
nvcc -V
cudnn下载网址:https://developer.nvidia.com/rdp/cudnn-download
解压tar.xz文件:tar -xvJf cudnn-linux-x86_64-8.6.0.163_cuda11-archive.tar.xz
参考:https://blog.csdn.net/qq_40870091/article/details/119926891
第4,5步参考:https://waltpeter.github.io/open-cv-basic/install-opencv-with-contrib-ubuntu/index.html
cmake编译命令:
注意OPENCV_EXTRA_MODULES_PATH那一栏要改成自己的路径。
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D WITH_CUDA=ON \
-D WITH_CUDNN=ON \
-D OPENCV_DNN_CUDA=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D CUDA_ARCH_BIN=7.5 \
-D WITH_CUBLAS=1 \
-D OPENCV_EXTRA_MODULES_PATH=/home/ubuntu1804/simulation/opencv_contrib/modules \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=ON ..
如果编译中缺失文件:https://www.cnblogs.com/arxive/p/11778731.html
将下载好的boostdesc_bgm.i
系列和vgg_generated_48.i
系列放到opencv-3.4.5/opencv_contrib-3.4.5/modules/xfeatures2d/src/
目录下。将下载好的7505c44ca4eb54b4ab1e4777cb96ac05-face_landmark_model.dat
放到opencv/.cache/data/
文件夹中。
编译阶段出现错误可以参考:https://blog.csdn.net/qq_42257666/article/details/123592033?spm=1001.2101.3001.6650.12&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-12-123592033-blog-78780269.pc_relevant_recovery_v2&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-12-123592033-blog-78780269.pc_relevant_recovery_v2&utm_relevant_index=13
在ubuntu中创建Python虚拟环境:
https://www.myfreax.com/how-to-create-python-virtual-environments-on-ubuntu-18-04/
python库换源或者临时换源下载:https://www.jianshu.com/p/ca7e3d9d27a3
pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple