ubuntu 16.04 安装opencv 3.4.0

Posted feng_dream

tags:

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

官网手册中的说明基本上是比较全的,这里主要记录下安装过程,以及编译选项 多看官方手册,少走弯路 官网安装说明:https://docs.opencv.org/3.4.0/d7/d9f/tutorial_linux_install.html

环境: Ubuntu 16.04 64bit ,openCV 3.4.0

一、安装opencv依赖包

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 The packages can be installed using a terminal and the following commands or by using Synaptic Manager:

[compiler] sudo apt-get install build-essential [required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev [optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

二、安装numpy(如果需要python使用)

这里用的使用python3,所以是pip3命令,如果用python2,直接改为pip命令即可

pip3 install numpy

三、下载opencv3.4.0

需要下载opencv和opencv_contrib(后者会在cmake配置的时候用到),这是因为opencv3以后SIFT和SURF之类的属性被移到了contrib中 下载地址:

https://opencv.org/releases.html

https://github.com/opencv/opencv_contrib/tree/3.4.0

四、安装opencv3.4.0

1.配置选项

cd opencv-3.4.0/

mkdir build

cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D INSTALL_PYTHON_EXAMPLES=ON
-D INSTALL_C_EXAMPLES=ON
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.0/modules
-D PYTHON_EXECUTABLE=/usr/bin/python3
-D BUILD_EXAMPLES=ON ..

2.编译

make -j4

-j4表示四核运算,可根据电脑配置选择 如果出现错误,改为单核执行

make clean

make

3.安装

sudo make install







以上是关于ubuntu 16.04 安装opencv 3.4.0的主要内容,如果未能解决你的问题,请参考以下文章

Linux ubuntu16.04 安装opencv4教程(源码编译)

ubuntu16.04上opencv安装

Ubuntu16.04安装opencv for python/c++

ubuntu16.04 python opencv2.4.9安装

ubuntu16.04下基于Python的OpenCV的安装

如何安装 OpenCV 3.3.1。跟踪 API (Ubuntu 16.04)