Ubuntu16.04下编译安装OpenCV3.4.0(C++ & python)

Ubuntu16.04下编译安装OpenCV3.4.0(C++ & python)

前提是已经安装了python2,python3

1)安装各种依赖库

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

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev

sudo apt-get install libxvidcore-dev libx264-dev

sudo apt-get install libatlas-base-dev gfortran

sudo apt-get install ffmpeg

2) 下载 opencv 源码

https://github.com/opencv/opencv/releases

选择最新(或自己喜欢的)版本,然后减压

3)编译安装

cd ~/opencv-3.4.0

mkdir build

cd build

配置

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

编译安装

make -j4

sudo make install

测试

import cv2

print(cv2.version)

3.4.0

错误

IPPICV: Download failed: 28;"Timeout was reached"

1) 下载ippicv_2017u3_lnx_intel64_general_20170822.tgz,结果下载失败

解决办法是重复试一下,一般都会下载成功。

如果一直失败则

1)手动下载ippicv库

https://github.com/opencv/opencv_3rdparty/pull/22/commits/dfe3162c237af211e98b8960018b564bc209261d

2) 将文件拷贝到opencv-3.4.0同级目录

3)执行如下命令

 ipp_file=ippicv_2017u3_lnx_intel64_general_20170822.tgz &&
ipp_hash=$(md5sum ../$ipp_file | cut -d" " -f1) &&
ipp_dir=.cache/ippicv && mkdir -p $ipp_dir &&
cp ../$ipp_file $ipp_dir/$ipp_hash-$ipp_file
上一篇:HDU - 4511 小明系列故事――女友的考验(AC自己主动机+DP)


下一篇:参数为json格式的接口