Installing OpenCV with Tesseract text module on Ubuntu

This post shows how to install OpenCV on Ubuntu (14.04) with all text and Tesseract goodies.

First install all dependencies.

sudo apt-get install -y build-essential cmake git pkg-config
sudo apt-get install -y libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install -y libgtk2.0-dev
sudo apt-get install -y libatlas-base-dev gfortran

Install Tesseract dependencies to be able to build it with OpenCV.

apt-get install -y tesseract-ocr libtesseract-dev libleptonica-dev

Install some extra Python stuff. I presume you already have Python 3 (or 2.7).

# Install Pip if you don't have it yet.
curl -O
sudo python3
sudo apt-get install -y python3.4-dev
pip install numpy

Get the right OpenCV source code.

cd ~
git clone
cd opencv
git checkout 3.1.0 # Or just use master

cd ~
git clone
cd opencv_contrib
git checkout 3.1.0 # Or just use master

Compile OpenCV from source.

cd ~/opencv
mkdir build
cd build
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
      -D BUILD_opencv_python3=ON \
make -j4
make install

Next you’re ready to go. Test your install by opening Python and check if you can access the new version and features:

>>> import cv2
>>> cv2.__version__
>>> cv2.text # should return the module

You could also check this Dockerfile to run everything in a container.