Ubuntu16.04下在Python3.5安装OpenCV3.3.1

Ubuntu16.04下在Python3.5安装OpenCV3.3.1

安装过程(官网安装教程  https://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html):

1. 用Ctrl+Alt+T打开终端,输入下述命令,安装OpenCV3.3.1的依赖包

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

2. 安装OpenCV3.3.1

(1)下载opencv和opencv_contrib,在刚才的终端中输入:

git clone https://github.com/opencv/opencv.git
去下载对应版本的opencv_contrib

会在home中发现有opencv和opencv_contrib两个文件夹,则下载成功

(2)用cmake配置属性(cpu版):

首先文件夹opencv新建一个build文件夹

cd ~/opencv
mkdir build
cd build   #打开build文件夹

配置编译opencv

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local  -D INSTALL_C_EXAMPLES=ON  -D PYTHON3_EXECUTABLE=/usr/bin/python3 -D PYTHON_INCLUDE_DIR=/usr/include/python3.5 -D PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so -D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.5/dist-packages/numpy/core/include -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D OPENCV_EXTRA_MODULES_PATH=/data1/storage_proxy/deeplearning/dl_project/inceptionv3/data/opencv-3.1.0/opencv_contrib/modules -D PYTHON_EXECUTABLE=/usr/lib/python3 -D BUILD_EXAMPLES=ON -D CMAKE_LIBRARY_PATH=/usr/local/cuda-8.0/lib64/stubs -D CUDA_CUDA_LIBRARY=/usr/local/cuda-8.0/lib64/stubs/libcuda.so ..

运行后显示:

该步成功,之后输入:

make -j7 # 7个任务并行,加快安装(亲测,如果输入的是make-j,电脑安装慢,还死机了,导致安装失败)

sudo make install

至此,安装完成

如想要查询安装的版本

输入:

python3

import cv2

cv2.__version__

可以得到:

错误1:samples/gpu/CMakeFiles/example_gpu_hog.dir/build.make:122: recipe for target

这是因为编译的时候没有加入cuda-8.0路径

解决办法:cmake的时候加入-D CMAKE_LIBRARY_PATH=/usr/local/cuda-8.0/lib64/stubs -D CUDA_CUDA_LIBRARY=/usr/local/cuda-8.0/lib64/stubs/libcuda.so ..

错误2:In file included from /home/avtomaton/arbeit/sdk/cxx/opencv/build/modules/python2/pyopencv_generated_include.h:11:0,
from /home/avtomaton/arbeit/sdk/cxx/opencv/modules/python/src2/cv2.cpp:12:

/home/avtomaton/arbeit/sdk/cxx/opencv_contrib/modules/hdf/include/opencv2/hdf/hdf5.hpp:40:18: fatal error: hdf5.h: No such file or directory

解决办法:into modules/python/common.cmake

 

# This file is included from a subdirectory
set(PYTHON_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../")

ocv_add_module(${MODULE_NAME} BINDINGS)

became

# This file is included from a subdirectory
set(PYTHON_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../")

find_package(HDF5)
include_directories(${HDF5_INCLUDE_DIRS})

ocv_add_module(${MODULE_NAME} BINDINGS)

参考链接:

1. Ubuntu16.04下安装OpenCV3.2.0 - Arkenstone - 博客园    http://www.cnblogs.com/arkenstone/p/6490017.html

2. OpenCV: Installation in Linux    https://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html

你可能感兴趣的:(图像处理)