ubuntu20.04源码安装支持cuda的opencv4.5.5,显卡Geforce RTX4090
参考了这位博主的内容:https://blog.csdn.net/u013454780/article/details/128357962
sudo apt-get update
sudo apt-get upgrade
安装依赖
//安装前的必备包
sudo apt-get install build-essential
sudo apt-get install cmake git g++
//安装官方给的opencv依赖包
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
sudo apt-get -y install libgstreamer-plugins-base1.0-dev
sudo apt-get -y install libgstreamer1.0-dev
sudo apt-get install libvtk6-dev
//依赖包
sudo apt-get install libv4l-dev liblapacke-dev
sudo apt-get install checkinstall yasm libxine2-dev libfaac-dev libmp3lame-dev libtheora-dev
sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev libavresample-dev x264 v4l-utils
//处理图像所需的包
sudo apt-get install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
安装libjasper-dev 之前需要做:
sudo vim /etc/apt/sources.list
//在末尾加上
deb http://security.ubuntu.com/ubuntu xenial-security main
//然后更新、安装
sudo apt-get update
sudo apt-get install libjasper-dev
继续安装相关依赖
//处理视频所需包
sudo apt-get install libxvidcore-dev libx264-dev ffmpeg
//opencv功能优化
sudo apt-get install libatlas-base-dev gfortran
//依赖包
sudo apt-get install libopencv-dev
sudo apt-get install libqglviewer-dev-qt5
sudo apt-get install libsuitesparse-dev
sudo apt-get install libcxsparse3
sudo apt-get install libcholmod3
sudo apt-get install python-dev python-numpy
sudo apt install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
sudo apt install build-essential qt5-default ccache libv4l-dev libavresample-dev libgphoto2-dev libopenblas-base libopenblas-dev doxygen openjdk-8-jdk pylint libvtk6-dev
由于Ubuntu20.0.4主存储库中已经将 Qt4框架/Qt4库 删除,需要进行以下操作后重新安装
sudo add-apt-repository ppa:rock-core/qt4
sudo apt-get install libqt4-dev qt4-qmake
下载opecv源码、opencv_contrib源码、编译
// 下载opecv源码
git clone https://github.com/opencv/opencv.git
// 指定版本
git checkout 4.5.5
// 下载opencv_contrib
git clone https://github.com/opencv/opencv_contrib.git
// 进入opencv目录编译
cdd opencv-4.5.5
mkdir build
cd build
//CMAKE_INSTALL_PREFIX可以选择自己的安装路径,也可以用默认的/usr/local
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/home/user/opencv_cuda/opencv_install \
-D INSTALL_C_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.5.5/modules \
-D WITH_OPENGL=ON \
-D WITH_OPENMP=ON\
-D BUILD_EXAMPLES=ON \
-D WITH_CUDA=ON \
-D BUILD_TIFF=ON \
-D ENABLE_PRECOMPILED_HEADERS=OFF\
-D OPENCV_GENERATE_PKGCONFIG=ON \
-DOPENCV_ENABLE_NONFREE=ON \
-D CUDA_nppicom_LIBRARY=stdc++ \
-D CUDA_ARCH_BIN="8.9" ..
CUDA_ARCH_BIN的版本查询方式
// 其中CUDA_ARCH_BIN的版本查询方式
cd /usr/local/cuda-11.8/samples/1_Utilities/deviceQuery
sudo make -j8
没在上面的路径中就可能在下面的路径中
cd /usr/local/cuda-11.8/extras/demo_suite/
运行deviceQuery进行查询
./deviceQuery
输出中的 CUDA Capability Major/Minor version number就是CUDA_ARCH_BIN的版本
IPPICV下载很慢,可以在github上下载,下载路径:https://github.com/opencv/opencv_3rdparty,在分支中搜索ippicv,选择需要的版本进行下载,然后打开opencv-4.5.5/3rdparty/ippicv/ippicv.cmake,修改第42行为你下载的IPPICV目录即可。
cmake成功后的显示
-- Disabled: world
-- Disabled by dependency: -
-- Unavailable: cvv java julia matlab ovis python3
-- Applications: tests perf_tests examples apps
-- Documentation: NO
-- Non-free algorithms: YES
--
-- GUI: GTK2
-- GTK+: YES (ver 2.24.32)
-- GThread : YES (ver 2.64.6)
-- GtkGlExt: NO
-- OpenGL support: NO
-- VTK support: YES (ver 6.3.0)
--
-- Media I/O:
-- ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
-- JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
-- WEBP: /usr/lib/x86_64-linux-gnu/libwebp.so (ver encoder: 0x020e)
-- PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.37)
-- TIFF: build (ver 42 - 4.2.0)
-- JPEG 2000: OpenJPEG (ver 2.4.0)
-- OpenEXR: /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2_3)
-- HDR: YES
-- SUNRASTER: YES
-- PXM: YES
-- PFM: YES
--
-- Video I/O:
-- DC1394: YES (2.2.5)
-- FFMPEG: YES
-- avcodec: YES (58.54.100)
-- avformat: YES (58.29.100)
-- avutil: YES (56.31.100)
-- swscale: YES (5.5.100)
-- avresample: YES (4.0.0)
-- GStreamer: YES (1.16.3)
-- v4l/v4l2: YES (linux/videodev2.h)
--
-- Parallel framework: OpenMP
--
-- Trace: YES (with Intel ITT)
--
-- Other third-party libraries:
-- VA: NO
-- Lapack: YES (/usr/lib/x86_64-linux-gnu/liblapack.so /usr/lib/x86_64-linux-gnu/libcblas.so /usr/lib/x86_64-linux-gnu/libatlas.so)
-- Eigen: YES (ver 3.3.7)
-- Custom HAL: NO
-- Protobuf: build (3.19.1)
--
-- NVIDIA CUDA: YES (ver 11.8, CUFFT CUBLAS)
-- NVIDIA GPU arch: 89
-- NVIDIA PTX archs:
--
-- cuDNN: YES (ver 8.6.0)
--
-- OpenCL: YES (no extra features)
-- Include path: /home/user/opencv_cuda/opencv-4.5.5/3rdparty/include/opencl/1.2
-- Link libraries: Dynamic load
--
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 2.7.18)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.18)
-- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.16.5)
-- install path: lib/python2.7/dist-packages/cv2/python-2.7
--
-- Python (for build): /usr/bin/python2.7
--
-- Java:
-- ant: NO
-- JNI: /usr/lib/jvm/java-8-openjdk-amd64/include /usr/lib/jvm/java-8-openjdk-amd64/include/linux /usr/lib/jvm/java-8-openjdk-amd64/include
-- Java wrappers: NO
-- Java tests: NO
--
-- Install to: /home/user/opencv_cuda/opencv_install
-- -----------------------------------------------------------------
--
-- Configuring done
然后编译、安装
make -j8
make install
标签:ubuntu20.04,opencv4.5,get,--,sudo,dev,源码,apt,install
From: https://blog.csdn.net/m0_64293675/article/details/142127890