概要
解决以下安装问题:
-- Could NOT find CUDNN: Found unsuitable version "..", but required is at least "7.5" (found CUDA_cudnn_LIBRARY-NOTFOUND)
下载cuda的runfile版本
连接地址:
https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=22.04&target_type=runfile_local
注意,请下载对应驱动的版本。
默认驱动和 cuda toolkit都会安装成功!
配置环境变量
官网下载cudann
官网下载cuda对应版本的cudnn:
https://developer.nvidia.com/rdp/cudnn-archive#a-collapse805-111
这里我们选择的是最新的cudnn版本v8.6.0。
cudnn 8的版本,将有版本号的头文件单独写了一个文件cudnn_version.h,而不再是之前的cudnn.h,所以需要执行的是以下语句(这里容易出错。8.x以后的cudnn需要执行此语句.)
sudo cp /usr/include/cudnn*.h /usr/local/cuda/include/
sudo cp /usr/lib/libcudnn* /usr/local/cuda/lib64/
安装Opencv依赖包
sudo apt-get update
sudo apt-get upgrade
sudo apt install cmake pkg-config unzip yasm git checkinstall libjpeg-dev libpng-dev libtiff-dev libavcodec-dev libavformat-dev libswscale-dev libavresample-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libxvidcore-dev x264 libx264-dev libfaac-dev libmp3lame-dev libtheora-dev libfaac-dev libmp3lame-dev libvorbis-dev libopencore-amrnb-dev libopencore-amrwb-dev
sudo apt-get install libdc1394-22 libdc1394-22-dev libxine2-dev libv4l-dev v4l-utils
cd /usr/include/linux
sudo ln -s -f ../libv4l1-videodev.h videodev.h
cd ~
sudo apt-get install libgtk-3-dev libtbb-dev libatlas-base-dev gfortran
下载opencv和opencv_contrib并解压
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
准备编译
cd opencv-4.5.5
mkdir build
cd build
安装anaconda环境
到以下环境安装anaconda
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
执行编译命令
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D CMAKE_C_COMPILER=/usr/bin/gcc-9 \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_opencv_python3=ON \
-D WITH_CUDA=ON \
-D WITH_CUDNN=ON \
-D WITH_TBB=ON \
-D OPENCV_DNN_CUDA=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D CUDA_ARCH_BIN=8.0 \
-D WITH_CUBLAS=1 \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_EXTRA_MODULES_PATH=/home/qwen/opencv_contrib/modules \
-D PYTHON3_EXECUTABLE=/home/qwen/anaconda3/bin/python3.7m \
-D PYTHON3_INCLUDE_DIR=/home/qwen/anaconda3/include/python3.7m \
-D PYTHON3_LIBRARY=/home/qwen/anaconda3/lib/libpython3.7m.so \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/home/qwen/anaconda3/lib/python3.7/site-packages/numpy/core/include \
-D PYTHON3_PACKAGES_PATH=/home/qwen/anaconda3/lib/python3.7/site-packages \
-D PYTHON_DEFAULT_EXECUTABLE=/home/qwen/anaconda3/bin/python3.7m \
-D CUDNN_LIBRARY=/usr/local/cuda/lib64/libcudnn.so.8.9.4 \
-D CUDNN_INCLUDE_DIR=/usr/local/cuda/include \
-D CUDA_CUDA_LIBRARY=/usr/local/cuda/lib64/stubs/libcuda.so \
-D OPENCV_PYTHON3_INSTALL_PATH=/home/qwen/anaconda3/lib/python3.7/site-packages \
-D OpenCV_INCLUDE_DIRS=/usr/include/openjpeg-2.3 \
-D WITH_WEBP=OFF \
-D WITH_OPENCL=OFF \
-D ETHASHLCL=OFF \
-D ENABLE_CXX11=ON \
-D BUILD_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D WITH_OPENGL=ON \
-D WITH_GSTREAMER=ON \
-D BUILD_OPENJPEG=ON \
-D WITH_V4L=ON \
-D WITH_QT=OFF \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_python2=OFF \
-D HAVE_opencv_python3=ON ..
以下编译命令,需要更换为自己的地址
-D CUDA_ARCH_BIN=8.9.4 \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_EXTRA_MODULES_PATH=/home/qwen/opencv_contrib-4.5.2/modules \
-D PYTHON3_EXECUTABLE=/home/qwen/anaconda3/bin/python3.7m \
-D PYTHON3_INCLUDE_DIR=/home/qwen/anaconda3/include/python3.7m \
-D PYTHON3_LIBRARY=/home/qwen/anaconda3/lib/libpython3.7m.so \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/home/qwen/anaconda3/lib/python3.7/site-packages/numpy/core/include \
-D PYTHON3_PACKAGES_PATH=/home/qwen/anaconda3/lib/python3.7/site-packages \
-D PYTHON_DEFAULT_EXECUTABLE=/home/qwen/anaconda3/bin/python3.7m \
-D CUDNN_LIBRARY=/usr/local/cuda/lib64/libcudnn.so.8.9.4 \
-D CUDNN_INCLUDE_DIR=/usr/local/cuda/include \
-D CUDA_CUDA_LIBRARY=/usr/local/cuda/lib64/stubs/libcuda.so \
-D OPENCV_PYTHON3_INSTALL_PATH=/home/qwen/anaconda3/lib/python3.7/site-packages \
编译成功标识:
文章来源:https://www.toymoban.com/news/detail-771566.html
安装OpenCV并检查是否安装成功
执行make后日志信息如下:文章来源地址https://www.toymoban.com/news/detail-771566.html
到了这里,关于Opencv cuda版本在ubuntu22.04中安装办法,解决Could NOT find CUDNN的办法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!