Ubuntu20.04 安装 Opencv4.4.0

文章目录

  • 1、更新系统,安装必要的包
  • 2、新建目录,下载包
  • 3、Configure
  • 4、Build
  • 5、Install

1、更新系统,安装必要的包

 sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
 sudo apt update
 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-is-python3 python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper1 libjasper-dev libdc1394-22-dev

2、新建目录,下载包

 mkdir ~/opencv && cd ~/opencv
 git clone https://gitee.com/yxd.osc.com/opencv.git
 git clone https://gitee.com/yxd.osc.com/opencv_contrib.git
 mkdir build && cd build

(opencv和opencv_contrib来自官网的github,github下载太慢所以导入到gitee中下载,而且修复了编译过程中的两个bug,放心使用!!!)

3、Configure

注意:根据自己的路径调整以下命令

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ../opencv -DOPENCV_EXTRA_MODULES_PATH=/home/bbnc/opencv/opencv_contrib/modules -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 PYTHON3_NUMPY_INCLUDE_DIRS=/home/bbnc/.local/lib/python3.8/site-packages/numpy/core/include -DOPENCV_GENERATE_PKGCONFIG=ON

(官网提示:如果不能执行,去掉-D后面的空格,BUILD_DOCS和BUILD_EXAMPLES的设置不确定正确与否。反正我是顺利执行成功了。)

4、Build

make -j14

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

5、Install

sudo make install

你可能感兴趣的:(Linux,ubuntu,opencv)