Install OpenCV and Deep Learning development with Python

    OpenCV 與深度學習開發環境安裝


    Operation System and Software Installed:

    • Ubuntu 16.04
    • OpenCV 3.3
    • Python 3

    Configure Ubuntu for deep learning with Python

    1. Step #1: Install Ubuntu system dependencies
    2. Step #2: Create your Python 3 virtual environment
    3. Step #3: Compile and Install OpenCV
    4. Step #4: Install Keras

    Step #1: Install Ubuntu system dependencies

    Ubuntu 16.04)

    $ sudo apt-get update
    $ sudo apt-get upgrade

    Install some libraries and dependency

    $ sudo apt-get install build-essential cmake git unzip pkg-config \
      libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev \
      libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
      libxvidcore-dev libx264-dev libgtk-3-dev libhdf5-serial-dev graphviz \
      libopenblas-dev libatlas-base-dev gfortran python-tk python3-tk python-imaging-tk

    Install Python development headers

    $ sudo apt-get install python2.7-dev python3.5-dev

    Step #2: Create your Python virtual environment

    Install pip

    $ cd ~
    $ wget
    $ sudo python
    $ sudo python3
    NOTE: If you keep 2 different versions of Python the pip installation is required for each of them.

    Python virtual environment

    $ sudo pip install virtualenv virtualenvwrapper
    $ sudo rm -rf ~/ ~/.cache/pip

    Edit the profile ~/.bashrc, add the following lines

    # virtualenv and virtualenvwrapper
    export WORKON_HOME=$HOME/.virtualenvs
    export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
    source /usr/local/bin/

    Apply the profile

    $ source ~/.bashrc

    Creating Python virtual environment

    $ mkvirtualenv py3cv3 -p python3
    py3cv3 is my project name, you can name it as whatever you like (and create as many Python virtual environments as you want).
    Install NumPy into your Python virtual environment
    $ workon py3cv3
    $ pip install numpy

    Step #3: Compile and Install OpenCV

    Download opencv and opencv_contrib.
    $ cd ~
    $ wget -O
    $ unzip
    $ wget -O
    $ unzip
    NOTE: Don't install v3.3.0, which would generate some unknow errors when you import it then quit from python.
    Running CMake
    $ workon py3cv3
    $ cd ~/opencv-3.4.3/
    $ mkdir build
    $ cd build
     -D CMAKE_INSTALL_PREFIX=/usr/local \
     -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.4.3/modules \
    Compiling OpenCV
    $ make -j4
    The -j  switch controls the number of processes to be used when compiling OpenCV.
    In my case, I have a quad-core processor, so I set -j4 .

    The last step is to actually install OpenCV 3 on Ubuntu 16.04:

    $ sudo make install
    $ sudo ldconfig
    $ cd ~
    $ rm -rf opencv-3.4.3
    $ rm -rf opencv_contrib-3.4.3
    Symbolic linking OpenCV to your virtual environment
    $ cd ~/.virtualenvs/py3cv3/lib/python3.5/site-packages/
    $ ln -s /usr/local/lib/python3.5/site-packages/
    $ cd ~
    Testing your OpenCV install

    To verify that your installation is working:

    1. Open up a new terminal.
    2. Execute the workon command to access the cv Python virtual environment.
    3. Attempt to import the Python + OpenCV bindings.
    $ workon py3cv3
    $ python
    Python 3.5.2 (default, Jul  5 2016, 12:43:10)
    [GCC 5.4.0 20160609] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import cv2
    >>> cv2.__version__

    As you can see, I can import my OpenCV bindings into my Python 3.5 shell.

    Step #4: Install Keras

    $ workon py3cv3
    $ pip install scipy matplotlib pillow
    $ pip install imutils h5py requests progressbar2
    $ pip install scikit-learn scikit-image
    Install Tensorflow
    $ pip install tensorflow
    Notice how we are using the CPU version of TensorFlow.
    Install Keras
    $ pip install keras
    Test the Keras install
    $ python
    >>> import keras
    Using TensorFlow backend.
    >>> exit()
    標籤 (Edit tags)
    • No tags
    您必須 登入 才能發佈評論。
    Powered by MindTouch Core