Monday, January 19, 2015

Digital Image processing with c++ ( Chapter 1 ) - Configure eclipse with open CV


This is my first blog post so there can be many mistakes please help to to correct my mistakes and make this blog more impressive.Today I'm going to explain you how to Configure working environment for Digital image processing with C++.For that first we need to download few softwares and libraries.

Prerequisites


Java JRE
Windows 7 or later

Development tools



  • Eclipse IDE for C/C++     Download
  • MinGW C++ compiler     Download
  • cmake     Download   (make sure to download binary distributions)
  • OpenCV     Download  


  • Here I use Cmake to compile my own binaries because lots of questions going on that precompiled binaries are NOT working for well.

    Configuration


    1. Install MinGW C++ compiler. During installation , select “C++ Compiler” and “MSYS Basic System” for installation
    2. Add system PATH to "c:/mingw/bin" (Right click on my computer-> Properties->Advance system settings->Environment variable -> select path and click edit) example
    3. Install Cmake
    4. Install/unzip Opencv to C:\OpenCV\
    5. Run cmake GUI tool
    6. Choose C:\OpenCV\ as source
    7. Choose the destination, C:\OpenCV\x86 ,This is where to build the binaries
    8. Press Configure button, choose MinGW Makefiles as the generator.(then in red highlighted area We can choose many options but it's better to use default options if you are beginner)
    9. Press the Configure button again then press the Generate button
    10. Exit the cmake program when the generating is done
    11. Run the command line mode (cmd.exe) and go to the destination directory C:\OpenCV\x86 (type :- cd /OpenCV\x86)
    12. Type "mingw32-make". You can see a progress of building binaries. If the command is not found error occur problem is in system path (step 2)
    13. Add system PATH to C:\OpenCV\x86\bin (similar as step 2)
    14. Restart Computer
    15. Extract the downloaded Eclipse and run it
    16. Creating a new C++ Project from the File and New menu
    17. Select “Hello World C++ Project” under Executable for the Project Type, and MinGW GCC for the Toolchain of your New C++ Project. Type a Project Name and click the Finish button.
    18. Add “-static-libgcc -static-libstdc++” as Linker flags for your new project. This text should be added to the Linker flags field, which can be found by right-clicking on the new Project in the Project Explorer and clicking on Properties. Under the Project Properties, expand the C/C++ Build menu and click on Settings. Under the Tool Settings tab, expand the MinGW C++ Linker menu and click on Miscellaneous. Add the text to the Linker flags field, then click the Apply button. (More details ) about step 16 to 18
    19. Go to Project > Properties > C/C++ Build > Settings > GCC C++ Compiler > Includes, and add the source OpenCV folder "C:\OpenCV\build\include"
    20. Add the built OpenCV library folder, "C:\OpenCV\x86\lib" to Library search path (-L)
    21. Go to Project > Properties > C/C++ Build > Settings > MinGW C++ Linker > Libraries, and add to the Libraries (-l) ONE BY ONE (this could vary from project to project, you can add all of them if you like or some of them just the ones that you need for your project,to run our simple project "opencv_core2410 " and "opencv_highgui2410 "):
        opencv_calib3d2410
        opencv_contrib2410
        opencv_core2410
        opencv_features2d2410
        opencv_flann2410
        opencv_gpu2410
        opencv_highgui2410
        opencv_imgproc2410
        opencv_legacy2410
        opencv_ml2410
        opencv_nonfree2410
        opencv_objdetect2410
        opencv_photo2410
        opencv_stitching2410
        opencv_video2410
        opencv_videostab2410

      *2410 mean opencv version 2.4.10 therefore this will need to change if you use other version

    22. Copy this code to your work place

      #include <opencv2/highgui/highgui.hpp>
      #include <opencv2/core/core.hpp>
      
      using namespace std;
      using namespace cv;
      
      int main()
      {
      
          Mat img=imread("c:/example_image.png");
          namedWindow("cat",WINDOW_AUTOSIZE);
          imshow("cat",img);
          waitKey(0);
          return 1;
      
      }
      

      (download this sample image and save it in c:/example_image.png)
    23. Click Build Project under the Project menu, then click Run under the Run menu.
    24. example_image.png will pop up !!!!!!!!!!!!!!

    Note :- if error occurs like this
    'cv::Exception' what(): C:\opencv\sources\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow
    Problem is incorrect path to image (c:/example_image.png)

    No comments: