当前位置:   article > 正文

Ubuntu18.04安装opencv和opencv_contrib_ubuntu18 opencv 安装

ubuntu18 opencv 安装

Ubuntu18.04安装opencv和opencv_contrib

目录

Ubuntu18.04安装opencv和opencv_contrib

1. 版本

2.源码编译和安装opencv和opencv_contrib

(1) 下载opencv和opencv_contrib源码

(2) 安装 OpenCV相关依赖库

(3) 源码编译

(4) android studio中使用opencv_contrib

3.一些异常处理

1.undefined reference to `TIFFReadDirectory@LIBTIFF_4.0'

2.usr/lib/x86_64-linux-gnu/libvtkIOImage-6.3.so.6.3:对‘TIFFReadDirectory@LIBTIFF_4.0’未定义的引用

4.Windows安装opencv和opencv_contrib


尊重原创,转载请注明出处https://blog.csdn.net/guyuealian/article/details/127400841


1. 版本

以安装opencv-4.3.0和opencv_contrib-4.3.0为例子,其他版本编译原则上步骤一样,但需确保opencv和opencv_contrib的版本号一致,避免版本差异导致编译错误。

本地使用版本下载地址说明
UbuntuUbuntu18.04-本机系统

opencv

opencv-4.3.04.3.0opencv-3.2.0以上亦可
opencv_contribopencv_contrib-4.3.04.3.0 opencv_contrib-3.2.0以上亦可

2.源码编译和安装opencv和opencv_contrib

(1) 下载opencv和opencv_contrib源码

(2) 安装 OpenCV相关依赖库

首先安装 OpenCV 所需要的依赖库,在终端依次执行以下命令:

  1. sudo apt-get update
  2. sudo apt-get install build-essential
  3. sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
  4. sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

(3) 源码编译

解压 opencv-4.3.0和opencv_contrib-4.3.0目录,然后进入到 opencv4.3.0 的目录,新建一个目录build,用于保存输出,命令行如下:

  1. # 新建一个目录build,用于保存输出
  2. mkdir build
  3. cd build

配置 OpenCV 工程文件,其中opencv_contrib填写你自己opencv_contrib-4.3.0中的modules文件夹所在的路径:

  1. #opencv_contrib的modules文件夹所在的路径
  2. opencv_contrib=/home/dm/app/opencv_contrib-4.3.0/modules
  3. cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=$opencv_contrib ..

cmake完成后,会输出类似如下的信息:

 最后开始编译并安装opencv

  1. make -j4
  2. sudo make install

(4) android studio中使用opencv_contrib

GitHub - chaoyangnz/opencv3-android-sdk-with-contrib: Build OpenCV3 Android SDK with contrib modules


3.一些异常处理

1.undefined reference to `TIFFReadDirectory@LIBTIFF_4.0'

 安装TIFF 下载地址:Index of /libtiff/ ,tiff-4.0.4.tar.gz (tiff-4.0.x以上亦可)

  1.    # 解压tar -zxvf tiff-4.0.4.tar.gz
  2.    # 进入tiff目录
  3.    ./configure
  4.    make
  5.    sudo make install

然后,重新编译opencv,并加上编译选项:-D BUILD_TIFF=ON

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_TIFF=ON  -D OPENCV_EXTRA_MODULES_PATH=$opencv_contrib ..

2.usr/lib/x86_64-linux-gnu/libvtkIOImage-6.3.so.6.3:对‘TIFFReadDirectory@LIBTIFF_4.0’未定义的引用

 可能是跟本地anaconda安装的库有冲突,可以先把anaconda的路径注释掉,再重新编译,参考:https://github.com/lagadic/visp/issues/109

确保安装了tiff库,新编译opencv,并加上编译选项:-D WITH_VTK=OFF -D BUILD_TIFF=ON

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_VTK=OFF -D BUILD_TIFF=ON  -D OPENCV_EXTRA_MODULES_PATH=$opencv_contrib ..

4.Windows安装opencv和opencv_contrib

 Windows opencv安装教程,请参考文章:Visual Studio 2017环境cmake编译opencv 4.3.0+opencv_contrib 4.3.0

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/119884
推荐阅读
相关标签
  

闽ICP备14008679号