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:
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)
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
13. Type the following command to check the location of opencv lib files
pkg-config –libs opencv
-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
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