ubuntu16.04安装opencv3.1.0(包含opencv_contrib模块)

整理自http://blog.csdn.net/yehuohan/article/details/51327465

1、安装依赖库

sudo apt-get install build-essential
# 必须的,gcc编译环境

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
# 必须的,包括cmake等工具

sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
# 可选的,看个人需要,总共5M左右

2、从官网下载 源码
在官网下载:http://opencv.org/downloads.html
或着用git clone:

cd ~/opencv310
    # opencv310为自己建的,源码将放在这里
git clone https://github.com/Itseez/opencv.git
git clone https://github.com/Itseez/opencv_contrib.git

3、cmake
解压opencv-3.1.0.zip

cd opencv-3.1.0
mkdir build

cmake时ippicv_linux_20151201.tgz总是不能成功下载,故cmake之前将
./downloads/linux-808b791a6eac9ed78d32a7666804320e 文件拷贝至
./opencv-3.1.0/3rdparty/ippicv/ 路径下
(先执行一次cmake 命令生成文件路径,在将ippicv_linux_20151201.tgz复制进去)
ippicv_linux_20151201.tgz下载链接: https://pan.baidu.com/s/1hWwR8VtHRwKNRmOilskmwA 密码: kvdz

cd opencv-3.1.0/build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
# 生成后的Makefile在build文件夹中,而需要的CMakeLists.txt在 ".."中,即上一级文件夹中(opencv-3.1.0)

ubuntu16.04安装opencv3.1.0(包含opencv_contrib模块)_第1张图片

如果要安装包含opencv_contrib模块的,则执行以下语句:
把opencv_contrib-master.zip放在opencv-3.1.0下,解压

cd opencv-3.1.0/build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-master/modules/ ..
# “../opencv_contrib-master/modules/是opencv_contrib-master解压后的路径

报错了
ubuntu16.04安装opencv3.1.0(包含opencv_contrib模块)_第2张图片

4、安装opencv
在opencv3.1.0/build下

# 4个线程编译,查看cpu核数量
# grep "model name" /proc/cpuinfo | wc -l 
make -j4

# 安装
sudo make install

测试安装是否成功,查看这篇:
ubuntu opencv3.1 编译demo报错 http://blog.csdn.net/u011440558/article/details/78213796

ubuntu 14.04 64位安装Opencv3.1.0+包含opencv_contrib模块

http://blog.csdn.net/jay463261929/article/details/53197228
报错:fatal error hdf5.h no such file or directory
这里写图片描述
解决办法:
在opencv-3.1.0/modules/python/common.cmake首行添加如下代码:

find_package(HDF5)
include_directories(${HDF5_INCLUDE_DIRS})

OK…
参考:https://github.com/opencv/opencv/issues/6016

opencv添加软连接到virtualenv环境

参考http://blog.csdn.net/isuker/article/details/52459992

安装pip和virtualenv:

sudo apt-get install python-pip python-dev python-virtualenv

创建 Virtualenv 虚拟环境:

virtualenv --no-site-packages seg-env

将 cv.py cv2.so文件连接到虚拟环境:
这里写图片描述

ln -s /usr/local/lib/python2.7/dist-packages/cv2.so /home/ly/seg-env/lib/python2.7/site-packages 

ubuntu16.04安装opencv3.1.0(包含opencv_contrib模块)_第3张图片
OK…

Ubuntu14.04 64位+Python3.4环境下安装opencv3.0的方法

http://blog.csdn.net/qingyuanluofeng/article/details/51558270

opencv3.2在安装CUDA后cmake报错:

参考:https://blog.csdn.net/CV_YOU/article/details/79950671
打开opencv文件下面的CMakelis.txt文件,将里面有关cuda选项都调为OFF(然后将有cuda有关的判断操作给注释了)。

cmake -D WITH_LAPACK=OFF -D CMAKE_BUILD_TYPE=RELEASE -D WITH_TBB=ON -D BUILD_opencv_gpu=OFF -D CUDA_GENERATION=Kepler -D WITH_V4L=ON -D CUDA_ARCH_BIN=6.1 -D CUDA_ARCH_PTX=6.1 -D CMAKE_INSTALL_PREFIX=/usr/local/opencv320 ..

卸载opencv

卸载opencv3.1.0: Going to the "build" folder directory of opencv from terminal, and execute the following:

1. $ sudo make uninstall
2. $ cd ..
3. $ sudo rm -r build
4. $ sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*
5. sudo apt-get –purge remove opencv-doc opencv-data python-opencv

你可能感兴趣的:(Linux)