Friday 24 July 2015

Installing OpenCV-2.4.11 on ubuntu 14.04

Why OpenCV?

Have you at any point of time wondered what OpenCV is all about ? And what makes it so popular among researchers and image processing experts?  Well, OpenCV is the most popular and advanced library with more than 2500 optimised algorithm, which include a comprehensive set of both classic and state-of-art computer vision and machine learning algorithms. These algorithms can be used to detect faces, identify objects, classify human actions in videos, track camera movements and many more. OpenCV has more than 47 thousand people of user community and estimated number of downloads exceeding 7 million. The library is used extensively in companies, research groups and by governmental bodies. And the best part is: its free for both academic and commercial use with C++, C, Python and Java interfaces and supports Windows, Linux, MacOS, iOS and Android. The official website and support for OpenCV can be found here.

Lets get Started!

So, without waiting lets get started with installing it on our Ubuntu Systems. 

1st Step: Install the Dependencies

To install the dependencies required from OpenCV, just run the following commands:
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 libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip

2nd Step: Download OpenCV 2.4.11

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

3rd step: Install OpenCV

Now, we’ll install OpenCV. Cmake command has a lot of options: choose those that better suit your needs and run the commands below. If you’re planning to use Qt 5.x, don’t use -D WITH_QT=ON. Learn how to use OpenCV with Qt Creator 3.2 (Qt 5.3). According to one of the users that tested it on Ubuntu 14.04, you’ll need to use WITH_FFMPEG=OFF.
cd opencv-2.4.11
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
make -j 4
sudo make install
Note: In command make -j 4 , the number '4' denotes number of core process your system supports. You could use '8', if you own octa-core processor.

4th step: Finishing Installation!! 

sudo gedit /etc/ld.so.conf.d/opencv.conf
 And add the following line to the file and save it.
/usr/local/lib/ 
Now, you have to open another file. 
sudo gedit /etc/bash.bashrc
And add the following 2 lines to it and save it. 
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig 
exprt PKG_CONFIG_PATH
Finally, close the console and open a new one, restart the computer or logout and then login again. OpenCV will not work correctly until you do this.
Now you have OpenCV 2.4.11 installed in your computer with 3D visualization, Python, Java, TBB, OpenGL, video, and Qt support.

Testing the Installations!

Just in case you are skeptical about the installation, you can simply check it by running few if the inbuilt examples. 
cd opencv/samples/c
chmod +x build_all.sh
./build_all.sh
./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" lena.jpg
./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_eye.xml" --scale=1.5 lena.jpg
I hope this tutorial helps you out! Do leave comments if something is not clear or you need an help! Suggestions and feedback are most welcome..!! Have great time with 'Computer Vision'. 

17 comments:

  1. Replies
    1. This comment has been removed by the author.

      Delete
  2. It is very useful for begineers like me..!! Thank you for lucid and clear procedure steps!!

    ReplyDelete
  3. Very helpful blog for naive users like me. Looking forward with such user friendly articles.

    ReplyDelete
  4. i get the following error
    modules/ocl/CMakeFiles/opencv_ocl.dir/build.make:213: recipe for target 'modules/ocl/CMakeFiles/opencv_ocl.dir/src/pyrlk.cpp.o' failed
    make[2]: *** [modules/ocl/CMakeFiles/opencv_ocl.dir/src/pyrlk.cpp.o] Error 1
    CMakeFiles/Makefile2:4667: recipe for target 'modules/ocl/CMakeFiles/opencv_ocl.dir/all' failed
    make[1]: *** [modules/ocl/CMakeFiles/opencv_ocl.dir/all] Error 2
    Makefile:147: recipe for target 'all' failed
    make: *** [all] Error 2
    please hlp

    ReplyDelete
    Replies
    1. kindly provide more detailed version of the error. Also mention the steps which you could execute correctly and step at which you ran across this error. I have tested this installation procedure on Ubuntu 14.04 and it works perfectly fine!

      Delete
  5. Thank you for the helpful tutorials

    but, I got some problem as follwings:

    Before " make -j 4" command, everything works fine,


    wkyoun@wkyoun-XPS-13-9343:~/opencv-2.4.11/build$ make -j 4

    Please refer the following errors:

    Would you please let me know how to fix it?


    [ 73%] Building NVCC (Device) object modules/gpu/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_bf_match.cu.o
    nvcc warning : The 'compute_11', 'compute_12', 'compute_13', 'sm_11', 'sm_12', and 'sm_13' architectures are deprecated, and may be removed in a future release.

    ReplyDelete
    Replies
    1. The tutorial works perfectly fine on Ubuntu 14.04 version with no GPU. Let me know which version of Ubuntu are you working on? Is it GPU enabled system?

      Delete
    2. in make -j4 4 means 4 core of CPU. if you have dual core CPU than use 2 or for single core use 1. e.g make -j2.
      If it's still doesn't work than use sudo for all preceding commands.

      Delete
  6. https://github.com/Itseez/opencv/issues/4940

    ReplyDelete
  7. Installation is perfect. However, samples folder is missing in the installed package. Is there anything wrong?

    ReplyDelete
  8. Bonjour, une erreur s'est glissée à l'étape 4 : Le nom du fichier à ouvrir n'est pas le bon. Il faut taper la commande "sudo gedit /etc/bash.bashrc" au lieu de "sudo gedit /etc/bash.bashsrc". Merci pour ce tuto malgré tout!

    ReplyDelete
  9. I'm sorry I replied in frensh : (There is an error in step 4 : The file's name is not "bash.bashsrc" but "bash.bashrc". Thank you for the post nonetheless.)

    ReplyDelete
    Replies
    1. Thank you for pointing out the mistake! Will have it changed! Cheers :)

      Delete
  10. Just one point, "exprt" PKG_CONFIG_PATH should be changed to "export" ...

    Thanks one more time

    ReplyDelete