0

Possible Duplicate:
OpenCV on ubuntu 11.10

I am having a very hard time trying to install OpenCV on Ubuntu. I believe that I have already installed OpenCV; however, I am trying to compile one of the samples program kalman.cpp with Eclipse, and I am not able to compile it. My problem I believe is linking with the libraries.

I have seen a lot of tutorial, and I do not understand why after installing opencv in my computer, I get the following output after using the command pkg-confi opencv --libs:

manuel@manuel:~$ sudo pkg-config opencv --libs
/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

Every tutorial out there the libraries appear as:

-L/where/you/have/installed/opencv/lib -lcxcore -lcv -lhighgui -lcvaux  

This is really annoying because Eclipse cannot find the library as libopencv_contrib.so. It is waiting for something as -lopencv_contrib

I really appreciate the help. Please let me know what I am doing wrong.

Community
  • 1
  • 1
MaM
  • 15
  • 1
  • 3
  • 5
  • It's not necessary to SHOUT to get your questions ANSWERED HERE. The shift key works very well, and using it makes your question easier to read. Thanks. – Ken White Oct 12 '12 at 00:13
  • did you install via aptitude ? have you tried ``pkg-config opencv --cflags --libs`` ? – moooeeeep Oct 12 '12 at 07:59

2 Answers2

0

I have never used OpenCV with Eclipse. I basically compile it using gcc or g++ (depending on c or C++) file.

for C file,

$ gcc -ggdb `pkg-config --cflags opencv` -o `basename opencvtest.c .c` opencvtest.c `pkg-config --libs opencv`

for C++ file,

$ g++ -ggdb `pkg-config --cflags opencv` -o `basename opencvtest.cpp .cpp` opencvtest.cpp `pkg-config --libs opencv`

For more information, see http://jayrambhia.wordpress.com/2012/05/08/beginning-opencv/

If you are comfortable with this, I don't think you would need to use Eclipse.

Hope this helps.

Froyo
  • 17,947
  • 8
  • 45
  • 73
0

To link to a library you need to specify the path to the directory where it is located using the -L /path/to/libraries flag.

You also need the specific libraries you want using -l my_library.

Usually you also need to specify the necessary include paths using -I /path/to/headers


pkg-config can be used as a helper to do this, as it returns the exact parameters you need in order to use a library.

You should rather use it like this:

echo `pkg-config opencv --cflags --libs`

resp.

g++ my_first_opencv_app.cc `pkg-config opencv --cflags --libs`

which on my system evaluates to

g++ my_first_opencv_app.cc -I/usr/include/opencv -lml -lcvaux -lhighgui -lcv -lcxcore

To get it to work with eclipse, you probably need to specify the include path (/usr/local/include/opencv ?), the library path (/usr/local/lib ?) and the libraries you need via some GUI element somewhere in the project settings. You probably shouldn't need pkgconfig then.

moooeeeep
  • 31,622
  • 22
  • 98
  • 187