Installing OpenCV on Linux (Ubuntu)


Earlier i was using openCV with Microsoft Visual C++ 6.0. But let me tell you, it crashed a lot. Every time i needed to close the process from Task Manager. Then i decided to somehow install OpenCV for my ubuntu.
After searching and trying a lot for this, i was finally able to use opencv in GNU compiler(g++ or gcc).
Synaptic Package Manager has simplified the life to a great extent. OpenCV is now available in the ubuntu repositories.
Though there are some problems related to ‘ffmpeg’, i needed opencv for image processing only. So i have not mentioned here what to do about ‘ffmpeg’.

Things to know before starting installation:
i. This installation needs a C++ compiler like “g++”(which is most commonly used). So install g++ first using Synaptic or by following command at the terminal–

$ sudo apt-get install g++

ii. OpenCV requires GTK+ 2.0 or higher for displaying images. GTK is graphical user interface library. Type out the following code to know the version of GTK+ installed on ur pc.

$ dpkg -l | grep libgtk

This command should give o/p something like:

libgtk-directfb-2.0-0 2.16.1-0ubuntu2

If not, then u need to install the libraries for GTK+ 2.0 first, then start with this opencv installation.
To install GTK+ 2.0 libraries, type out the following command:

$ sudo apt-get install libgtk2.0-dev

If both g++ & GTK+ 2.0 are there then proceed as follows:

I am using Ubuntu 9.04 (Jaunty Jackalope) and i did the following steps to install & configure OpenCV(ver 1.0.0.6) successfully:

1. Go to Synaptic Package Manager (System> Administration> Synaptic Package Manager)
2. Search for “opencv” and install the main “opencv” package and the following lib files:
libcv
libcv-dev
libcvaux
libcvaux-dev
libhighgui
libhighgui-dev
opencv-doc
(‘python-opencv’ not required).
(you can also install opencv directly from the terminal by “sudo apt-get install” the above lib files
3. After installing all the packages, open a terminal & type this code:

export LD_LIBRARY_PATH=/home/opencv/lib
export PKG_CONFIG_PATH=/home/opencv/lib/pkgconfig

The above ones are default paths for the opencv libraries.
4. For testing:
Create a new folder & a file “hello.cpp” in it using any text editor & type this code in it:

#include < cv.h > /* required to use OpenCV */
#include < highgui.h > /* required to use OpenCV's highgui */
#include < stdio.h >

int main(int argc, char *argv[]) {
IplImage* img=0; /* pointer to an image */
printf("Hello\n");
if(argv[1] != 0)
img = cvLoadImage(argv[1], 0); // 1 for color
else
printf("Enter filename\n");
if(img != 0) {
cvNamedWindow("Display", CV_WINDOW_AUTOSIZE); // create a window
cvShowImage("Display", img); // show image in window
cvWaitKey(0); // wait until user hits a key
cvDestroyWindow("Display");
}
else
printf("File not found\n");
return 0;
}


5. To check the path where opencv & other lib files are stored, do:

$ pkg-config --cflags opencv

(output will come as)
-I/usr/include/opencv

$ pkg-config --libs opencv

(output will come as)
-lcxcore -lcv -lhighgui -lcvaux -lml

These paths are needed to compile your opencv programs, as given in the next step.

6. To compile & run:

$ g++ -I/usr/include/opencv -lcxcore -lhighgui -lm hello.cpp
./a.out img

where “img” is the name of any image within the same folder with extension.
You should be able to see “Hello” and the image in a different window.

-> If this runs, Congrats! now you can run any C/C++ program with opencv lib.
Else, try

$ export PATH=$HOME/usr/bin/:$PATH

and go to step3 again.

7. Now lets simplify the above big command by making a shortcut for it:
go to your local home directory(cd /home/) and open the .bashrc file using gedit(the file will be hidden). Append the following to the file:

alias gcv="g++ -I/usr/include/opencv -lcv -lcxcore -lcvaux -lhighgui -lm"

and save. Close the terminal and open it again.(as this process requires relogin of the terminal)

8.Now, go to directory containing a sample program & do

$ gcv filename.c && ./a.out
or
$ gcv filename.c
$ ./a.out input_img.jpg

As you can see the commands now become similar to $cc filename.c, $./a.out which are used normally for compiling and executing C programs.

****************************
Some ways to check whether all lib files are installed-
1. $ apt-cache search opencv
returns:
libcv-dev - development files for libcv
libcv0.9-0c2 - computer vision library
libcvaux-dev - development files for libcvaux
libcvaux0.9-0c2a - computer vision extension library
libhighgui-dev - development files for libhighgui
libhighgui0.9-0c2 - computer vision GUI library
opencv-doc - OpenCV documentation and examples


—————————————————————————
If you want to install openCV from a .tar file, refer this article:
Installing opencv in linux(Ubuntu) from .tar.gz file
Other helpful links on this topic:
http://ivkin.net/2009/11/installing-opencv-2-0-on-ubuntu-9-10-karmic-koala/

Advertisements

117 responses to “Installing OpenCV on Linux (Ubuntu)

  1. Pingback: Installing OpenCV on Ubuntu 10.04 LTS | Phaisarn Sutheebanjard

  2. when i tried this pkg-config –libs opencv
    i got reverse -lml -lcvaux -lhighgui -lcv -lcxcore

    and it’s not showing path to opencv by echo $PATH
    help me (fast)

  3. apt-cache search opencv
    libavcodec-extra-53 – Libav codec library
    libcv-dev – Translation package for libcv-dev
    libcv2.4 – computer vision library – libcv* translation package
    libcvaux-dev – Translation package for libcvaux-dev
    libcvaux2.4 – computer vision library – libcvaux translation package
    libhighgui-dev – Translation package for libhighgui-dev
    libhighgui2.4 – computer vision library – libhighgui translation package
    libopencv-calib3d-dev – development files for libopencv-calib3d
    libopencv-calib3d2.4 – computer vision Camera Calibration library
    libopencv-contrib-dev – development files for libopencv-contrib
    libopencv-contrib2.4 – computer vision contrib library
    libopencv-core-dev – development files for libopencv-core
    libopencv-core2.4 – computer vision core library
    libopencv-dev – development files for opencv
    libopencv-features2d-dev – development files for libopencv-features2d
    libopencv-features2d2.4 – computer vision Feature Detection and Descriptor Extraction library
    libopencv-flann-dev – development files for libopencv-flann
    libopencv-flann2.4 – computer vision Clustering and Search in Multi-Dimensional spaces library
    libopencv-highgui-dev – development files for libopencv-highgui
    libopencv-highgui2.4 – computer vision High-level GUI and Media I/O library
    libopencv-imgproc-dev – development files for libopencv-imgproc
    libopencv-imgproc2.4 – computer vision Image Processing library
    libopencv-legacy-dev – development files for libopencv-legacy
    libopencv-legacy2.4 – computer vision legacy library
    libopencv-ml-dev – development files for libopencv-ml
    libopencv-ml2.4 – computer vision Machine Learning library
    libopencv-objdetect-dev – development files for libopencv-objdetect
    libopencv-objdetect2.4 – computer vision Object Detection library
    libopencv-photo-dev – development files for libopencv-photo2.4
    libopencv-photo2.4 – computer vision computational photography library
    libopencv-stitching-dev – development files for libopencv-stitching2.4
    libopencv-stitching2.4 – computer vision image stitching library
    libopencv-ts-dev – development files for libopencv-ts2.4
    libopencv-ts2.4 – computer vision ts library
    libopencv-video-dev – development files for libopencv-video
    libopencv-video2.4 – computer vision Video analysis library
    libopencv-videostab-dev – development files for libopencv-videostab2.4
    libopencv-videostab2.4 – computer vision video stabilization library
    opencv-doc – OpenCV documentation and examples
    python-opencv – Python bindings for the computer vision library

    $ pkg-config –libs opencv
    Package opencv was not found in the pkg-config search path.
    Perhaps you should add the directory containing `opencv.pc’
    to the PKG_CONFIG_PATH environment variable
    No package ‘opencv’ found

  4. I am able to compile my opencv pgm but getting a runtime error of not able to trace the lib file libopencv_core.But when I checked the path of lib file it shows the file.Pls help me in this
    root@kickseed:~/openeg# g++ `pkg-config opencv –cflags` Display.cpp -o Display_Video `pkg-config opencv –libs`
    root@kickseed:~/openeg# ./Display_Video
    ./Display_Video: error while loading shared libraries: libopencv_core.so.2.4: cannot open shared object file: No such file or directory
    root@kickseed:~/openeg# pkg-config –cflags opencv
    -I/usr/local/include/opencv -I/usr/local/include
    root@kickseed:~/openeg# pkg-config –libs opencv
    /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so
    root@kickseed:~/openeg#

    • Hi Geetha, looks like the code is looking for “libopencv_core.so.2.4” which it is not able to find. I am not sure whether this library actually comes with the default opencv installation and for which function it is looking for this library. You can look for answers to these 2 questions.

    • Ubuntu repositories has missing OpenCV libraries. So general opencv applications require libopencv_core,libopencv_imgproc which your ubuntu version seems to be missing atm. So I suggest you to compile OpenCV from source which is not trivial as installing it from software center or apt-get. Or update to 12.04 or later for getting this libs from software center.

    • Yes. These steps work on Ubuntu 12.10 as well. One of my friends has tried it successfully. I think the library filenames are changed in the latest version of OpenCV (2.4). For instance, the new library names are:

      opencv_core
      opencv_highgui
      opencv_ml

      Hence, with the latest OpenCV you’ll have to type the following command to compile:

      g++ -I/usr/include/opencv -lopencv_core -lopencv_highgui -lopencv_ml hello.cpp

      instead of the previous command:

      $ g++ -I/usr/include/opencv -lcxcore -lhighgui -lm hello.cpp

      Likewise the alias is to be changed in the .bashrc (located in /etc in Ubuntu 12.04):

      alias gcv=”g++ -I/usr/include/opencv -lopencv_core -lopencv_highgui -lopencv_ml”

      Let me know if this works. I’ll update the blog post likewise. Thanks.

  5. Dear abhishek,
    I am trying to install opencv from Synaptic manager in ubuntu 12.04, I am getting this loader error which is

    warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
    /usr/bin/ld: cannot find -lcxcore
    /usr/bin/ld: cannot find -lhighgui
    collect2: ld returned 1 exit status

    please help me to reduce this problem.
    THANKS

  6. Dear abhishek,
    I am trying to install opencv from Synaptic manager in ubuntu 12.04, I am getting this loader error which is very common.

    /usr/bin/ld: cannot find -lcxcore
    /usr/bin/ld: cannot find -lhighgui
    collect2: ld returned 1 exit status

    But my problem is after export the library path still i am not able to get rid of this error
    I have given your command ” pkg-config –libs opencv” for finding the libraries which are installed, the outout is

    “-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann ” that means the output which you have got and I am getting is differing ./.. Can you please advice me to find what woud have gone wrong …. I compiled with gcc -I/usr/include/opencv -lcxcore -lhighgui -lm RGBconvert.c
    as well as gcc -I/usr/include/opencv -lopencv_core -lopencv_highgui -lopencv_ml RGBconvert.c
    but still its giving the error. I tried to find where the opencv/lib is located. I am not able to find it … Can you give me suggestion regarding this !

    Thank you in advance
    with loving regards
    ajith

    • Hi Ajith,
      Looks like OpenCV has again renamed its libraries. Since pkg-config command is listing the different libs, they definitely exist in the system and OpenCV is installed properly. You just to give the proper name and path where to find them.

      Check the location of the libraries and export their path through the LD_LIBRARY_PATH variable as:
      export LD_LIBRARY_PATH=
      export PKG_CONFIG_PATH=

      After this try giving the new library names after “-l” while linking.
      Let me know if this works.

  7. Please help me

    I typed in the hello.cpp program

    my paths are

    $ pkg-config –cflags opencv
    -I/usr/local/include/opencv -I/usr/local/include

    $ pkg-config –libs opencv
    -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann

    $ gcc -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -o img img.c
    img.c:1:16: fatal error: cv.h: No such file or directory
    compilation terminated.

    Why it is so?

  8. Show this error:
    hello.cpp:(.text+0x3d): undefined reference to `cvLoadImage’
    hello.cpp:(.text+0x6a): undefined reference to `cvNamedWindow’
    hello.cpp:(.text+0x7e): undefined reference to `cvShowImage’
    hello.cpp:(.text+0x8a): undefined reference to `cvWaitKey’
    hello.cpp:(.text+0x96): undefined reference to `cvDestroyWindow’
    Can anyone help ??

    • for all who are facing problem to build :

      hello.cpp:(.text+0x3d): undefined reference to `cvLoadImage’
      hello.cpp:(.text+0x6a): undefined reference to `cvNamedWindow’
      hello.cpp:(.text+0x7e): undefined reference to `cvShowImage’
      hello.cpp:(.text+0x8a): undefined reference to `cvWaitKey’
      hello.cpp:(.text+0×96): undefined reference to `cvDestroyWindow’

      execute : g++ hello.c -o hello `pkg-config –cflags –libs opencv`
      and have fun

  9. Hello sir!

    I would like to ask for help on installing opencv in linux.
    I’m a new with Ubuntu, I really need your help to get this OpenCV running.
    Thanks in advance!

    What I’m trying now is to run this simple command that I got from a book:

    #include “highgui.h”

    int main(int argc, char** argv)
    {
    IplImage* img = cvLoadImage( argv[1] );
    cvNamedWindow( “Example1”, CV_WINDOW_AUTOSIZE );
    cvShowImage( “Example1”, img );
    cvWaitKey(0);
    cvReleaseImage( &img );
    cvDestroyWindow( “Example1” );

    exit(0);
    }

    I saved it as myopencv.c on my home directory.

    When I tried to execute the following commands:

    PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:${ PKG_CONFIG_PATH }
    export PKG_CONFIG_PATH
    gcc ‘pkg-config –cflags –libs opencv’ -o myopencv myopencv.c

    I had this error message:

    myopencv.c: In function ‘main’:
    myopencv.c:5:1: error: too few arguments to function ‘cvLoadImage’
    /usr/local/include/opencv2/highgui/highgui_c.h:213:18: note: declared here

    When I entered this command:

    $PKG_CONFIG_PATH

    I had this error message:

    bash: /usr/local/lib/pkgconfig::/usr/local/lib/pkgconfig: No such file or directory

    I entered the following commands:

    pkg-config –cflags opencv
    pkg-config –libs opencv

    And I got this:

    pkg-config –cflags opencv
    -I/usr/local/include/opencv -I/usr/local/include

    pkg-config –libs opencv
    -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann

    I don’t know what to do now, I really need your help.
    Looking forward to your reply.
    Thankyou very much! 🙂

    • Try changing the code to this:
      1. Reading an image from a file:
      IplImage* img=0 ;
      img=cvLoadImage(fileName);

      Or
      2. By default, the loaded image is forced to be a 3-channel color image. This default can be modified by using:
      img=cvLoadImage(fileName,flag );
      flag: >0 the loaded image is forced to be a 3-channel color image
      =0 the loaded image is forced to be a 1 channel grayscale image
      <0 the loaded image is loaded as is (with number of channels in the file).

  10. Thanks for your post Abhi,
    When I saw your post I installed new Ubuntu 11.10 distro ans followed the instructions.
    Can’t get this to work! please help if you have some time to look at this.

    Thank you
    Viktor

    ###

    $ apt-cache search opencv
    harpia – Image Processing/Computer Vision Automatic Prgm. Tool
    libcv-dev – development files for libcv
    libcv2.1 – computer vision library
    libcvaux-dev – development files for libcvaux
    libcvaux2.1 – computer vision extension library
    libhighgui-dev – development files for libhighgui
    libhighgui2.1 – computer vision GUI library
    opencv-doc – OpenCV documentation and examples
    python-opencv – Python bindings for the computer vision library

    ###

    $ echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/include/opencv

    ###

    hello.cpp
    #include /* required to use OpenCV */
    #include /* required to use OpenCV’s highgui */
    #include

    ###

    $ g++ -o pro -I/usr/include/opencv -lcxcore -lhighgui -lm hello.cpp
    /tmp/ccX98ZnE.o: In function `main’:
    hello.cpp:(.text+0x3d): undefined reference to `cvLoadImage’
    hello.cpp:(.text+0x6a): undefined reference to `cvNamedWindow’
    hello.cpp:(.text+0x7e): undefined reference to `cvShowImage’
    hello.cpp:(.text+0x8a): undefined reference to `cvWaitKey’
    hello.cpp:(.text+0x96): undefined reference to `cvDestroyWindow’
    collect2: ld returned 1 exit status

  11. Hey Guyz ,
    I had a the following problem :

    g++ -o pro -I/usr/include/opencv -lcxcore -lhighgui -lm test.cpp
    /tmp/ccINeHqP.o: In function `main’:
    test.cpp:(.text+0x3d): undefined reference to `cvLoadImage’
    test.cpp:(.text+0x6a): undefined reference to `cvNamedWindow’
    test.cpp:(.text+0x7e): undefined reference to `cvShowImage’
    test.cpp:(.text+0x8a): undefined reference to `cvWaitKey’
    test.cpp:(.text+0×96): undefined reference to `cvDestroyWindow’
    collect2: ld returned 1 exit status

    I finally figured it out .
    Use the following compilation command .

    g++ -ggdb `pkg-config opencv –cflags –libs` YOURFILENAME.cpp -o YOURFILENAME `pkg-config –libs opencv`

    It worked for me .
    Hope this helps u .

  12. Hi Abhi,
    I have just posted a comment , but now i have found my problem, the right comment is
    tuong@tuong:~/Desktop/OpenGL$ ./halo img.png
    Thanks

  13. Hi Abhi,
    Thanks for your post, I’m a newbie in OpenCV, I have done following your article but I have a problem with loading img (I have copied an image with the name img.jpg in to the same folder of hello.cpp). Here is my problem

    tuong@tuong:~/Desktop/OpenGL$ g++ -I/usr/include/opencv -lml -lcvaux -lhighgui -lcv -lcxcore halo.cpp -o halo
    tuong@tuong:~/Desktop/OpenGL$ ./halo img
    Hello
    File not found

    Thanks for your answer pls

  14. Pingback: Using OpenCV on Linux « esrc618

  15. Hi Abishek,

    I have been trying to install and use OpenCV in windows and linux I find it hard time to do in both. First let me ask your help in windows and later with latest version of Ubuntu and OpenCV version 2.3.

    To install in Windows I follwed the procedure in the website http://opencv.willowgarage.com/wiki/MinGW

    Till step 18 in the webpage was ok and when I did step 19 ” Go to the command prompt and inside the folder “C:\OpenCV2.2MinGW” type “mingw32-make” and hit enter (takes some time)”

    I had error showing up in my terminal

    E:\OpenCV2.2MinGW>mingw32-make
    [ 2%] Built target zlib
    [ 35%] Built target opencv_lapack
    [ 36%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/alloc.obj
    In file included from E:/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:4047,
    from E:\OpenCV-2.2.0\modules\core\src\precomp.hpp:55,
    from E:\OpenCV-2.2.0\modules\core\src\alloc.cpp:43:
    E:/OpenCV-2.2.0/modules/core/include/opencv2/core/operations.hpp:1193: error: template-id `cross’ for `cv::Vec cv::Vec::cross(const cv::Vec&) const’ does not match any template declaration
    E:/OpenCV-2.2.0/modules/core/include/opencv2/core/operations.hpp:1193: error: invalid function declaration
    E:/OpenCV-2.2.0/modules/core/include/opencv2/core/operations.hpp:1200: error: template-id `cross’ for `cv::Vec cv::Vec::cross(const cv::Vec&) const’ does not match any template declaration
    E:/OpenCV-2.2.0/modules/core/include/opencv2/core/operations.hpp:1200: error: invalid function declaration
    mingw32-make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/alloc.obj] Error 1
    mingw32-make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
    mingw32-make: *** [all] Error 2

    Do you know how I can proceed with this. YOur reply will help me to get started.

    • Hi suresh,
      I have no idea about your error. I mostly go for readymade EXE’s than compiling the source code in windows. But using C Make should also be fine. Dont know why its not working in your case.

  16. g++ -o pro -I/usr/include/opencv -lcxcore -lhighgui -lm test.cpp
    /tmp/ccINeHqP.o: In function `main’:
    test.cpp:(.text+0x3d): undefined reference to `cvLoadImage’
    test.cpp:(.text+0x6a): undefined reference to `cvNamedWindow’
    test.cpp:(.text+0x7e): undefined reference to `cvShowImage’
    test.cpp:(.text+0x8a): undefined reference to `cvWaitKey’
    test.cpp:(.text+0x96): undefined reference to `cvDestroyWindow’
    collect2: ld returned 1 exit status

    Givin me this error ??
    Could u pls help me out ..

    Installed everything properly

    • Hi Rahul,
      Check whether opencv has been added to ur PATH (echo $PATH)

      If yes, what is the header that u included? This one? :

      #include < cv.h > /* required to use OpenCV */
      #include < highgui.h > /* required to use OpenCV’s highgui */

      depending on the path of opencv in $PATH, try

      #include <opencv/ cv.h > /* required to use OpenCV */
      #include < opencv/highgui.h > /* required to use OpenCV’s highgui */

  17. Pingback: Installing and configuring OpenCV 1.1 Eclipse on ubuntu 10.04 and higher » Tj.Wallas | Zone.X. - Tech-Reviews-Blog

  18. hi abhishek
    i m new to opencv i want to read a perticular frame from “fun.avi” file can u post me piece of code for reading say 210th frame from a .avi file.,which i can use in my programme.
    me:maheshmhegade@gmail.com

  19. Hello Abhishek! A really nice post, I must appreciate! 🙂
    But there is a problem with me installing it. Everything is fine till step 3, where you ask to type in the following in the terminal:

    export LD_LIBRARY_PATH=/home/opencv/lib
    export PKG_CONFIG_PATH=/home/opencv/lib/pkgconfig

    But after executing it, I couldn’t find any such directory in /home i.e. there is no such directory /home/opencv

    Then, in the next step, where do we have to create the folder? In /usr/include/opencv or /home/opencv (which doesn’t exist) or anywhere else??

    Please help me out. Thanks a lot!

    • hi. what i have written in this post is probably all i can help u with. Specify if u r stuck somewhere. And sorry i can’t help u with idle or python.

  20. anyone getting a cv.h no such file or directory when trying to compile should remove the spaces on either side in the include brackets.
    i.e. change #include to #include ‘less than’ cv.h ‘greater than’

  21. i am getting following error when i try to run demo code any idea?

    cat.jpg: file not recognized: File format not recognized

  22. wanted a start in linux but didn’t find any way
    what is the best way to start. Is ubuntu a best choice?
    concerning to programming and shell scripting etc etc
    plz help
    email me at chelperr@gmail.com
    I will be very thankful to you.

    • hi, yes ubuntu is the best linux to start with. everything is available in it… and others u can easily install through synaptic.
      Enjoy!

    • i think u should start with linux mint … i’m using ubuntu from last two years and recently switched to mint….. both ubuntu and mint are based on debian distro. but what makes mint better is it has all necessary package and software out of the box but in ubuntu u have to install different packages for playing mp3, videos. Mint comes with vlc, thunderbird and required packages for playing video and audio……….. and one more thing , mint looks far more better than ubuntu.
      mint comes in DVD(867 MB), CD (666 MB) and OEM (664 MB) versions……… mint is same as ubuntu but with extra features specially for new users as well as experienced one…

      So i’ll suggest Mint over ubuntu for u and my out of the box rating for mint is 9 while for ubuntu 5 out of 10 …………… !!!

      visit http://www.linuxmint.com/download.php for downloding mint and other informations….

    • Its a issue of incompatibility between ur cam & opencv. My friend faced it. Install latest version of openCV or try with a different cam or the problem still persists, try ur code on a different m/c. Ur code might not hv any problem.

  23. hey that after making change in to that .bashrc file, when i tried to compile the code, it gives me this error..

    No command ‘gcv’ found,

    • Hv u saved the .bashrc?… I mean u need to be superuser/root to save the changes made.
      If yes, check out the alias line again. Might b some small mistake.

  24. you are really great!!, the explaination its very useful and my installation worked at first time. maybe the most useful site . ive spent ages on that shit of windows compilers…

    • show hidden files & folder from menu.
      & ha u need to be superuser or root to edit this file. So “sudo gedit “

  25. i have got my above problem solution.
    The highgui package was not completely installed due to my weak internet connection. But after writing the command
    sudo apt-get install libhighgui4
    and
    sudo apt-get install libhighgui-dev
    It installed completely…..
    Thanx anyways for the procedure guidance…..it was very helpful

  26. Hi Abhishek,
    The command : apt-cache search opencv
    is showing that all essential library are installed but in compiling , it is showing :: error: highgui.h: No such file or directory…. The intresting thing is , it is recognizing cv.h but not highgui.h . So how do i fix this. Is it possible that only partial library of highgui get installed.

  27. thanks 😉
    i changed some things and it works..

    1_include drictories

    #include “opencv/cv.h” /* required to use OpenCV */
    #include “opencv/highgui.h” /* required to use OpenCV’s highgui */
    #include “stdio.h”

    2_Compile

    g++ -o pro -I/usr/include/opencv -lcxcore -lhighgui -lm test.cpp

    _and_run

    ./pro someimage.JPG

  28. same issue still… the message from deepak says some prob with code… wat is thr space between “” is not valid mean? Its not clear

  29. I am a newbie to linux and very much interested in learning linux. I am well aware of openCV in windows but not in linux (procedures). This is a nice guide, i tried but i get this message
    g++: ./a.out: No such file or directory
    i created a file called a.out in this location but still same message. Let me know the issues with this. Thanks in advance.

    • Hi. a.out file is the equivalent of .exe file in windows. If this file is not found after compilation, that means there were error(s) in compiling the code. Go through the errors. If u find any difficulty i’ll help.
      Abhishek

  30. For ALL those who got the following ERROR
    g++: ./a.out: No such file or directory
    g++: img: No such file or directory
    hello.cpp:2:47: error: cv.h : No such file or directory
    hello.cpp:3:62: error: highgui.h : No such file or directory
    hello.cpp:4:21: error: stdio.h : No such file or directory
    hello.cpp: In function ‘int main(int, char**)’:
    hello.cpp:7: error: ‘IplImage’ was not declared in this scope
    hello.cpp:7: error: ‘img’ was not declared in this scope
    hello.cpp:8: error: ‘printf’ was not declared in this scope
    hello.cpp:10: error: ‘cvLoadImage’ was not declared in this scope
    hello.cpp:14: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
    hello.cpp:14: error: ‘cvNamedWindow’ was not declared in this scope
    hello.cpp:15: error: ‘cvShowImage’ was not declared in this scope
    hello.cpp:16: error: ‘cvWaitKey’ was not declared in this scope
    hello.cpp:17: error: ‘cvDestroyWindow’ was not declared in this scope

    SOLTION:
    there is an error with the code when you copy and paste
    make sure you change #include “” to #include “”
    same for others
    that is the spaces withing “”is not valid

  31. Everything went peacefully till step 5.When i try to compile the code i get these errors:
    g++: ./a.out: No such file or directory
    g++: img: No such file or directory
    hello.cpp:2:47: error: cv.h : No such file or directory
    hello.cpp:3:62: error: highgui.h : No such file or directory
    hello.cpp:4:21: error: stdio.h : No such file or directory
    hello.cpp: In function ‘int main(int, char**)’:
    hello.cpp:7: error: ‘IplImage’ was not declared in this scope
    hello.cpp:7: error: ‘img’ was not declared in this scope
    hello.cpp:8: error: ‘printf’ was not declared in this scope
    hello.cpp:10: error: ‘cvLoadImage’ was not declared in this scope
    hello.cpp:14: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
    hello.cpp:14: error: ‘cvNamedWindow’ was not declared in this scope
    hello.cpp:15: error: ‘cvShowImage’ was not declared in this scope
    hello.cpp:16: error: ‘cvWaitKey’ was not declared in this scope
    hello.cpp:17: error: ‘cvDestroyWindow’ was not declared in this scope

    I think there is only one thing wrong with this.Can you please let me know what went wrong here.Thanks a million.

  32. hey, thanks a lot for the instructions. i did everything step by step but i got an error, when i compile, it says “the command could not be located because ‘usr/bin’ is not included in the PATH environment variale”..anyone know how to do this! please help
    Onty

  33. Hello,

    It works for images but I can’t get streaming from my camera. I am using ubuntu 9.10 and the camera (microsoft LifeCam 1.4) works fine with cheese so it’s not a problem with camera driver. Do you have any clues on how to solve this problem?

  34. Hi Sir,
    Its amazing I tried it first time & it worked nice.
    Best article to setup opencv in Ubuntu.
    Thank a lot.
    –Jainendra
    M.Tech.(Robotics)
    IIIT-Allahabad

  35. hi… I compile and run the code,i get an error

    g++ : ./a.out : No such file or directory

    a.out is a file? I have to create it?

    tks!
    Samuel

    • a.out is the output file(similar to .exe file in windows) that is made when ur code compiles & builds properly.
      if a.out is missing, it implies ur code didn’t got compiled/ linked/ built properly.

    • Execute this as two separate commands
      $ g++ -I/usr/include/opencv -lcxcore -lhighgui -lm hello.cpp
      and
      $./a.out img

      when you compile hello.cpp , a.out file is created in the same directory where your hello.cpp is.
      It seems compiling and running commands in here are confused by lot of people

      If you have set up opencv properly and included libraries properly rest of the code should work.

  36. Thanks a lot worked like a charm

    @Abhishek and Manju
    try this as two separate commands. make sure your current directory and and directory of hello.cpp are the same
    $ g++ -I/usr/include/opencv -lcxcore -lhighgui -lm hello.cpp

    $./a.out img

    • and I had to change
      #include cv.h
      #include highgui.h
      #include stdio.h
      to..
      #include
      #include
      #include

    • hope this will work 🙂 browser erroneously interpreted my previous comment
      and I had to change
      #include cv.h
      #include highgui.h
      #include stdio.h
      to..
      #include <cv.h>
      #include <highgui.h>
      #include <stdio.h>

    • ya obviously u need the brackets…. in wordpress when i was posting, it was taking “” as html tags. i mentioned it below too….

  37. hi…i tried installing the exact way as in ur post but when i compile and run the code,i get an error

    g++ : ./a.out : No such file or directory

    pls pls help me…

  38. Pingback: My First OpenCv Program with Qt & Eclipse « Great Blogger Julhandi

  39. I tried to compile and run the instructions, but it displayed:

    g++ -I/usr/include/opencv -lcxcore -lhighgui -lm hello.cpp
    g++: hello.cpp: No such file or directory
    jcp@jcp:~$ g++ -I/usr/include/opencv -lcxcore -lhighgui -lm sample.cpp
    sample.cpp:1:14: error: #include expects “FILENAME” or
    sample.cpp:2:14: error: #include expects “FILENAME” or
    sample.cpp:3:14: error: #include expects “FILENAME” or
    sample.cpp: In function ‘int main(int, char**)’:
    sample.cpp:6: error: ‘IplImage’ was not declared in this scope
    sample.cpp:6: error: ‘img’ was not declared in this scope
    sample.cpp:7: error: ‘printf’ was not declared in this scope
    sample.cpp:9: error: ‘cvLoadImage’ was not declared in this scope
    sample.cpp:13: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
    sample.cpp:13: error: ‘cvNamedWindow’ was not declared in this scope
    sample.cpp:14: error: ‘cvShowImage’ was not declared in this scope
    sample.cpp:15: error: ‘cvWaitKey’ was not declared in this scope
    sample.cpp:16: error: ‘cvDestroyWindow’ was not declared in this scope
    jcp@jcp:~$

    • Hi. i think u have not included cv.h & highgui.h properly.
      check this code at the start of sample.cpp:

      #include
      #include

      g++ is not able to link the opencv lib files bcoz of some problem in this #include’s.

  40. Pingback: Tweets that mention Installing OpenCV on Linux (Ubuntu) « Abhishek's… -- Topsy.com

  41. I have installed opencv on ubuntu and windows 7.It’s showing side by side configuration error in windows(Microsoft visual studio 2008)
    and
    In ubuntu i am able to compile programs but it’s not taking any input from camera.i can only able to manipulate images and other task which do not require input from camera
    I am using sony vaio laptop.

    Camera is working fine in windows 7 but when i use a program cheese in ubuntu, it says no device found.a is not

    I have installed ubuntu in other drive also as an virtual machine but it doesn’t find camera.

    Thanks.

  42. I have been trying for so long.It’s seventh day today.I installed it on windows and it’s showing side by side config error.

    Now i have read your article and installed it on Ubuntu.Thank you.

    There is problem in running a program of face detection

    ERROR: Could not load classifier cascade
    Usage: facedetect [–cascade=””]
    [–nested-cascade[=”nested_cascade_path”]]
    [–scale[=
    [filename|camera_index]

    i will appreciate your help.

    Thanks.

    • Hi. I think this piece of article can help:

      “How to run this code? As said in the code, you have to specify the exact location of the haar classifier xml file. It is normally present in the/OpenCV/data/haarcascadeslocation. You should verify that the filehaarcascade_frontalface_alt.xmlis present inside the folder or not.

      Suppose that you have installed OpenCV in its default location:C:/Program Files. Then, the exact location of the classifier is:”C:/Program Files/OpenCV/data/haarcascades/haarcascade_frontalface_alt.xml” Now, you can run the facedetect sample with this command in the prompt: facedetect –cascade=”C:/Program Files/OpenCV/data/haarcascades/haarcascade_frontalface_alt.xml”

      If you are using an IDE, and want to play with the source code, you’ll need to add the classifier location to the additional command line arguments. In Visual C++, you can go toProject->Debugging->Command Arguments In Additional Options tab, enter this:–cascade=”C:/Program Files/OpenCV/data/haarcascades/haarcascade_frontalface_alt.xml” Now, the source code will compile and run fine.”

      Its taken from OpenCV’s site: http://opencv.willowgarage.com/wiki/FaceDetection
      Good Luck!

  43. Hello,
    when opening synaptic I cannot find anything matching opencv, probably the repository is missing.
    Could anyone kindly tell me which repository should I add for that? Or do you see any other reason?

    Best

    • Hi opencv_beg, the problem is with the repository only. you can try different repositories (from other countries too) in the settings of Synaptic. And search for opencv. You will surely get in some.
      (If not, then try next day… it works 😉

  44. HI abhishek
    i am using ubuntu 9.04 version and trying to install opencv with ffmpeg support
    first i installed ffmpeg using the sudo apt-get install ffmpeg*
    and downloaded the opencv2.1.0 used cmake and installed
    but ffmpeg is not getting included into the opencv can u help me…?

  45. EXCELLENT POST ! ….. however in my experience OpenCV works lot more smoothly in Ubuntu 9.10 (I have used OpenCV in both Ubuntu 9.10 and Ubuntu 9.04).

    Is there any quick command line to check for version of the OpenCV etc ?

    • You can check OpenCV’s (or for that matter any installed program’s) version in the synaptic package manager. Just open it & search for “opencv”. Good thing in this is u get to know which is the latest version available in the repository.

      I have not tried OpenCV in Ubuntu 9.10.
      Have u checked out OpenCV 2.0? It has restructured all the libraries.

  46. sorry for the double post, it seems that for some reason WordPress erased some key words from my previous post. I was trying to say that I don’t have the file opencv.h , but I used another one called cv.h and the program executed well.

    • @Minguel: yes, it should be “cv.h” only. thanks for bringing this to notice. I will update it.

  47. Thanks a lot for the info about installing openCV under Ubuntu, specially the quick test program, it was very useful to verify the success of my installation (although to install openCV I followed mostly the steps mentioned in the INSTALL.txt file provided with the sources).

    I just have one comment-question, for some reason in my include directory (/usr/local/include/opencv) I don’t have any thus I just modified that line of code in order to include and the program ran without any problem. My doubt is, is it normal not to have that include file?

    Cheers

    • thanks for bringing that to notice.
      those #includes got erased as wordpress considered them to be html tags…
      it should be:
      #include opencv.h
      #include highgui.h
      #include stdio.h
      with those “”…as usual

  48. This is Perfect!!! Thanks a lot!!! I can’t believe I spent my entire evening trying to install OpenCV through terminal when it was this simple using the Synaptic Package Manager!!!!
    Suggestion to others: Follow the instructions above carefully and you should be good on Ubuntu 9.10
    Tips:
    1. pkg-config –cflags opencv instead of copying pkg-config –cflags opencv
    2. comment out printf
    include files: “cv.h”, “highgui.h”,

    KUDOS TO THE AUTHOR OF THIS ARTICLE!!!!

    • hi there! I have also the same problem (like others) with the compilation of this script.
      here the output of compiler:

      hello.cpp:2:10: error: #include expects “FILENAME” or
      hello.cpp:3:10: error: #include expects “FILENAME” or
      hello.cpp:4:10: error: #include expects “FILENAME” or
      hello.cpp: In function ‘int main(int, char**)’:
      hello.cpp:7:1: error: ‘IplImage’ was not declared in this scope
      hello.cpp:7:11: error: ‘img’ was not declared in this scope
      hello.cpp:8:17: error: ‘printf’ was not declared in this scope
      hello.cpp:10:29: error: ‘cvLoadImage’ was not declared in this scope
      hello.cpp:14:26: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
      hello.cpp:14:44: error: ‘cvNamedWindow’ was not declared in this scope
      hello.cpp:15:27: error: ‘cvShowImage’ was not declared in this scope
      hello.cpp:16:12: error: ‘cvWaitKey’ was not declared in this scope
      hello.cpp:17:26: error: ‘cvDestroyWindow’ was not declared in this scope

      What can i do? in order to link the opencv libraries.
      Thenks

    • Hi. Plz add < and > just before and after the header file names in all the #include lines. eg.
      #include< cv.h >

      (I have updated the code. Copy-paste that, it should work.)

What do you think??

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s