OpenCV  3.1.0
Open Source Computer Vision
Install OpenCV-Python in Fedora


In this tutorial


OpenCV-Python can be installed in Fedora in two ways, 1) Install from pre-built binaries available in fedora repositories, 2) Compile from the source. In this section, we will see both.

Another important thing is the additional libraries required. OpenCV-Python requires only Numpy (in addition to other dependencies, which we will see later). But in this tutorials, we also use Matplotlib for some easy and nice plotting purposes (which I feel much better compared to OpenCV). Matplotlib is optional, but highly recommended. Similarly we will also see IPython, an Interactive Python Terminal, which is also highly recommended.

Installing OpenCV-Python from Pre-built Binaries

Install all packages with following command in terminal as root.

1 $ yum install numpy opencv*

Open Python IDLE (or IPython) and type following codes in Python terminal.

1 >>> import cv2
2 >>> print cv2.__version__

If the results are printed out without any errors, congratulations !!! You have installed OpenCV-Python successfully.

It is quite easy. But there is a problem with this. Yum repositories may not contain the latest version of OpenCV always. For example, at the time of writing this tutorial, yum repository contains 2.4.5 while latest OpenCV version is 2.4.6. With respect to Python API, latest version will always contain much better support. Also, there may be chance of problems with camera support, video playback etc depending upon the drivers, ffmpeg, gstreamer packages present etc.

So my personnel preference is next method, i.e. compiling from source. Also at some point of time, if you want to contribute to OpenCV, you will need this.

Installing OpenCV from source

Compiling from source may seem a little complicated at first, but once you succeeded in it, there is nothing complicated.

First we will install some dependencies. Some are compulsory, some are optional. Optional dependencies, you can leave if you don't want.

Compulsory Dependencies

We need CMake to configure the installation, GCC for compilation, Python-devel and Numpy for creating Python extensions etc.

1 yum install cmake
2 yum install python-devel numpy
3 yum install gcc gcc-c++

Next we need GTK support for GUI features, Camera support (libdc1394, libv4l), Media Support (ffmpeg, gstreamer) etc.

1 yum install gtk2-devel
2 yum install libdc1394-devel
3 yum install libv4l-devel
4 yum install ffmpeg-devel
5 yum install gstreamer-plugins-base-devel

Optional Dependencies

Above dependencies are sufficient to install OpenCV in your fedora machine. But depending upon your requirements, you may need some extra dependencies. A list of such optional dependencies are given below. You can either leave it or install it, your call :)

OpenCV comes with supporting files for image formats like PNG, JPEG, JPEG2000, TIFF, WebP etc. But it may be a little old. If you want to get latest libraries, you can install development files for these formats.

1 yum install libpng-devel
2 yum install libjpeg-turbo-devel
3 yum install jasper-devel
4 yum install openexr-devel
5 yum install libtiff-devel
6 yum install libwebp-devel

Several OpenCV functions are parallelized with Intel's Threading Building Blocks (TBB). But if you want to enable it, you need to install TBB first. ( Also while configuring installation with CMake, don't forget to pass -D WITH_TBB=ON. More details below.)

1 yum install tbb-devel

OpenCV uses another library Eigen for optimized mathematical operations. So if you have Eigen installed in your system, you can exploit it. ( Also while configuring installation with CMake, don't forget to pass -D WITH_EIGEN=ON. More details below.)

1 yum install eigen3-devel

If you want to build documentation ( Yes, you can create offline version of OpenCV's complete official documentation in your system in HTML with full search facility so that you need not access internet always if any question, and it is quite FAST!!! ), you need to install Sphinx (a documentation generation tool) and pdflatex (if you want to create a PDF version of it). ( Also while configuring installation with CMake, don't forget to pass -D BUILD_DOCS=ON. More details below.)

1 yum install python-sphinx
2 yum install texlive

Downloading OpenCV

Next we have to download OpenCV. You can download the latest release of OpenCV from sourceforge site. Then extract the folder.

Or you can download latest source from OpenCV's github repo. (If you want to contribute to OpenCV, choose this. It always keeps your OpenCV up-to-date). For that, you need to install Git first.

1 yum install git
2 git clone

It will create a folder OpenCV in home directory (or the directory you specify). The cloning may take some time depending upon your internet connection.

Now open a terminal window and navigate to the downloaded OpenCV folder. Create a new build folder and navigate to it.

1 mkdir build
2 cd build

Configuring and Installing

Now we have installed all the required dependencies, let's install OpenCV. Installation has to be configured with CMake. It specifies which modules are to be installed, installation path, which additional libraries to be used, whether documentation and examples to be compiled etc. Below command is normally used for configuration (executed from build folder).


It specifies that build type is "Release Mode" and installation path is /usr/local. Observe the -D before each option and .. at the end. In short, this is the format:

1 cmake [-D <flag>] [-D <flag>] ..

You can specify as many flags you want, but each flag should be preceded by -D.

So in this tutorial, we are installing OpenCV with TBB and Eigen support. We also build the documentation, but we exclude Performance tests and building samples. We also disable GPU related modules (since we use OpenCV-Python, we don't need GPU related modules. It saves us some time).

*(All the below commands can be done in a single cmake statement, but it is split here for better understanding.)*

Now you build the files using make command and install it using make install command. make install should be executed as root.

1 make
2 su
3 make install

Installation is over. All files are installed in /usr/local/ folder. But to use it, your Python should be able to find OpenCV module. You have two options for that.

  1. Move the module to any folder in Python Path : Python path can be found out by entering import sys;print sys.path in Python terminal. It will print out many locations. Move /usr/local/lib/python2.7/site-packages/ to any of this folder. For example,
    1 su mv /usr/local/lib/python2.7/site-packages/ /usr/lib/python2.7/site-packages
    But you will have to do this every time you install OpenCV.
  2. Add /usr/local/lib/python2.7/site-packages to the PYTHON_PATH: It is to be done only once. Just open/.bashrc and add following line to it, then log out and come back.
    1 export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
    Thus OpenCV installation is finished. Open a terminal and try import cv2.

To build the documentation, just enter following commands:

1 make docs
2 make html_docs

Then open opencv/build/doc/_html/index.html and bookmark it in the browser.

Additional Resources


  1. Compile OpenCV from source in your Fedora machine.