Installing opencv in linux(Ubuntu) from .tar.gz file


I installed opencv for g++ in Ubuntu 9.04 (jaunty) through the following procedure.
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.
ii. Type out the following code to know the version of GTK+ installed on ur pc.

$ dpkg -l | grep libgtk

GTK is graphical user interface library. OpenCV requires GTK+ 2.0 or higher for displaying images.
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.

If both g++ & GTK+ 2.0 are there then proceed as follows:
1. extract the opencv.tar.gz(right click> extract) into a folder, say “opencv”
2. copy that folder to /home
3. open terminal & cd to that folder
$ cd /home/opencv

4. type out:
./configure –prefix=/home/opencv –enable-apps –with-gnu-ld –with-x

If g++ is not installed, error may come as:
checking for C++ compiler default output file name… configure: error: C++ compiler cannot create executables
See `config.log’ for more details.

If you check this config.log, it says that g++ compiler not found. So you need to install it first.

5. Assuming all goes well, the configuration program will end with a prompt to ‘make’. Do that and then register the libraries (make install).

6. sudo make
Wait patiently, it’ll take time.
7. sudo make install
8. go to /home/ using
$ cd ~

9. Open .bashrc file using your favourite editor, eg:
$ gedit .bashrc

10. Append the following 2 lines to it:(before adding check whether these 2 paths respectively contain “lcxcore” & “opencv.pc”. If no, findout the path where these two files are & then modify the path accordingly)

export LD_LIBRARY_PATH=/home/opencv/lib
export PKG_CONFIG_PATH=/home/opencv/
and save & close .bashrc

11. Close the terminal & reopen(as this process requires relogin of the terminal)
12. Type the following command to check the location of opencv
pkg-config –cflags opencv

o/p:
-I/home/opencv/include/opencv

13. Type the following command to check the location of opencv lib files
pkg-config –libs opencv

o/p:
-L/home/opencv/lib -lcxcore -lcv -lhighgui -lcvaux -lml

14. To compile & build your code, cd into the folder where u have your program(*.cpp) & do:
$ g++ -I/home/opencv/include/opencv -L/home/opencv/lib -lcv -lcxcore -lcvaux -lhighgui -lm”

15. To run: $./a.out
or $./a.out

If things like the following appear-
recompile libraries using Windows,GTK+ or Carbon
Terminating blah blah..

Then goto synaptic Package Manager & install the library files for GTK+.
Then restart from step#3

16.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/home/opencv/include/opencv -L/home/opencv/lib -lcv -lcxcore -lcvaux -lhighgui -lm”

and save. Close the terminal and open it again.

17. Now onwards, to compile, build & run a program, u can simply do:
$ gcv filename.cpp
$ ./a.out img_name.extension

Enjoy!!!

Advertisements

7 responses to “Installing opencv in linux(Ubuntu) from .tar.gz file

  1. Also are you sure there are files named “lcxcore” or “lcv” etc? Coz I have openCV installed here on a computer, it works fine, all the codes run but when I searched the system for those files, couldn’t find them. Same system configs, Ubuntu 9.04

    • the -lcxcore automatically searches for files named cxcore.a and libcxcore.a

      Try adding a ‘/’ at the end of the -I flag.so it looks like -I/home/opencvlib/includes/opencv/

  2. Hey,
    I tried uninstalling it from Synaptics but couldn’t as it doesn’t show opencv installed in my comp.
    These are the errors I get –
    First after this command – ./configure –prefix=/home/opencv –enable-apps –with-gnu-ld –with-x, I get this warning – warning : unknown command: –with-x
    but then it goes on to configure it and am guessing it does it properly.
    sudo make also takes a long time but finishes off fine.
    But when I do sudo make install, I see this output –

    /usr/bin/install: `opencv/cv.h’ and `/home/opencv/include/opencv/cv.h’ are the same file
    /usr/bin/install: `opencv/cv.hpp’ and `/home/opencv/include/opencv/cv.hpp’ are the same file
    /usr/bin/install: `opencv/cvaux.h’ and `/home/opencv/include/opencv/cvaux.h’ are the same file
    /usr/bin/install: `opencv/cvaux.hpp’ and `/home/opencv/include/opencv/cvaux.hpp’ are the same file
    /usr/bin/install: `opencv/cvcompat.h’ and `/home/opencv/include/opencv/cvcompat.h’ are the same file
    /usr/bin/install: `opencv/cvstreams.h’ and `/home/opencv/include/opencv/cvstreams.h’ are the same file
    /usr/bin/install: `opencv/cxmat.hpp’ and `/home/opencv/include/opencv/cxmat.hpp’ are the same file
    /usr/bin/install: `opencv/cvtypes.h’ and `/home/opencv/include/opencv/cvtypes.h’ are the same file
    /usr/bin/install: `opencv/cvver.h’ and `/home/opencv/include/opencv/cvver.h’ are the same file
    /usr/bin/install: `opencv/cvvidsurv.hpp’ and `/home/opencv/include/opencv/cvvidsurv.hpp’ are the same file
    /usr/bin/install: `opencv/cvwimage.h’ and `/home/opencv/include/opencv/cvwimage.h’ are the same file
    /usr/bin/install: `opencv/cxcore.h’ and `/home/opencv/include/opencv/cxcore.h’ are the same file
    /usr/bin/install: `opencv/cxcore.hpp’ and `/home/opencv/include/opencv/cxcore.hpp’ are the same file
    /usr/bin/install: `opencv/cxerror.h’ and `/home/opencv/include/opencv/cxerror.h’ are the same file
    /usr/bin/install: `opencv/cxflann.h’ and `/home/opencv/include/opencv/cxflann.h’ are the same file
    /usr/bin/install: `opencv/cxmisc.h’ and `/home/opencv/include/opencv/cxmisc.h’ are the same file
    /usr/bin/install: `opencv/cxoperations.hpp’ and `/home/opencv/include/opencv/cxoperations.hpp’ are the same file
    /usr/bin/install: `opencv/cxtypes.h’ and `/home/opencv/include/opencv/cxtypes.h’ are the same file
    /usr/bin/install: `opencv/highgui.h’ and `/home/opencv/include/opencv/highgui.h’ are the same file
    /usr/bin/install: `opencv/highgui.hpp’ and `/home/opencv/include/opencv/highgui.hpp’ are the same file
    /usr/bin/install: `opencv/ml.h’ and `/home/opencv/include/opencv/ml.h’ are the same file
    make[2]: *** [install-pkgincludeHEADERS] Error 1
    make[2]: Leaving directory `/home/opencv/include’
    make[1]: *** [install-am] Error 2
    make[1]: Leaving directory `/home/opencv/include’
    make: *** [install-recursive] Error 1

    Any idea why?
    Thanks.

  3. Hi Abhishek,
    I installed OpenCV by the method given and tried compiling the sample code given by you in your other post.

    First of all, I couldn’t find any lcxcore file in my comp. But there are libcxcore files in my opencv/lib folder. Are these the same?
    Secondly, when I try to build the code using g++ -I/home/opencv/include/opencv -L/home/opencv/lib -lcv -lcxcore -lcvaux -lhighgui -lm, I get this error –
    /usr/bin/ld: cannot find -l/home/opencv/include/opencv
    collect2: ld returned 1 exit status

    Why?

    • U need to reload ur repositories & reinstall opencv. Its not installed properly on ur system. From synaptic, do complete removal of opencv & then reinstall with reloaded repositories.

  4. Pingback: Installing OpenCV on Linux « Hary Mulyadi

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