Ubuntu18.04安装opencv和opencv_contrib

Ubuntu18.04安装opencv和opencv_contrib

目录

Ubuntu18.04安装opencv和opencv_contrib

1. 版本

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

(1) 下载opencv和opencv_contrib源码

(2) 安装 OpenCV相关依赖库

(3) 源码编译

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’未定义的引用


Ubuntu18.04安装opencv和opencv_contrib_第1张图片

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


1. 版本

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

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

opencv

opencv-4.3.0 4.3.0 opencv-3.2.0以上亦可
opencv_contrib opencv_contrib-4.3.0 4.3.0  opencv_contrib-3.2.0以上亦可

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

(1) 下载opencv和opencv_contrib源码

  • opencv-4.3.0:Release OpenCV 4.3.0 · opencv/opencv · GitHub
  • opencv_contrib-4.3.0:Release 4.3.0 · opencv/opencv_contrib · GitHub

(2) 安装 OpenCV相关依赖库

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

sudo apt-get 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 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,用于保存输出,命令行如下:

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

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

#opencv_contrib的modules文件夹所在的路径
opencv_contrib=/home/dm/app/opencv_contrib-4.3.0/modules

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

Ubuntu18.04安装opencv和opencv_contrib_第2张图片

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

Ubuntu18.04安装opencv和opencv_contrib_第3张图片

 最后开始编译并安装opencv

make -j4
sudo make install

3.一些异常处理

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

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

   # 解压tar -zxvf tiff-4.0.4.tar.gz
   # 进入tiff目录
   ./configure
   make
   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 ..

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

你可能感兴趣的:(OpenCV,opencv,opencv_contrib,编译opencv,安装opencv)