opencv 3.2.0

来源:互联网 发布:编译java的软件 编辑:程序博客网 时间:2024/06/10 18:15

Opencv installation

1.Download 

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

  https://github.com/opencv/opencv_contrib/releases/tag/3.2.0

  https://github.com/opencv/opencv_extra/releases/tag/3.2.0


2.Reference tools installation :

      2.1 Protobuf installation

a)Download from https://github.com/google/protobuf           I choose 3.1.2

b)Use c++ compile, read  src/README.md

c)sudo apt-get install autoconf automake libtool curl make g++ unzip

d)build:

./autogen.sh

./configure./configure
make
make check
sudo make install
sudo ldconfig

e) To verify  protobuffer version : protoc --version


注意tensorflow

2.2 Caffe installation

http://caffe.berkeleyvision.org/install_apt.html

sudo apt-get install  libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev sudo apt-get install --no-install-recommends libboost-all-dev

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

#libprotobuf-dev 
#protobuf-compiler老是遇到 error This file was generated by a newer version of protoc , 发现是版本过多:dpkg --list |grep protobuf,卸载对应的

CUDA: Install by apt-get or the NVIDIA.run package.The NVIDIA package tends to follow more recent library and driver versions, but the installation is more manual.If installing from packages, install the library and latest driver separately; the driver bundled with the library is usually out-of-date.This can be skipped for CPU-only installation.

BLAS: install ATLAS by

sudo apt-get install libatlas-base-dev

             or install OpenBLAS by :sudo apt-get install libopenblas-dev or MKL for better CPU performance.

                              OpenBlas,可以通过下载,然后make, make install

Python (optional): if you use the default Python you will need to

sudo apt-get install the python-dev package to have the Python headers for building the pycaffe interface.


gotoblas


Download from: https://github.com/BVLC/caffe.git

cp Makefile.config.example Makefile.config# Adjust Makefile.config (for example, if using Anaconda Python, or if cuDNN is desired)make allmake testmake runtest

python;import caffe 说明安装成功

===make pycaffe出现错误

    python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: no such file or directory
    Makefile:498: recipe for target 'python/caffe/_caffe.so' failed make: *** [python/caffe/_caffe.so] Error 1
==fix:

  原因
    python-numpy没有安装到位
    解决方法
    输入命令
    sudo apt-get install python-numpy
    确认Makefile.config文件中有以下代码,注意路径或版本号与自己的相符。
    PYTHON_INCLUDE := /usr/include/python2.7 \

    /usr/lib/python2.7/dist-packages/numpy/core/include



Download Mnist data :   data/mnist$ ./get_mnist.sh

.build_release/tools/caffe             ==>add to env
# train LeNet
caffe train -solver examples/mnist/lenet_solver.prototxt
# train on GPU 2
caffe train -solver examples/mnist/lenet_solver.prototxt -gpu 2
# resume training from the half-way point snapshot
caffe train -solver examples/mnist/lenet_solver.prototxt -snapshot examples/mnist/lenet_iter_5000.solverstate


  • For CPU & GPU accelerated Caffe, no changes are needed.
  • For cuDNN acceleration using NVIDIA’s proprietary cuDNN software, uncomment theUSE_CUDNN := 1 switch inMakefile.config. cuDNN is sometimes but not always faster than Caffe’s GPU acceleration.
  • For CPU-only Caffe, uncomment CPU_ONLY := 1 inMakefile.config.

To compile the Python and MATLAB wrappers do make pycaffe and make matcaffe respectively.Be sure to set your MATLAB and Python paths inMakefile.config first!




2.3 CUDA installation

a)CUDA: https://developer.nvidia.com/cuda-downloads

   I choose 8.0

  1. `sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb`
  2. `sudo apt-get update`
  3. `sudo apt-get install cuda`
  4. cuBLAS Patch Update to CUDA 8: Includes performance enhancements and bug-fixes


b)CUDNN:https://developer.nvidia.com/rdp/cudnn-download 

     I choose 5.1

    tar xvzf cudnn-8.0-linux-x64-v5.1-ga.tgz
    sudo cp -P cuda/include/cudnn.h /usr/local/cuda/include
    sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64
    sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*


对于NVIDIA1080P或者Titanx,有可能会遇到重启之后X启动不了的情况,也就是停留在循环登录界面。试过了大黄蜂,更换X,以及各种其他手段都无果,我选择了workround . 也就是以下命令:

prime-select * 去选择备用显卡

nvidia-smi 去确认cuda work



===1080 just use cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64-deb will work fine====

2.4 Other tools

sudo apt-get install git-core  cmake
sudo apt-getinstall cmakebuild-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev

sudo apt-get install libavresample-dev libgphoto2-dev

sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev


Blas,cblas,lapack:

http://www.netlib.org/blas/blas.tgz

http://www.netlib.org/blas/blast-forum/cblas.tgz

http://www.netlib.org/lapack/lapack-3.4.2.tgz,


lacpack:

  1. make # 编译所有的lapack文件  
  2. cd lapacke # 进入lapacke 文件夹,这个文件夹包含lapack的C语言接口文件  
  3. make # 编译lapacke  
  4. cp include/*.h /usr/local/include #将lapacke的头文件复制到系统头文件目录  
  5. cd .. #返回到 lapack-3.4.2 目录  
  6. cp *.a /usr/local/lib # 将生成的所有库文件复制到系统库目录 

SS-QT5:

sudo add-apt-repository ppa:hzwhuang/ss-qt5
sudo apt-get update
sudo apt-get install shadowsocks-qt5


vtk

地址:http://www.vtk.org/VTK/resources/software.html         wiki:http://www.vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/Sphere
或者直接apt-get install libvtk**-qt4 libvtk** libvtk**-dev

如果vtk不安装的话,viz不会被编译,而且cnn_3dobj需要viz

opengl

apt-get install mesa-common-dev libgl1-mesa-dev  sudo apt-get install mesa-common-dev mesademos libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev
QT

https://www.qt.io/download-open-source/  http://blog.csdn.net/laizhenghong2012/article/details/51758164

numpy

sudo apt-get install python3-numpy 

2.5 Build opencv

mkdir build

cd build

cmake ..           #cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=./  ..

make  -j8

sudo make install

检查:
        cd lib/
        ls
        查看是否存在cv2.so
        存在则:ln cv2.so /usr/local/lib/python2.7/site-packages
        否则重新安装,查找错误
        8.最后检查:
        cd
        python
        import cv2
        如果不报错 则成功!!!!


==MEET PROBLEM==:


      -- Caffe:   NO (FindCaffe.cmake)  message("Caffe_INCLUDE_DIR = \"${Caffe_INCLUDE_DIR}\"")
                                                                message("Caffe_LIBS = \"${Caffe_LIBS}\"")

                                                                Caffe_INCLUDE_DIR = "/usr/local/include"
                                                                Caffe_LIBS = "Caffe_LIBS-NOTFOUND"

==Fix Method==:

:+//Path to bashrc.
+Caffe_INCLUDE_DIR:PATH=/usr/local/include
+//Path to a library.
+Caffe_LIBS:FILEPATH=/usr/local/lib/libcaffe.so

/usr/local/lib$                           sudo cp -r    /localrepo/caffe/src/caffe/                                  ./

/usr/local/include$                sudo cp -r      /localrepo/caffe/include/caffe/                          ./
/usr/local/include/caffe$        sudo cp -r    /localrepo/caffe/build/src/caffe/proto/              ./
#/usr/local/include/caffe/$        sudo cp      /localrepo/caffe/include/caffe/util/io.hpp       ./
/usr/local/include/caffe/$        sudo cp -r   /localrepo/caffe/include/caffe/util/                   ./

/usr/local/lib/$                            sudo cp /localrepo/caffe/.build_release/lib/libcaffe.so  ./



2.6 Hosts

git clone https://github.com/betsyweilin/hosts

开host文件

      sudo  cp /etc/hosts /etc/hosts_bak

      sudo  cp hosts /etc/hosts

      vim gedit /etc/hosts
      添加你需要的项,格式如下:
      格式:
       <IP> <HOSTNAME>.<DOMAIN> <ALIAS>
       示例:
                216.239.37.99 www.google.com
                编辑后,你需要重新启动一下你的网络。
                 /etc/init.d/networking restart



 opengl