OpenCV with video support in recent Linux distros

There were days when we had to painstakingly go through the manual install process for getting OpenCV running on our systems. Those days are long gone, and for the good. Current day distros bundle both OpenCV and ffmpeg in their repositories, making life extremely easy for enthusiasts and geeks alike. The following 4 steps provide a fully functional OpenCV install on Fedora:

  • sudo yum groupinstall “Development Tools” “Development Libraries”
  • sudo yum install eigen2-devel CTL CTL-devel OpenEXR_CTL-libs tbb yasm yasm-devel tbb-devel OpenEXR CTL-devel  gstreamer-plugins-base-devel libsigc++20-devel glibmm24-devel libxml++-devel gstreamermm xine-lib libunicapgtk-devel xine-lib-devel gstreamermm-devel python-devel sip-macros sip vamp-plugin-sdk audacity sip-devel xorg-x11-proto-devel libXau-devel libX11-devel automake libogg-devel libtheora-devel libvorbis-devel libdc1394-devel x264-devel faac-devel xvidcore-devel dirac-devel gsm-devel zlib-devel faad2-devel speex-devel lame-devel orc-compiler orc-devel libvdpau cppunit libvdpau-devel schroedinger-devel dirac x264 lame faad2 amrwb-devel opencore-amr-devel amrnb amrnb-devel
  • sudo yum install ffmpeg ffmpeg-devel opencv opencv-devel opencv-python
  • sudo updatedb

That’s it! Dont believe me, well run a sample python or c code and see for yourself! 🙂 You can download this PDF file containing a sample code written in both python and C. Provide the video file appropriately and enjoy seeing your OpenCV installation playing a video file.

P.S : For C based codes, run gcc as:

gcc -L/usr/include/opencv -lopencv_core -lopencv_highgui -lm -o a.out fileName.c

For python based codes:

python fileName.py

Video in OpenCV

Video files in OpenCV
Advertisements

Install OpenCV 2.3 with video support in Fedora 15

Much has changed since OpenCV 2.0.. android support, CUDA support, etc are up and running. So is the change in the method of installing OpenCV. So, i though to quickly jot down the steps to follow for a painless install.

I must add, due to changes in gcc, removal of libv4l support from linux kernel, etc.. OpenCV 2.1 and 2.2 give loads of issues during install. I just couldnt manage installing v2.1, though v2.2 needed few hacks as mentioned in the link : https://code.ros.org/trac/opencv/ticket/324 . So, for people wanting to install v2.2, can follow exactly same steps mentioned below after making the above hack. Note that, even UVC-webcams dont work with v2.2. So, if you’re like me, needing lots of webcam feed for vision-based tasks, its best to avoid v2.2. Moral of the story : Go for v2.3..

1. Install the following :

sudo yum install eigen2-devel, CTL, CTL-devel, OpenEXR_CTL-libs, tbb, yasm, yasm-devel, tbb-devel, OpenEXR CTL-devel, OpenEXR CTL, perl-URI, perl-Compress-Raw-Zlib, perl-Compress-Raw-Bzip2, perl-l0-Compress, libucil-clevel, perl-HTML-Tagset, perl-HTML-Parser, perl-Iibwww-perl, perl-XML-Parser, gstreamer-plugins-base-devel, libsigc++20-devel, glibmm24-devel, libxml++-devel, gstreamermm, xine-lib, libunicapgtk-devel, xine-lib-devel, gstreamermm-devel, python-devel, sip-macros, sip, vamp-plugin-sdk, audacity, sip-devel

sudo yum install libXext-clevel, glib2-devel, libXrender-devel, libXfixes-devel, Iibunicap, freetype-devel, boost-system, fontconfig-devel, libpng-devel, boost-filesystem, boost-serialization, boost-thread, boost-date-time, boost-regex, libXt-devel, libXdamage-devel, libXcomposite-devel, libXcursor-devel, libXrandr-devel, atk-devel, libXinerama-devel, libXxf86vm-devel, libXi-devel, libxml2-devel, blas-devel, libjpeg-turbo-devel, pixman-clevel, cairo-devel, pango-devel, libdrm-devel, mesa-libGL-devel, boost-graph, boost-wave, libucil, boost-signals, boost-python, boost-iostreams, boost-program-options, boost-random, boost-test, boost, mesa-libGLU-devel, ilmbase-devel, libunicapgtk, gdk-pixbuf2-devel, libibverbs, libmlx4, librdmacm, check, check-devel, boost-jam, rarian, rarian-compat, cmake, plpa-libs, numactl, environment-modules, boost-devel, boost-build, OpenEXR-devel, jasper-devel, lapack-devel, libunicap-devel, libtifl-devel, atlas-devel, openmpi, boost-openmpi, ucview, gstreamer-devel, gtk2-devel, jasper, 0penEXR

sudo yum install xorg-x11-proto-devel, libXau-devel, Iibxcb-devel, libX11-devel, libram1394-devel, automake, libogg-devel, libtheora-devel, libvorbis-devel, libdc1394-devel, x264-devel, faac-devel, xvidcore-devel, dirac-devel, gsm-devel, zlib-devel, faad2-devel, speex-devel, lame-devel, orc-compiler, orc-devel, libvdpau, cppunit, libvdpau-devel, schroedinger-devel, dirac, x264, lame, faad2, amrwb-devel, opencore-amr-devel, amrnb, amrnb-devel

(i have tried copying the package names via OCR software and some editing as much as could be possible from the screenshot below)

OR

Install from Add/Remove Programs (PackageKit)

List of Packages to install for OpenCV dependency resolution

2. Now, download and Install FFMPEG

  • Eventhough FFMPEG is at v0.8.. its best to go for v0.7.. thats coz of several dependency issues. Many things like VLC, etc are based on ffmpeg v0.69 code, and v0.8 MAY give lots of issues..
  • Download ffmpeg 0.7 from : http://ffmpeg.org/releases/ffmpeg-0.7.1.tar.bz2
  • extract the above file (say files get extracted to /home/user/ffmpeg)
  • Open terminal and cd to above location.. i.e. : cd /home/user/ffmpeg
  • Now type the following :

./configure –enable-gpl –enable-version3 –enable-nonfree –enable-postproc –enable-libfaac –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libtheora –enable-libvorbis –enable-libxvid –enable-x11grab –enable-swscale –enable-shared

make

sudo make install

  • And you are done.. FFMPEG is ready to be integrated with OpenCV.

3. Download OpenCV 2.3 . Extract to a folder (say /home/user/Opencv-2.3)

  • There still are a few packages of ffmpeg like libavcodec-dev, libavutil-dev, etc which need to be present in /usr/local/ffmpeg/ . But, the above  install of ffmpeg doesnt create this. So, open Add/Remove Programs and install following or install using yum:

sudo yum -y install ffmpeg ffmpeg-devel ffmpeg-libs

  • Now, the requisite libraries are all present in the location OpenCV can find them. Open terminal and cd to the OpenCV folder.. i.e.

cd /home/user/OpenCV-2.3

  • Create a folder called Release

mkdir Release

  • cd to the Release folder and type the following to install OpenCV

cd Release/

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_CUDA=OFF -D WITH_V4L=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_FFMPEG_BUILD=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_IPP=OFF -D BUILD_EXAMPLES=ON ..

make -j 2

sudo make install

  • Few more steps need to be done to ensure flawless build.

sudo gedit /etc/ld.so.conf.d/opencv.conf

(Type the following and save-close the file) : /usr/local/lib

sudo ldconfig

sudo gedit /etc/bashrc

(Type the following and save-close the file) :

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

And you are done !!! 🙂 OpenCV 2.3 with ffmpeg support is ready to be used on Fedora 15 with full webcam support.. ENJOY !!

NOTE : due to requests for Ubuntu specific steps, i’ll put the changed steps in this post itself in a few days

Install OpenCV in Linux with video (ffmpeg) support

Faced with the task of running Computer Vision problems in Linux environment, i started googling for the methods.. Though i found the install steps at many places, but my install always failed, getting stuck while doing a make operation on the source files.

Finally, i managed to install it from source.. I am listing the steps here, with a special thanks to all the people, their blogs and google for helping me succeed in installing OpenCV.

  • Download ffmpeg
  • Extract contents to a folder. do a cd to the folder location in the terminal. Build ffmpeg as follows (as root) :
  • su -c
  • ./configure –enable-shared
  • make all
  • make install
  • The –enable-shared option during configuration ensures compatibility between LGPL licence of ffmpeg contents and BSD licence of OpenCV.
  • ADDITIONAL IMPORTANT STEPS (before installing OpenCV)
  • goto the folder where library files of ffmpeg have got installed in your system. you can do a “locate ffmpeg” to know that. for e.g, in my case, its /usr/include/ffmpeg/
  • Now, type in the follwing (as root):
  • ln -s libavcodec/avcodec.h avcodec.h
  • ln -s libavformat/avformat.h avformat.h
  • ln -s libavformat/avio.h avio.h
  • ln -s libavutil/avutil.h avutil.h
  • ln -s libswscale/swscale.h swscale.h
  • Download latest build of OpenCV 2.1 or OpenCV 2.0
  • install swig in your version of linux.. its available in the repos of all the distros. Swig is the application that interacts between different programming languages like C / C++, Python, etc. Swig is extremely essential for succesfull build of OpenCV.
  • yum install swig sip (Fedora)
  • apt-get install swig python-sip (Debian based distros)
  • Extract and build OpenCV as follows :
  • ./configure –enable-shared

ENSURE the summary of this step is somewhat similar to https://aspratyush.files.wordpress.com/2010/04/opencv-configure.png

If not, please install the required dependencies from your package manager (yum / Synaptic) as mentioned in the link. Any missing dependency will lead to some problem or the other.

  • make
  • make install
  • Now, comes the finishing touch stage.. you need to let the system know where the OpenCV library files are located.
  • export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
  • ldconfig

And you are done.. enjoy the OpenCV build by running examples as mentioned in the technical documentation : OpenCV install Guide

OpenCV summary of configure step

Example of playing a file using ffplay command

playing a video file using ffplay