赞
踩
安装cuda比较简单,进入官网,选择自己需要的版本,按照命令运行即可
CUDA Toolkit Archive | NVIDIA Developer
需要注意的是,选择WSL-Ubuntu
sudo vim ~/.bashrc
移动到最后一行,shift+insert可以复制到vim中。
- export CUDA_HOME=/usr/local/cuda-12.2
- export PATH=/usr/local/cuda-12.2/bin:$PATH
- export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64:$LD_LIBRARY_PAT
最后按ESC退出编辑,输入“:wq”,或者 “ZZ” 保存。
然后输入以下命令使环境变量生效:
source ~/.bashrc
nvcc -V
1、进入官网进行下载,选择匹配自己cuda版本
cuDNN Archive | NVIDIA Developer
2、解压文件,并将其放入cuda对应的文件中
- tar -xvf cudnn-linux-x86_64-8.9.3.28_cuda12-archive.tar.xz
- sudo cp cudnn-*-archive/include/cudnn*.h /usr/local/cuda-12.2/include
- sudo cp -P cudnn-*-archive/lib/libcudnn* /usr/local/cuda-12.2/lib64
- sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda-12.2/lib64/libcudnn*
3、测试
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
1、安装依赖项
- sudo apt-get install cmake git
- sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev libgtk2.0-dev pkg-config
2、下载OpenCV、OpenCV_contrib
3、编译安装
- mkdir build
- cd build
- cmake -D CMAKE_BUILD_TYPE=RELEASE \
- -D CMAKE_INSTALL_PREFIX=/usr/local \
- -D INSTALL_C_EXAMPLES=ON \
- -D OPENCV_ENABLE_NONFREE=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 WITH_CUBLAS=1 \
- -D OPENCV_GENERATE_PKGCONFIG=ON \
- -D OPENCV_EXTRA_MODULES_PATH=/mnt/f/project_linux/opencv_contrib-4.8.1/modules \
- -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 WITH_V4L=ON \
- -D WITH_QT=OFF \
- -D BUILD_opencv_python3=ON \
- -D BUILD_opencv_python2=OFF \
- -D HAVE_opencv_python3=ON ..
-
- make -j8
- sudo make install
4、一些错误
sudo apt install libopenjp2-7-dev
cuda版本太高,下载opencv4.8.1版本
解决办法:Ubuntu20 安装 带cuda的opencv遇到的问题_cuda4dnn/primitives/normalize_bbox.hpp: in instant-CSDN博客
You want to change line 114 in opencv/modules/dnn/src/cuda4dnn/primitives/normalize_bbox.hpp: from: if (weight != 1.0) to: if (weight != static_cast<T>(1.0))
As well as line 124 in opencv/modules/dnn/src/cuda4dnn/primitives/region.hpp (due to a similar error): from: if (nms_iou_threshold > 0) { to: if (nms_iou_threshold > static_cast<T>(0)) {
参考:
Linux下编译Opencv和contrib_linux opencv_contrib-4.5.2编译-CSDN博客
Linux系统编译CUDA版的OpenCV4.2_linux c++使用opencv_contrib dnn-CSDN博客
Install Caffe on Ubuntu 20.04 with OpenCV 4.4 - Q-engineering (qengineering.eu)
ubuntu 编译安装支持CUDA的OpenCV+其他opencv细节(需要特定版本gcc)_ubuntu opencv cuda-CSDN博客
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。