Install OpenCV 3.4 on Ubuntu 17.10

Hello and greetings everyone.

In this post, I'll be showing you how to install OpenCV 3.4 on Ubuntu 17.10 with Python2 and Python3.

so, let us start.

First of all, we need to update Ubuntu with latest updates.

sudo apt update
sudo apt -y upgrade
sudo apt -y autoremove
Secondly, let us remove old dependencies installed on Ubuntu.

sudo apt -y autoremove libopencv-dev python-opencv x264 libx264-dev

Thirdly, we install build tools for compiling OpenCV source.

sudo apt install -y build-essential cmake pkg-config checkinstall git gfortranlibboost-all-dev

Fourthly, we install GUI packages used by OpenCV.

# GUI (if you want to use GTK instead of Qt, replace 'qt5-default' with 'libgtkglext1-dev' and remove '-DWITH_QT=ON' option in CMake):
sudo apt install -y qt5-default libvtk6-dev libgtk2.0-dev

Then, we install media packages.

# Media I/O:
sudo apt install -y zlib1g-dev libjpeg-dev libjpeg8-dev libwebp-dev libpng-dev libtiff5-dev libjasper-dev libopenexr-dev libgdal-dev libfaac-dev libmp3lame-dev
# Video I/O:
sudo apt install -y libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev x264 v4l-utils
# Parallelism and linear algebra libraries:
sudo apt install -y libtbb-dev libeigen3-dev libatlas-base-dev

Then, we install python 2 & 3 packages.

sudo apt install -y python-dev python-tk python-numpy python3-dev python3-tk python3-numpy python-pip python3-pip
sudo -H pip2 install -U pip numpy
sudo -H pip3 install -U pip numpy

After that, we install Java JDK.

sudo apt install -y ant default-jdk

Lastly, we install documentation tools.

sudo apt install -y libprotobuf-dev protobuf-compiler libgoogle-glog-dev libgflags-dev libgphoto2-dev libeigen3-dev libhdf5-dev doxygen

After installing all packages needed by OpenCV let's start downloading the source and compile it.

sudo apt install -y unzip wget
mkdir ~/OpenCV
cd ~/OpenCV
wget -O -c
wget -O
mv opencv-3.4.0 OpenCV
cd OpenCV
mkdir build
cd build

Now, we downloaded the source and prepared it for compilation process.

to start compiling write this command:


or, if you have a multi-core processor and want to speed up compilation use this command instead.

let say we have 4 core processor:

make -j4

Finally, installing compiled source to your system.

sudo make install
sudo ldconfig

Now, we are ready to go, to check if everything is all right, open python REPL.


and then test import.

import cv2