Opencv4.4 安装(Ubuntu 18.04+CUDA10.0+OpenCV4.4)

Opencv4.4 安装(Ubuntu 18.04+CUDA10.0+OpenCV4.4)

参考:https://docs.opencv.org/4.4.0/d7/d9f/tutorial_linux_install.html

1. 基础包安装

sudo apt-get install build-essential
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 libjasper-dev libdc1394-22-dev

sudo apt-get install libatlas-dev
sudo apt-get install libopenblas-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev

sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

安装libjasper-dev 报错,使用以下方式解决

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev 
# 其中libjasper1为 libjasper-dev 的依赖库

可选安装QT

2. 下载源文件

opencv-4.4.0.zip
opencv_contrib-4.4.0.zip

3. 解压并创建build文件夹

unzip opencv-4.4.0.zip
unzip opencv_contrib-4.4.0.zip
cd opencv-4.4.0
mkdir build
cd build

4. 编译

cmake   -D CMAKE_BUILD_TYPE=Release \
				 -D CMAKE_INSTALL_PREFIX=/usr/local/opencv44 \
				-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.4.0/modules \
				-D INSTALL_C_EXAMPLES=ON \
				-D BUILD_DOCS=ON \
				-D BUILD_EXAMPLES=ON \
				-D OPENCV_GENERATE_PKGCONFIG=ON \
				-D WITH_CUDA=ON \
				-D WITH_CUDNN=ON \
				-D OPENCV_DNN_CUDA=ON \
				-D WITH_V4L=ON \
				-D WITH_QT=ON \
				-D WITH_OPENGL=ON \
				-D WITH_GSTREAMER=ON \
				 ..
sudo make -j8
sudo make install

注:Cmake 时会下载一些文件,最好挂代理
可能的错误提示: 缺少hdf5相关文件.
在hdf5 官网下载相应版本

sudo tar -xvf hdf5-1.8.21.tar.gz
cd  hdf5-1.8.21/
sudo ./configure --prefix=/usr/local/hdf5
sudo make
sudo make check   
sudo make install

安装完成后在/usr/local下出现hdf5

5. 环境配置

配置库 (opencv.conf)

cd /etc/ld.so.conf.d/
sudo echo /usr/local/opencv44/lib >> opencv.conf
sudo ldconfig -v

配置 opencv4.pc
opencv4.pc 由编译过程生成,其的默认目录为/usr/local/opencv44/pkgconfig

sudo vi ~/.bashrc
#添加
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opencv44/lib/pkgconfig
#也可以使用命令直接添加(>>为向文件中追加文本的命令)
echo PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opencv44/lib/pkgconfig >> ~/.bashrc

将opencv.pc 放在系统路径下

 sudo cp /usr/local/opencv44/lib/pkgconfig/opencv4.pc  /usr/lib/pkgconfig/opencv.pc

重新加载配置

sudo ldconfig
  • 使用pkg-config 查看opencv版本
    pkg-config --modversion opencv
    pkg-config --modversion opencv
  • 查看 pkg-config 搜索的路径
    pkg-config --variable pc_path pkg-config

Opencv3411

cmake   -D CMAKE_BUILD_TYPE=Release \
				 -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3411 \
				-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.4.11/modules \
				-D INSTALL_C_EXAMPLES=ON \
				-D BUILD_DOCS=ON \
				-D BUILD_EXAMPLES=ON \
				-D OPENCV_GENERATE_PKGCONFIG=ON \
				-D WITH_CUDA=ON \
				-D WITH_CUDNN=ON \
				-D OPENCV_DNN_CUDA=ON \
				-D WITH_V4L=ON \
				-D WITH_QT=ON \
				-D WITH_OPENGL=ON \
				-D WITH_GSTREAMER=ON \
				 ..

你可能感兴趣的:(OpenCV,C++,opencv,linux,ubuntu)