I recently moved from Visual Studio to Eclipse and found I had to build OpenCV binary files on my computer. After a lot of hunting around, I found the following easy steps. This uses the MinGW compiler instead of Visual Studio and is ideal for OpenCV development on other machines.
- Download OpenCV: You can find a range of downloads for different platforms on the original site: http://opencv.org/downloads.html
- Download MinGW. Remember to download the right version (64-bit/32-bit), both of which can be found here: http://sourceforge.net/projects/mingw/files/
- Download CMake: Installation file is available from http://www.cmake.org/download/. I just downloaded the windows .exe installation file. During the installation process you don’t need to add CMake to the system Path variable.
- Open the CMake GUI and point the source to where you installed OpenCV (i.e. “C:/OpenCV/”) and the destination to “C:/OpenCVMinGW/”
- Hit the “Generate” button.
- Once it has completed the GUI will show you red blocks. Uncheck all the options that you don’t need. In my case, that was most of them and hit “Generate” again.
- You shouldn’t have any red block now so go ahead and hit the “Compile” button.
- To create the .bin files you need to do another step: Go to “C:/OpenCVMinGW” in the command prompt. Then type “min32-cmake” and hit Enter. This will create the files which you need in Eclipse…
- Add the bin directory, “C:/OpenCVMinGW/bin” to your system Path variable. (Right click “MyComputer”, click “Properties -> Advanced Settings -> Environment Variables”)
- Restart your machine.
Building a project
- Create a new C++ empty project in Eclipse. Select the “GCC MinGW” compiler option when the “New Project” box pops up.
- Go to “Project” -> “Properties” and under “GCC++ Compiler” expand “Build”. There should be a box where you can define additional include paths. Add “C:/OpenCV/build/include/”
- Underneath “GCC++ Compiler” there should be a “MinGW Compiler” option. Expand this to get the “Linker” option. Click on it.
- In the additional library path box (bottom) add “C:/OpenCV/build/x64/mingw/lib” (change x64 to x86 if you are on a 32-bit machine)
- In the additional libraries box (top) add “opencv_core246” and “opencv_highgui246”. You may have to change the version 246 to something else. Check in the “C:/OpenCV/build/x64/mingw/lib” folder. After we test the project you can add the other libraries you need here.
- Hit “Apply”.
- Now we just need to test our project with some dummy code. Create a new .cpp file and put the following code in it:
using namespace cv;
using namespace std;
int main(int argc, char** argv)
Mat im = imread(argc == 2 ? argv : "C:/lena.jpg", 1);
cout << "Cannot open image!" << endl;