[PYTHON] Install OpenCV and Chainer on Ubuntu

environment
Ubuntu 14.04.4 LTS

Purpose

I want to get a face from an image and analyze who it is. To that end, first set up the environment.

Don't do

Video analysis is not performed with OpenCV. So I don't put in video related packages as much as possible.

What to put

What to put
Python 3.4.3
OpenCV 3.0.0
Chainer 1.10.0

Update the environment to the latest

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

Insert pytnon3

Check the version already included

$ python -V

Installation

$ sudo apt-get install build-essential
$ sudo apt-get install python3-dev

Check version

$ python -V
$ python3 -V

Also install pip

$ sudo apt-get install python3-pip
$ pip3 -V
$ pip3 list

Insert OpenCV

Install the required packages

$ sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff4-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip
$ sudo apt-get -y install build-essential libopenexr-dev python-tk libtbb-dev libeigen3-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra default-jdk ant libvtk5-qt4-dev unzip
$ sudo apt-get -y install libdc1394-22-dev libdc1394-22 libdc1394-utils

download

$ cd ~
$ wget -O opencv-3.0.0.zip https://github.com/Itseez/opencv/archive/3.0.0.zip
$ unzip opencv-3.0.0.zip

Creating CMake

$ cd opencv-3.0.0
$ mkdir build
$ cd build
$ sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D INSTALL_PYTHON_EXAMPLES=ON -D PYTHON_EXECUTABLE=$(which python3) -D BUILD_opencv_python3=ON -D BUILD_opencv_python2=ON BUILD_EXAMPLES=ON -D WITH_FFMPEG=OFF -D  BUILD_opencv_java=OFF BUILD_opencv_test_java=OFF ..

   General configuration for OpenCV 3.0.0 =====================================
  
abridgement
  
     Python 3:
       Interpreter:                 /usr/bin/python3.4 (ver 3.4.3)
       Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3)
       numpy:                       /usr/local/lib/python3.4/dist-packages/numpy/core/include (ver 1.11.1)
       packages path:               lib/python3.4/dist-packages
  
     Python (for build):            /usr/bin/python3
  
abridgement
  
     Install path:                  /usr/local
  
     cvconfig.h is in:              /home/ubuntu/opencv-3.0.0/build
   -----------------------------------------------------------------

Build & install

$ sudo make
$ sudo make install

Add Path

$ sudo vi /etc/ld.so.conf.d/opencv.conf
  /usr/local/lib
  /usr/lib

Reload & confirm Path

$ sudo ldconfig 
$ ldconfig -v

Check version

$ python3 -c "import cv2;print(cv2.__version__)" 

If you get a libdc1394 error

$ sudo ln /dev/null /dev/raw1394

Insert Chainer

Installation

$ sudo pip3 install chainer

Install the required packages

$ sudo apt-get install python3-numpy python3-scipy
$ sudo pip3 install -U scikit-learn

Be able to image the analysis results

$ sudo pip3 install matplotlib

Check version

$ python3 -c "import chainer;print(chainer.__version__)" 

end

I was surprised that Chainer entered very smoothly. I'll use it now.

Recommended Posts

Install OpenCV and Chainer on Ubuntu
Install CUDA 8.0 and Chainer on Ubuntu 16.04
Install OpenCV on Ubuntu + python
Install Mecab and mecab-python3 on Ubuntu 14.04
Build and install OpenCV on Windows
Install fabric on Ubuntu and try
Build Python3 and OpenCV environment on Ubuntu 18.04
Install Puppet Master and Client on Ubuntu 16.04
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Install TensorFlow on Ubuntu
Install PySide2 on Ubuntu
Install JModelica on Ubuntu
Install Python 3.3 on Ubuntu 12.04
Install Chainer 1.5.0 on Windows
Install Theano on Ubuntu 12.04
Install angr on Ubuntu 18.04
Install Chainer on CentOS 6.7
Install pip / pip3 on Ubuntu
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Install MongoDB on Ubuntu 16.04 and operate via python
Install GoLand IDE on Ubuntu
Install Chainer 1.6 (GPU) on Windows 7.
wsl Install PostgreSQL on Ubuntu 18.04
[ROS] Install ROS (melodic) on Ubuntu (18.04)
Install Caffe on Ubuntu 14.04 (GPU)
Install Docker on WSL Ubuntu 18.04
[Python] [Chainer] [Windows] Install Chainer on Windows
Install OpenCV4 on Raspberry Pi 3
Install Apache 2.4 on Ubuntu 19.10 Eoan Ermine and run CGI
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Install CUDA10.1 + cuDNN7.6.5 + tensorflow-2.3.0 on Ubuntu 18.04
Install Python 3.8 on Ubuntu 18.04 (OS standard)
Install Caffe on Ubuntu 14.04 (CPU mode)
Install Python 3.8 on Ubuntu 20.04 (OS standard)
Install python3 and scientific calculation library on Ubuntu (virtualenv + pip)
How to install OpenCV on Mac
Install Python 3.9 on Ubuntu 20.04 (OS standard?)
Install confluent-kafka for Python on Ubuntu
Install Python 2.7 on Ubuntu 20.04 (OS standard?)
How to install Go on Ubuntu
ROS study # 1 Install ros-noetic on ubuntu 20.04
OpenCV3 & Python3 environment construction on Ubuntu
Install easy_install and pip on windows
How to install OpenCV on Cloud9 and run it in Python
Install Ubuntu 18.04 on MacBook Pro Touchbar model and connect to WIFI
Quickly install OpenCV 2.4 (+ python) on OS X and try the sample
Install opencv on Mac using Anaconda Navigator
Install wsl2 and master linux on windows
Python virtual environment and packages on Ubuntu
Steps to install Python environment on Ubuntu
Install and launch k3s on Manjaro Linux
Install and Configure TigerVNC server on Linux
Mount and format Disk on Ubuntu on GCP.
Created Ubuntu, Python, OpenCV environment on Docker
Install Pleasant on Ubuntu 20.04 (.NetCore3.1 / PostgreSQL version)
Install ubuntu on 32bit UEFI Ultra Notebook
Install Caffe running 3D-CNN on clean Ubuntu 14.04
How to install php7.4 on Linux (Ubuntu)
Install pyenv and rbenv on CentOS system-wide
Don't work Python with OpenCV on AMD Ryzen CPU on WSL2 Ubuntu 18.04 And 20.04
Shebang on Ubuntu 20.04