Shazia Akbar
View Shazia Akbar's Github repositories View Shazia Akbar's profile on LinkedIn View Shazia Akbar's Google Scholar page

Setting up OpenCV on Eclipse

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.

Installing OpenCV

  1. Download OpenCV: You can find a range of downloads for different platforms on the original site:
  2. Download MinGW. Remember to download the right version (64-bit/32-bit), both of which can be found here:
  3. Download CMake: Installation file is available from I just downloaded the windows .exe installation file. During the installation process you don’t need to add CMake to the system Path variable.
  4. Open the CMake GUI and point the source to where you installed OpenCV (i.e. “C:/OpenCV/”) and the destination to “C:/OpenCVMinGW/”
  5. Hit the “Generate” button.
  6. cmake

  7. 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.
  8. You shouldn’t have any red block now so go ahead and hit the “Compile” button.
  9. 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…
  10. Add the bin directory, “C:/OpenCVMinGW/bin” to your system Path variable. (Right click “MyComputer”, click “Properties -> Advanced Settings -> Environment Variables”)
  11. Restart your machine.

Building a project

  1. Create a new C++ empty project in Eclipse. Select the “GCC MinGW” compiler option when the “New Project” box pops up.
  2. 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/”
  3. eclipse_include

  4. Underneath “GCC++ Compiler” there should be a “MinGW Compiler” option. Expand this to get the “Linker” option. Click on it.
  5. 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)
  6. 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.
  7. eclipse_lib

  8. Hit “Apply”.
  9. Now we just need to test our project with some dummy code. Create a new .cpp file and put the following code in it:

#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
Mat im = imread(argc == 2 ? argv[1] : "C:/lena.jpg", 1);
if (im.empty())
cout << "Cannot open image!" << endl;
return -1;
imshow("image", im);
return 0;

Comments are closed