Monday, January 16, 2012

Installing OpenCV 2.3 in Eclipse in Ubuntu 11.04( updated to 12.10)

I'm writing this particular post because I didn't find a convincing working easy to follow article of how to install OpenCV for Eclipse in Ubuntu 11.04 and up (till 12.10).

Installing OpenCV
  1. Install OpenCV libraries from Ubuntu Software Center. Install libcv, libcv-dev, libhighgui, libhighgui-dev (and Whatever other libraries of your favor.)
  2. You can check the installation by opening up a terminal and typing pkg-config --libs opencv and pkg-config --cflags opencv
    and it should result something like this if you have installed all the libraries,

    -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann 

    -I/usr/include/opencv 
Setting up Eclipse
  1. Create a new C++ project and fill in the details 
  2. Then go to Project>Properties>C/C++ Build>Settings> Tools Tab
  3. Under GCC C++ compliler > Directories add /usr/include/opencv


      4. Then under GCC C++ Linker > Libraries add these parameters


Congratulations !! Now you are good to go. Here's a test program to test your configurations..!!

 #include “highgui/highgui.hpp”
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” );
}
// add a image and rename the img parameter from "Example 1" to whatever your image file name is :)