OpenCV in Eclipse

This time it's all about setting up the mighty “pixel”-processing library OpenCV1 in the well-known IDE called Eclipse2. Before we get our hands dirty, I should mention that it will be a very brief post, since it is only a necessary preparation in order to get started with the next project coming up, dealing with mini robots doing penalty shootouts (← You surely don't wanna miss that ;)).
So nuff said, let's get started!

(In this tutorial I assume that you are using linux and have Eclipse already installed)

If you have already installed OpenCV, you can skip to point 3.
  1. First get OpenCV from the link below. I used the latest version, which was 2.4.5 at that time.

     


  2. Well done! Now unzip it, build it & install it.


    > cmake .

    > sudo make install


  3. If the previous steps were successful, you are good to go! Now switch to Eclipse and create a new project. In my case it's called OpenCVLocalTest.

    Ceate new project


  4. Next create a new source file (e.g. OpenCVLocalTest.cpp) and paste the following source. (This step is optional.)

    Add source file
    #include <cv.h>  
    #include <highgui.h> 
    
    using namespace cv;
    
    int main(int argc, char** argv) {
     // create image.
     Mat image;
     // insert your image here (e.g. logo.png).
     image = imread("logo.png", 1);
    
     // test if image is loaded properly.
     if (!image.data) {
      printf("No image loaded\n");
      return -1;
     }
    
     // create window with the size of the image.
     namedWindow("sciWave", CV_WINDOW_AUTOSIZE);
     imshow("sciWave", image);
    
     // close windows by pressing any key.
     waitKey(0);
     return 0;
    }
    

  5. So now it gets serious! Open the properties dialogue for your newly created project and switch to “C/C++ Build” → “Settings”. Under “GCC C++ Compiler” → “Includes” you have to add the path to the OpenCV headers you want to include. They should be located in /usr/local/include/OpenCV/.

    Add includes

  6. After that, you have to set the “Library search path (-L)”, located under “GCC C++ Linker” → “Libraries”, to the path of the folder containing the OpenCV libraries. (Normally located in /usr/local/lib/.)

    Add libraries

  7. The last part is to finally add all the libs, that you actually want to use in your project, in the “Libraries (-l)”-section.

  8. Ready to roll? Press build all, insert an image and start the program!

    Final result SciWave
Yeah, now we're finished with the boring preparations and about to rock! I hope it was helpful to you and I can't wait for your comments, so feel free to share your thoughts ;-)
http://www.sciwave.com/
1 Kommentar: