0


Ubuntu 20.04 安装opencv 和 +opencv_contrib教程

首先opencv和opencv_contrib下载版本要一致!!!!

我是以opencv3.4.5为例

opencv下载官网:Releases - OpenCV

opencv_contirb网址:GitHub - opencv/opencv_contrib: Repository for OpenCV's extra modules

源地址:GitHub - opencv/opencv_contrib: Repository for OpenCV's extra modules

以上即是在Ubuntu上下载好opencv和opencv_contrib

安装开始:

1 先跟新一下:

  1. sudo apt-get update
  2. sudo apt-get upgrade

2 安装一下依赖包

sudo apt-get install build-essential

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

3.解压下载好的包:
sudo unzip opencv-3.4.5.zip
sudo unzip opencv_contrib-3.4.5.zip

4.解压完后需要将opencv_contrib-3.4.5.zip提取到opencv-3.4.5目录下,同时在该目录下新建一个文件夹build
sudo cp -r opencv_contrib-3.4.5 opencv-3.4.5 #复制opencv_contrib到opencv目录下

cd opencv-3.4.5

sudo mkdir build #新建文件夹build

5 cd build(进入build文件夹)

cmake -D CMAKE_BUILD_TYPE=Release

-D** OPENCV_GENERATE_PKGCONFIG=ON**

-D CMAKE_INSTALL_PREFIX=/usr/local ..

-D OPENCV_EXTRA_MODULES_PATH=/home///opencv_contrib/modules ..

解释:带星号就是你opencv_contrib/modules的绝对路径 可以进入到opencv_contrib/modules中打开终端输入:pwd即可查询。

6 进行编译:make -j4

重要:如果缺少文件或者是报路径相关的错误,可以打开下面的链接看一下:

https://blog.csdn.net/bj233/article/details/113351023

make后:sudo make install

7 配置环境变量

1)安装成功后还需要设置opencv的环境变量。打开文件:

sudo gedit /etc/ld.so.conf.d/opencv.conf

(2)将空白文档中添加以下内容:

     /usr/local/lib

(3)接下来配置库:

sudo ldconfig

(4)更改环境变量:

sudo gedit /etc/bash.bashrc

(5)在文件后添加:

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

(6)保存退出,终端输入:

source /etc/bash.bashrc

至此,opencv及opencv_contrib安装配置完成了!

8 测试

进入opencv/samples/cpp/example_cmake目录下,终端打开,依次输入:

cmake .
make
./opencv_example

出现这个图像就圆满结束了,不过我是配置的c++的

参考 https://blog.csdn.net/fengxinzioo/article/details/88740915

     https://blog.csdn.net/bj233/article/details/113351023

本文转载自: https://blog.csdn.net/m0_73349585/article/details/127948468
版权归原作者 m0_73349585 所有, 如有侵权,请联系我们删除。

“Ubuntu 20.04 安装opencv 和 +opencv_contrib教程”的评论:

还没有评论