Linux(Ubuntu 18.04)中安装OpenCV + OpenCV_Contrib

Posted zzy1024

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux(Ubuntu 18.04)中安装OpenCV + OpenCV_Contrib相关的知识,希望对你有一定的参考价值。

从github中down下OPenCV + OpenCV_Contrib库,可以从https://github.com/opencv上下载(注意版本对应)

cd ~/<my_working_directory>
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

将opencv_contrib目录移到opencv目录下

添加opencv所需要的依赖库:

Required Packages

  • GCC 4.4.x or later
  • CMake 2.8.7 or higher
  • Git
  • GTK+2.x or higher, including headers (libgtk2.0-dev)
  • pkg-config
  • Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
  • ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev(一些开发用视频解码)
  • [optional] libtbb2 libtbb-dev
  • [optional] libdc1394 2.x
  • [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
  • [optional] CUDA Toolkit 6.5 or higher
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

在使用命令

    sudo apt-get install libjaster-dev

出现:errorE: unable to locate libjasper-dev时,执行

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update

 

进入opencv文件夹,打开terminal

mkdir build
cd build

cmake编译(后面的两个点不能丢)

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

技术图片

make -j8

技术图片

python
import cv2

如果出现"No module named cv2",请执行

sudo apt-get install python-opencv

 

以上是关于Linux(Ubuntu 18.04)中安装OpenCV + OpenCV_Contrib的主要内容,如果未能解决你的问题,请参考以下文章

无法在 ubuntu 18.04 中安装 web3

ubuntu18.04中安装iNode

Ubuntu 18.04 版本中安装mysql 8的方法

sh 如何在Ubuntu(18.04)中安装和设置mongodb?

Ubuntu 18.04中安装搜狗拼音

Ubuntu18.04中安装virtualenv和virtualenvwrapper