Ubuntu 20.04编译安装OpenCV 4.3

原创
2021/04/13 17:24
阅读数 1K

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 libopenexr-dev \
    libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev \
    qtbase5-dev qtdeclarative5-dev llvm clang libclang-dev

2、下载OpenCV 4.3源码

OpenCV: https://github.com/opencv/opencv/releases/tag/4.3.0

OpenCV contrib: https://github.com/opencv/opencv_contrib/releases/tag/4.3.0

1)下载地址:

https://github.com/opencv/opencv/archive/refs/tags/4.3.0.tar.gz

https://github.com/opencv/opencv_contrib/archive/refs/tags/4.3.0.tar.gz

2)解压到目录:/home/admin/opencv_4.3_build/

cd /home/admin/opencv_4.3_build/
tar -zxvf opencv-4.3.0.tar.gz 
tar -zxvf opencv_contrib-4.3.0.tar.gz

3、Configure

cd /home/admin/opencv_4.3_build/opencv-4.3.0/

cmake .. \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_QT=ON \
-D WITH_GTK=ON \
-D WITH_OPENGL=ON \
-D WITH_VTK=ON \
-D OPENCV_GENERATE_PKGCONFIG=YES \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_DOCS=ON \
-D BUILD_EXAMPLES=ON \
-D PYTHON3_EXECUTABLE=/usr/bin/python3 \
-D PYTHON_INCLUDE_DIR=/usr/include/python3.8 \
-D PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.8.so \
-D OPENCV_EXTRA_MODULES_PATH=/home/admin/opencv_4.3_build/opencv-4.3.0/opencv_contrib-4.3.0/modules \
-D BUILD_EXAMPLES=ON

4、Build

(-j后面的数字代表多线程,请根据自己的电脑配置设置,官网默认为7)

make -j12

5、Install

sudo make install

6、验证安装

pkg-config --modversion opencv4
# 输出:4.3.0
python3 -c "import cv2; print(cv2.__version__)"
# 输出:4.3.0
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部