Ubuntu 20.04 源码编译安装OpenCV 4.5.0

 源码安装 OpenCV 4.5

官方文档:

官方文档:OpenCV: Install OpenCV-Python in Ubuntu

1. 安装编译依赖

sudo apt install build-essential cmake git pkg-config libgtk-3-dev \ libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \ libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \ gfortran openexr libatlas-base-dev python3-dev python3-numpy \ libtbb2 libtbb-dev libdc1394-22-dev

2. 克隆 OpenCV 4.5.0 源代码

wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.0.zip
wget -O opencv.zip https://github.com/opencv/opencv/archive/master.zip

3. 编译 OpenCV

mkdir build

cd build


cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local/opencv \
-DINSTALL_PYTHON_EXAMPLES=OFF \
-DINSTALL_C_EXAMPLES=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_TEST=OFF \
-DENABLE_FAST_MATH=1 \
-DOPENCV_ENABLE_NONFREE=ON \
..


make -j4  # 使用 4 核处理器来编译

sudo make install

 第一次直接make -j8的时候,报 test 相关的错误,增加上述关闭 test 的 cmake 参数,删除 build 文件夹,重新编译,仍然报

4. 编辑/etc/ld.so.conf

sudo gedit /etc/ld.so.conf

include /etc/ld.so.conf.d/*.conf

include /usr/local/lib

sudo ldconfig

5. 编辑bash  .bashrc

#sudo gedit /etc/bash.bashrc

添加: 

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

export PKG_CONFIG_PATH

 更新:

# source /etc/bash.bashrc

参考文章:

Ubuntu 20.04 LTS 安装OpenCV 4.5.5-CSDN博客

猜你喜欢

转载自blog.csdn.net/coco_1998_2/article/details/141558537