Wednesday, 31 July 2013

Configuring OpenCV 2.4.5, Eclipse CDT (Juno), MinGW (x86) on Windows 7

Eclipse CDT Juno was already installed.

My procedure was as follows:

 1. Download and install MinGW and add to the system PATH with  c:/mingw/bin

 2. Download cmake from and install it

 3. Download OpenCV2.4.5 Windows version

 4. Install/unzip Opencv to C:\OpenCV245PC\ (README,index.rst and CMakeLists.txt are here with all subfolders)

 5. Run CMake GUI tool

 6. Choose C:\OpenCV245PC\ as source

 7. Choose the destination, C:\OpenCV245MinGW\x86  where to build the binaries

 8. Press Configure button, choose MinGW Makefiles as the generator. There are some red highlights in the window, choose options as you need. 

 9. Press the Configure button again. Configuring is now done.

 10. Press the Generate button.

 11. Exit the program when the generating is done.

 12. Exit the Cmake program.

 13. Run the command line mode (cmd.exe) and go to the destination directory C:\OpenCV245MinGW\x86

 14. Type "mingw32-make" (without quotation marks). You will see a progress of building binaries. If the command is not found, you must make sure that the system PATH is added with c:/mingw/bin. The build continues according the chosen options to a completion.

 15. In Windows system PATH (My Computer > Right button click > Properties > Advanced > Environment Variables > Path) add the destination's bin directory, C:\OpenCV245MinGW\x86\bin


 17. Go to the Eclipse CDT IDE, create a C++ program using the sample OpenCV code (You can use code from top of this topic).

 18. Go to Project > Properties > C/C++ Build > Settings > GCC C++ Compiler > Includes, and add the source OpenCV folder (including quotation marks) "C:\OpenCV245PC\build\include"

 19. 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): 
(for later version like opencv 2.4.6 change below 245 number to 246)opencv_calib3d245

 20. Add the built OpenCV library folder (including quotation marks),  "C:\OpenCV245MinGW\x86\lib" to Library search path (-L)

You can use this code to test your setup:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main()

Mat img = imread("c:/lenna.png", CV_LOAD_IMAGE_COLOR);

namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
imshow("MyWindow", img);

return 0;

Don't forget to put image to the C:\ (or wherever you might find suitable, just be sure that eclipse have read acess.

No comments:

Post a Comment