Ubuntu16.04+python2.7搭建opencv3.2.0

在安装opencv3.2.0的过程中,我遇到了好多坑,特此记录一下。建议安装了Anaconda的朋友们找一找网上的方法,直接利用它进行安装,可以避免很多坑。
下面结合参考的网上的教程,说一说我的安装过程和解决办法。

一、准备工作

提前下载好三个文件,https://github.com/hanxuan123/opencv3.2/tree/master/all,这里给出网上分享的一个链接(感谢)。包括opencv-3.2.0、ippicv_linux_20151201.tgz、opencv_contrib-3.2.0

二、安装依赖文件

这里每个人需要装的文件可能不同,我是根据https://blog.csdn.net/yifa3588/article/details/78284794这篇博客中给的依赖文件先安装的,之后再根据CMake的报告添加缺少的依赖文件
在终端输入

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

三、编译

3.1

首先将第一步中下载好的opencv-3.2.0解压到一个新的文件夹中,我的新文件夹命名为opencv3,opencv_contrib-3.2解压到opencv-3.2.0中,再在opencv-3.2.0中新建一个文件夹,命名为build,并在该文件下编译。

3.2

cd /home/software/opencv3/opencv-3.2.0/build  #这里根据自己的路径调整

3.3

cmake -D CMAKE_BUILD_TYPE=RELEASE \
 -D CMAKE_INSTALL_PREFIX=/usr/local \
 -D INSTALL_C_EXAMPLES=ON \
 -D OPENCV_EXTRA_MODULES_PATH=/home/software/opencv3/opencv-3.2.0/opencv_contrib-3.2.0/modules/  ..   #这里根据自己的路径调整, 注意最后的两个点

注意:这是重要的一步,这一步可能会出现各种各样的问题,要根据所遇到的问题,对症下药~在此附上我遇到的一些问题和解决办法,仅供参考。

...

Checking for module 'gstreamer-base-1.0'
--   No package 'gstreamer-base-1.0' found
-- Checking for module 'gstreamer-video-1.0'
--   No package 'gstreamer-video-1.0' found
-- Checking for module 'gstreamer-app-1.0'
--   No package 'gstreamer-app-1.0' found
-- Checking for module 'gstreamer-riff-1.0'
--   No package 'gstreamer-riff-1.0' found
-- Checking for module 'gstreamer-pbutils-1.0'
--   No package 'gstreamer-pbutils-1.0' found
-- Checking for module 'gstreamer-base-0.10'
--   Found gstreamer-base-0.10, version 0.10.36
-- Checking for module 'gstreamer-video-0.10'
--   No package 'gstreamer-video-0.10' found
-- Checking for module 'gstreamer-app-0.10'
--   No package 'gstreamer-app-0.10' found
-- Checking for module 'gstreamer-riff-0.10'
--   No package 'gstreamer-riff-0.10' found
-- Checking for module 'gstreamer-pbutils-0.10'
--   No package 'gstreamer-pbutils-0.10' found
-- Looking for linux/videodev.h
-- Looking for linux/videodev.h - not found
-- Looking for linux/videodev2.h
-- Looking for linux/videodev2.h - found
-- Looking for sys/videoio.h
-- Looking for sys/videoio.h - not found
-- Checking for module 'libavresample'
--   No package 'libavresample' found
-- Checking for module 'libgphoto2'
--   No package 'libgphoto2' found
-- found IPP (ICV version): 9.0.1 [9.0.1]
-- at: /home/elsa/software/opencv3/opencv-3.2.0/build/3rdparty/ippicv/ippicv_lnx
-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- Could NOT find Atlas (missing:  Atlas_CBLAS_INCLUDE_DIR Atlas_CLAPACK_INCLUDE_DIR Atlas_CBLAS_LIBRARY Atlas_BLAS_LIBRARY Atlas_LAPACK_LIBRARY) 
-- Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE) 
-- Could NOT find JNI (missing:  JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH) 
-- Could NOT find Matlab (missing:  MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIRS MATLAB_ROOT_DIR MATLAB_LIBRARIES MATLAB_LIBRARY_DIRS MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN) 
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
CMake Error at cmake/OpenCVModule.cmake:295 (message):
  No extra modules found in folder:
  /home/software/opencv3/opencv3.2.0/opencv_contrib-3.2.0/modules

  Please provide path to 'opencv_contrib/modules' folder.
Call Stack (most recent call first):
  modules/CMakeLists.txt:7 (ocv_glob_modules)


......


-- 
-- Configuring incomplete, errors occurred!
See also "/home/elsa/software/opencv3/opencv-3.2.0/build/CMakeFiles/CMakeOutput.log".
See also "/home/elsa/software/opencv3/opencv-3.2.0/build/CMakeFiles/CMakeError.log".

出现这种情况,基本上就是失败了,要根据提示挨个填坑了。

首先是安装缺少的依赖包
根据这些提示,

sudo apt-get install \
libgstreamer0.10-dev \ 
libgstreamer-plugins-base0.10-dev \ 
libgstreamer1.0-dev \ 
libgstreamer-plugins-base1.0-dev \ 
gstreamer-plugins-base-devel \
libgphoto2-dev \

当然,最好将cmake升级一下,不然也可能出现错误。

sudo apt-get install cmake

除此之外,还可能存在ippicv_linux_20151201.tgz下载失败的问题。这时候可以将第一步中我们提前下载好的该文件,移动到报告中提示的路径。
例如,报告称/opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/找不到该文件,我们就可以在新的终端中进行如下操作

sudo mv ippicv_linux_20151201.tgz /opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e 

之后可以新建终端,重新进行cmake

如果提示

-- Configuring done
-- Generating done 

则可以进行下一步
依次进行

sudo make
sudo make install

四、测试

这里我在python2.7.12下测试才成功,其他版本下测试 均提示找不到cv2 module
测试如下:

XXX:~$ python
Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
>>> quit()
XXXXX:~$ source activate python2.7
(python2.7) xxxxxxx:~$ python
Python 2.7.14 |Anaconda, Inc.| (default, Mar 27 2018, 17:29:31) 
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "", line 1, in <module>
ImportError: No module named cv2
>>> 
(python2.7) xxxxxxxx:~$ sudo python
[sudo] xxx的密码: 
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "", line 1, in <module>
ImportError: /lib/x86_64-linux-gnu/libz.so.1: version `ZLIB_1.2.9' not found (required by /home/software/anaconda3/lib/libpng16.so.16)
>>> 

根据提示,缺少了ZLIB,参考这里给的帮助
可以下载Zlib,然后依次执行:

tar -xvf ~/Downloads/zlib-1.2.9.tar.gz
cd zlib-1.2.9
sudo -s
./configure; make; make install
cd /lib/x86_64-linux-gnu
ln -s -f /usr/local/lib/libz.so.1.2.11/lib libz.so.1
cd ~
rm -rf zlib-1.2.11

附上下载地址戳这里~

过程如下:

XXXX:~$ tar -xvf ~/下载/zlib-1.2.11.tar.gz
zlib-1.2.11/
zlib-1.2.11/adler32.c
zlib-1.2.11/amiga/
zlib-1.2.11/ChangeLog
zlib-1.2.11/CMakeLists.txt
zlib-1.2.11/compress.c
zlib-1.2.11/configure
zlib-1.2.11/contrib/
zlib-1.2.11/crc32.c
zlib-1.2.11/crc32.h
zlib-1.2.11/deflate.c
zlib-1.2.11/deflate.h
zlib-1.2.11/doc/
zlib-1.2.11/examples/
zlib-1.2.11/FAQ
zlib-1.2.11/gzclose.c
zlib-1.2.11/gzguts.h
zlib-1.2.11/gzlib.c
zlib-1.2.11/gzread.c
zlib-1.2.11/gzwrite.c
zlib-1.2.11/INDEX
zlib-1.2.11/infback.c
zlib-1.2.11/inffast.c
zlib-1.2.11/inffast.h
zlib-1.2.11/inffixed.h
zlib-1.2.11/inflate.c
zlib-1.2.11/inflate.h
zlib-1.2.11/inftrees.c
zlib-1.2.11/inftrees.h
zlib-1.2.11/make_vms.com
zlib-1.2.11/Makefile
zlib-1.2.11/Makefile.in
zlib-1.2.11/msdos/
zlib-1.2.11/nintendods/
zlib-1.2.11/old/
zlib-1.2.11/os400/
zlib-1.2.11/qnx/
zlib-1.2.11/README
zlib-1.2.11/test/
zlib-1.2.11/treebuild.xml
zlib-1.2.11/trees.c
zlib-1.2.11/trees.h
zlib-1.2.11/uncompr.c
zlib-1.2.11/watcom/
zlib-1.2.11/win32/
zlib-1.2.11/zconf.h
zlib-1.2.11/zconf.h.cmakein
zlib-1.2.11/zconf.h.in
zlib-1.2.11/zlib.3
zlib-1.2.11/zlib.3.pdf
zlib-1.2.11/zlib.h
zlib-1.2.11/zlib.map
zlib-1.2.11/zlib.pc.cmakein
zlib-1.2.11/zlib.pc.in
zlib-1.2.11/zlib2ansi
zlib-1.2.11/zutil.c
zlib-1.2.11/zutil.h
zlib-1.2.11/win32/DLL_FAQ.txt
zlib-1.2.11/win32/Makefile.bor
zlib-1.2.11/win32/Makefile.gcc
zlib-1.2.11/win32/Makefile.msc
zlib-1.2.11/win32/README-WIN32.txt
zlib-1.2.11/win32/VisualC.txt
zlib-1.2.11/win32/zlib.def
zlib-1.2.11/win32/zlib1.rc
zlib-1.2.11/watcom/watcom_f.mak
zlib-1.2.11/watcom/watcom_l.mak
zlib-1.2.11/test/example.c
zlib-1.2.11/test/infcover.c
zlib-1.2.11/test/minigzip.c
zlib-1.2.11/qnx/package.qpg
zlib-1.2.11/os400/bndsrc
zlib-1.2.11/os400/make.sh
zlib-1.2.11/os400/README400
zlib-1.2.11/os400/zlib.inc
zlib-1.2.11/old/descrip.mms
zlib-1.2.11/old/Makefile.emx
zlib-1.2.11/old/Makefile.riscos
zlib-1.2.11/old/os2/
zlib-1.2.11/old/README
zlib-1.2.11/old/visual-basic.txt
zlib-1.2.11/old/os2/Makefile.os2
zlib-1.2.11/old/os2/zlib.def
zlib-1.2.11/nintendods/Makefile
zlib-1.2.11/nintendods/README
zlib-1.2.11/msdos/Makefile.bor
zlib-1.2.11/msdos/Makefile.dj2
zlib-1.2.11/msdos/Makefile.emx
zlib-1.2.11/msdos/Makefile.msc
zlib-1.2.11/msdos/Makefile.tc
zlib-1.2.11/examples/enough.c
zlib-1.2.11/examples/fitblk.c
zlib-1.2.11/examples/gun.c
zlib-1.2.11/examples/gzappend.c
zlib-1.2.11/examples/gzjoin.c
zlib-1.2.11/examples/gzlog.c
zlib-1.2.11/examples/gzlog.h
zlib-1.2.11/examples/README.examples
zlib-1.2.11/examples/zlib_how.html
zlib-1.2.11/examples/zpipe.c
zlib-1.2.11/examples/zran.c
zlib-1.2.11/doc/algorithm.txt
zlib-1.2.11/doc/rfc1950.txt
zlib-1.2.11/doc/rfc1951.txt
zlib-1.2.11/doc/rfc1952.txt
zlib-1.2.11/doc/txtvsbin.txt
zlib-1.2.11/contrib/ada/
zlib-1.2.11/contrib/amd64/
zlib-1.2.11/contrib/asm686/
zlib-1.2.11/contrib/blast/
zlib-1.2.11/contrib/delphi/
zlib-1.2.11/contrib/dotzlib/
zlib-1.2.11/contrib/gcc_gvmat64/
zlib-1.2.11/contrib/infback9/
zlib-1.2.11/contrib/inflate86/
zlib-1.2.11/contrib/iostream/
zlib-1.2.11/contrib/iostream2/
zlib-1.2.11/contrib/iostream3/
zlib-1.2.11/contrib/masmx64/
zlib-1.2.11/contrib/masmx86/
zlib-1.2.11/contrib/minizip/
zlib-1.2.11/contrib/pascal/
zlib-1.2.11/contrib/puff/
zlib-1.2.11/contrib/README.contrib
zlib-1.2.11/contrib/testzlib/
zlib-1.2.11/contrib/untgz/
zlib-1.2.11/contrib/vstudio/
zlib-1.2.11/contrib/vstudio/readme.txt
zlib-1.2.11/contrib/vstudio/vc10/
zlib-1.2.11/contrib/vstudio/vc11/
zlib-1.2.11/contrib/vstudio/vc12/
zlib-1.2.11/contrib/vstudio/vc14/
zlib-1.2.11/contrib/vstudio/vc9/
zlib-1.2.11/contrib/vstudio/vc9/miniunz.vcproj
zlib-1.2.11/contrib/vstudio/vc9/minizip.vcproj
zlib-1.2.11/contrib/vstudio/vc9/testzlib.vcproj
zlib-1.2.11/contrib/vstudio/vc9/testzlibdll.vcproj
zlib-1.2.11/contrib/vstudio/vc9/zlib.rc
zlib-1.2.11/contrib/vstudio/vc9/zlibstat.vcproj
zlib-1.2.11/contrib/vstudio/vc9/zlibvc.def
zlib-1.2.11/contrib/vstudio/vc9/zlibvc.sln
zlib-1.2.11/contrib/vstudio/vc9/zlibvc.vcproj
zlib-1.2.11/contrib/vstudio/vc14/miniunz.vcxproj
zlib-1.2.11/contrib/vstudio/vc14/minizip.vcxproj
zlib-1.2.11/contrib/vstudio/vc14/testzlib.vcxproj
zlib-1.2.11/contrib/vstudio/vc14/testzlibdll.vcxproj
zlib-1.2.11/contrib/vstudio/vc14/zlib.rc
zlib-1.2.11/contrib/vstudio/vc14/zlibstat.vcxproj
zlib-1.2.11/contrib/vstudio/vc14/zlibvc.def
zlib-1.2.11/contrib/vstudio/vc14/zlibvc.sln
zlib-1.2.11/contrib/vstudio/vc14/zlibvc.vcxproj
zlib-1.2.11/contrib/vstudio/vc12/miniunz.vcxproj
zlib-1.2.11/contrib/vstudio/vc12/minizip.vcxproj
zlib-1.2.11/contrib/vstudio/vc12/testzlib.vcxproj
zlib-1.2.11/contrib/vstudio/vc12/testzlibdll.vcxproj
zlib-1.2.11/contrib/vstudio/vc12/zlib.rc
zlib-1.2.11/contrib/vstudio/vc12/zlibstat.vcxproj
zlib-1.2.11/contrib/vstudio/vc12/zlibvc.def
zlib-1.2.11/contrib/vstudio/vc12/zlibvc.sln
zlib-1.2.11/contrib/vstudio/vc12/zlibvc.vcxproj
zlib-1.2.11/contrib/vstudio/vc11/miniunz.vcxproj
zlib-1.2.11/contrib/vstudio/vc11/minizip.vcxproj
zlib-1.2.11/contrib/vstudio/vc11/testzlib.vcxproj
zlib-1.2.11/contrib/vstudio/vc11/testzlibdll.vcxproj
zlib-1.2.11/contrib/vstudio/vc11/zlib.rc
zlib-1.2.11/contrib/vstudio/vc11/zlibstat.vcxproj
zlib-1.2.11/contrib/vstudio/vc11/zlibvc.def
zlib-1.2.11/contrib/vstudio/vc11/zlibvc.sln
zlib-1.2.11/contrib/vstudio/vc11/zlibvc.vcxproj
zlib-1.2.11/contrib/vstudio/vc10/miniunz.vcxproj
zlib-1.2.11/contrib/vstudio/vc10/miniunz.vcxproj.filters
zlib-1.2.11/contrib/vstudio/vc10/minizip.vcxproj
zlib-1.2.11/contrib/vstudio/vc10/minizip.vcxproj.filters
zlib-1.2.11/contrib/vstudio/vc10/testzlib.vcxproj
zlib-1.2.11/contrib/vstudio/vc10/testzlib.vcxproj.filters
zlib-1.2.11/contrib/vstudio/vc10/testzlibdll.vcxproj
zlib-1.2.11/contrib/vstudio/vc10/testzlibdll.vcxproj.filters
zlib-1.2.11/contrib/vstudio/vc10/zlib.rc
zlib-1.2.11/contrib/vstudio/vc10/zlibstat.vcxproj
zlib-1.2.11/contrib/vstudio/vc10/zlibstat.vcxproj.filters
zlib-1.2.11/contrib/vstudio/vc10/zlibvc.def
zlib-1.2.11/contrib/vstudio/vc10/zlibvc.sln
zlib-1.2.11/contrib/vstudio/vc10/zlibvc.vcxproj
zlib-1.2.11/contrib/vstudio/vc10/zlibvc.vcxproj.filters
zlib-1.2.11/contrib/untgz/Makefile
zlib-1.2.11/contrib/untgz/Makefile.msc
zlib-1.2.11/contrib/untgz/untgz.c
zlib-1.2.11/contrib/testzlib/testzlib.c
zlib-1.2.11/contrib/testzlib/testzlib.txt
zlib-1.2.11/contrib/puff/Makefile
zlib-1.2.11/contrib/puff/puff.c
zlib-1.2.11/contrib/puff/puff.h
zlib-1.2.11/contrib/puff/pufftest.c
zlib-1.2.11/contrib/puff/README
zlib-1.2.11/contrib/puff/zeros.raw
zlib-1.2.11/contrib/pascal/example.pas
zlib-1.2.11/contrib/pascal/readme.txt
zlib-1.2.11/contrib/pascal/zlibd32.mak
zlib-1.2.11/contrib/pascal/zlibpas.pas
zlib-1.2.11/contrib/minizip/configure.ac
zlib-1.2.11/contrib/minizip/crypt.h
zlib-1.2.11/contrib/minizip/ioapi.c
zlib-1.2.11/contrib/minizip/ioapi.h
zlib-1.2.11/contrib/minizip/iowin32.c
zlib-1.2.11/contrib/minizip/iowin32.h
zlib-1.2.11/contrib/minizip/make_vms.com
zlib-1.2.11/contrib/minizip/Makefile
zlib-1.2.11/contrib/minizip/Makefile.am
zlib-1.2.11/contrib/minizip/miniunz.c
zlib-1.2.11/contrib/minizip/miniunzip.1
zlib-1.2.11/contrib/minizip/minizip.1
zlib-1.2.11/contrib/minizip/minizip.c
zlib-1.2.11/contrib/minizip/minizip.pc.in
zlib-1.2.11/contrib/minizip/MiniZip64_Changes.txt
zlib-1.2.11/contrib/minizip/MiniZip64_info.txt
zlib-1.2.11/contrib/minizip/mztools.c
zlib-1.2.11/contrib/minizip/mztools.h
zlib-1.2.11/contrib/minizip/unzip.c
zlib-1.2.11/contrib/minizip/unzip.h
zlib-1.2.11/contrib/minizip/zip.c
zlib-1.2.11/contrib/minizip/zip.h
zlib-1.2.11/contrib/masmx86/bld_ml32.bat
zlib-1.2.11/contrib/masmx86/inffas32.asm
zlib-1.2.11/contrib/masmx86/match686.asm
zlib-1.2.11/contrib/masmx86/readme.txt
zlib-1.2.11/contrib/masmx64/bld_ml64.bat
zlib-1.2.11/contrib/masmx64/gvmat64.asm
zlib-1.2.11/contrib/masmx64/inffas8664.c
zlib-1.2.11/contrib/masmx64/inffasx64.asm
zlib-1.2.11/contrib/masmx64/readme.txt
zlib-1.2.11/contrib/iostream3/README
zlib-1.2.11/contrib/iostream3/test.cc
zlib-1.2.11/contrib/iostream3/TODO
zlib-1.2.11/contrib/iostream3/zfstream.cc
zlib-1.2.11/contrib/iostream3/zfstream.h
zlib-1.2.11/contrib/iostream2/zstream.h
zlib-1.2.11/contrib/iostream2/zstream_test.cpp
zlib-1.2.11/contrib/iostream/test.cpp
zlib-1.2.11/contrib/iostream/zfstream.cpp
zlib-1.2.11/contrib/iostream/zfstream.h
zlib-1.2.11/contrib/inflate86/inffas86.c
zlib-1.2.11/contrib/inflate86/inffast.S
zlib-1.2.11/contrib/infback9/infback9.c
zlib-1.2.11/contrib/infback9/infback9.h
zlib-1.2.11/contrib/infback9/inffix9.h
zlib-1.2.11/contrib/infback9/inflate9.h
zlib-1.2.11/contrib/infback9/inftree9.c
zlib-1.2.11/contrib/infback9/inftree9.h
zlib-1.2.11/contrib/infback9/README
zlib-1.2.11/contrib/gcc_gvmat64/gvmat64.S
zlib-1.2.11/contrib/dotzlib/DotZLib/
zlib-1.2.11/contrib/dotzlib/DotZLib.build
zlib-1.2.11/contrib/dotzlib/DotZLib.chm
zlib-1.2.11/contrib/dotzlib/DotZLib.sln
zlib-1.2.11/contrib/dotzlib/LICENSE_1_0.txt
zlib-1.2.11/contrib/dotzlib/readme.txt
zlib-1.2.11/contrib/dotzlib/DotZLib/AssemblyInfo.cs
zlib-1.2.11/contrib/dotzlib/DotZLib/ChecksumImpl.cs
zlib-1.2.11/contrib/dotzlib/DotZLib/CircularBuffer.cs
zlib-1.2.11/contrib/dotzlib/DotZLib/CodecBase.cs
zlib-1.2.11/contrib/dotzlib/DotZLib/Deflater.cs
zlib-1.2.11/contrib/dotzlib/DotZLib/DotZLib.cs
zlib-1.2.11/contrib/dotzlib/DotZLib/DotZLib.csproj
zlib-1.2.11/contrib/dotzlib/DotZLib/GZipStream.cs
zlib-1.2.11/contrib/dotzlib/DotZLib/Inflater.cs
zlib-1.2.11/contrib/dotzlib/DotZLib/UnitTests.cs
zlib-1.2.11/contrib/delphi/readme.txt
zlib-1.2.11/contrib/delphi/ZLib.pas
zlib-1.2.11/contrib/delphi/ZLibConst.pas
zlib-1.2.11/contrib/delphi/zlibd32.mak
zlib-1.2.11/contrib/blast/blast.c
zlib-1.2.11/contrib/blast/blast.h
zlib-1.2.11/contrib/blast/Makefile
zlib-1.2.11/contrib/blast/README
zlib-1.2.11/contrib/blast/test.pk
zlib-1.2.11/contrib/blast/test.txt
zlib-1.2.11/contrib/asm686/match.S
zlib-1.2.11/contrib/asm686/README.686
zlib-1.2.11/contrib/amd64/amd64-match.S
zlib-1.2.11/contrib/ada/buffer_demo.adb
zlib-1.2.11/contrib/ada/mtest.adb
zlib-1.2.11/contrib/ada/read.adb
zlib-1.2.11/contrib/ada/readme.txt
zlib-1.2.11/contrib/ada/test.adb
zlib-1.2.11/contrib/ada/zlib-streams.adb
zlib-1.2.11/contrib/ada/zlib-streams.ads
zlib-1.2.11/contrib/ada/zlib-thin.adb
zlib-1.2.11/contrib/ada/zlib-thin.ads
zlib-1.2.11/contrib/ada/zlib.adb
zlib-1.2.11/contrib/ada/zlib.ads
zlib-1.2.11/contrib/ada/zlib.gpr
zlib-1.2.11/amiga/Makefile.pup
zlib-1.2.11/amiga/Makefile.sas
XXXX:~$ cd zlib-1.2.11
XXXX:~/zlib-1.2.11$ sudo -s
[sudo] XXXX 的密码: 
root@XXXX:~/zlib-1.2.11# ./configure; make; make install
Checking for gcc...
Checking for shared library support...
Building shared library libz.so.1.2.11 with gcc.
Checking for size_t... Yes.
Checking for off64_t... Yes.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I. -c -o example.o test/example.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o adler32.o adler32.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o crc32.o crc32.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o deflate.o deflate.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o infback.o infback.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o inffast.o inffast.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o inflate.o inflate.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o inftrees.o inftrees.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o trees.o trees.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o zutil.o zutil.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o compress.o compress.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o uncompr.o uncompr.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o gzclose.o gzclose.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o gzlib.o gzlib.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o gzread.o gzread.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o gzwrite.o gzwrite.c
ar rc libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o 
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o example example.o -L. libz.a
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I. -c -o minigzip.o test/minigzip.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o minigzip minigzip.o -L. libz.a
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/adler32.o adler32.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/crc32.o crc32.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/deflate.o deflate.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/infback.o infback.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/inffast.o inffast.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/inflate.o inflate.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/inftrees.o inftrees.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/trees.o trees.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/zutil.o zutil.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/compress.o compress.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/uncompr.o uncompr.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/gzclose.o gzclose.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/gzlib.o gzlib.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/gzread.o gzread.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -DPIC -c -o objs/gzwrite.o gzwrite.c
gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o libz.so.1.2.11 adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo  -lc 
rm -f libz.so libz.so.1
ln -s libz.so.1.2.11 libz.so
ln -s libz.so.1.2.11 libz.so.1
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o examplesh example.o -L. libz.so.1.2.11
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o minigzipsh minigzip.o -L. libz.so.1.2.11
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I. -D_FILE_OFFSET_BITS=64 -c -o example64.o test/example.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o example64 example64.o -L. libz.a
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I. -D_FILE_OFFSET_BITS=64 -c -o minigzip64.o test/minigzip.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o minigzip64 minigzip64.o -L. libz.a
rm -f /usr/local/lib/libz.a
cp libz.a /usr/local/lib
chmod 644 /usr/local/lib/libz.a
cp libz.so.1.2.11 /usr/local/lib
chmod 755 /usr/local/lib/libz.so.1.2.11
rm -f /usr/local/share/man/man3/zlib.3
cp zlib.3 /usr/local/share/man/man3
chmod 644 /usr/local/share/man/man3/zlib.3
rm -f /usr/local/lib/pkgconfig/zlib.pc
cp zlib.pc /usr/local/lib/pkgconfig
chmod 644 /usr/local/lib/pkgconfig/zlib.pc
rm -f /usr/local/include/zlib.h /usr/local/include/zconf.h
cp zlib.h zconf.h /usr/local/include
chmod 644 /usr/local/include/zlib.h /usr/local/include/zconf.h
root@XXXX:~/zlib-1.2.11# cd /lib/x86_64-linux-gnu
root@XXXX:/lib/x86_64-linux-gnu# ln -s -f /usr/local/lib/libz.so.1.2.9/lib libz.so.1
root@XXXX:/lib/x86_64-linux-gnu# cd ~
root@XXXX:~# rm -rf zlib-1.2.11

此外,如果出现如下问题:

>>> import cv2
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
Traceback (most recent call last):
  File "", line 1, in <module>
ImportError: numpy.core.multiarray failed to import

则可能是因为numpy和opencv2版本不合,可以先 pip install -U numpy 再重新测试

这时再测试就ok啦

XXXX:~$ sudo python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.2.0'
>>> 

五、配置python3的opencv

该地址提供了一种在已经配置了python2和opencv的情况下,再配python3的方法
还未尝试,留待之后亲测后再来完善本篇。在这分享给大家,有需要可以自行尝试。

你可能感兴趣的:(安装配置)