A new version of OpenCV has been released so… Time to update!




(This is an updated version of the article I wrote months ago: Installing and using OpenCV 3.2 with Eclipse and MinGW on Windows 10. )

Getting started

– You will need:

 

Configuring OpenCV

  • Add MinGW to System Path
    – Edit your System Environment variables (you can search for Environment in Windows’ Start Menu) ;
    – Click on Path, and Edit;
    – Then, hit New, and add the address of your MinGW bin  folder.

 

Adding environment variables

 

  • Extract OpenCV to a folder, rename it opencv_src- Inside it, create a folder named Mingw_build

 

Now, let’s compile OpenCV

  • Open CMake-gui;
  • Set “Where is the source code:” to opencv_srcand “Where to build the binaries” to opencv_src/Mingw_build/
  • Click on Configure, choosing Eclipse CDT4 – MinGW MakeFilein the next window, then next;

 

 

Optional Step: OpenCV_Contrib Extra modules

  • If you want a simple and flawlessly working installation, just skip this step and go to the next, it’s not obligatory for you to have opencv_contrib.
  • After the “Configure” is finished, Set OPENCV_EXTRA_MODULES_PATH  to opencv_contrib/modules folder

 

Installing opencv_contrib

 

Building and Installing

  • After the “Configure”, on my PC I had to deselect the options ENABLE_PRECOMPILED_HEADERS and BUILD_opencv_python3  to correctly compile.
  • Hit “Generate”;
  • Now, open the CMD/PowerShell, and navigate to opencv_src/Mingw_build/
  • Inside opencv_src/Mingw_build  type mingw32-make  and hit enter;- This step probably will take a while, wait until it’s finished.
  • Install using mingw32-make install
  • Finally, add C:\opencv_src\Mingw_build\install\x64\mingw\binto your system path.
  • I have seen errors related also to the following parameters: WITH_PTHREADS_PF  , WITH_OPENCL  and ENABLE_CXX11  options. Try unchecking then if something occurs.

Configuring Eclipse

  • Open it and create a C++ program using the following OpenCV  example:

 

  • Go to
    Project > Properties > C/C++ Build > Settings > GCC C++ Compiler > Includes
    and add the source OpenCV folder

    C:\opencv_src\Mingw_build\install\include

Project > Properties > C/C++ Build > Settings > GCC C++ Compiler > Includes

 

  • Go to
    Project > Properties > C/C++ Build > Settings > MinGW C++ Linker > Libraries
    , and add this to the Libraries (-l), separately as shown in the image
  • For OpenCV 3.4:

  • For OpenCV 3.3:

 

  • If you are using a different OpenCV version, change the number at end of each lib to match your version

 

 

  • You can  add additional libraries from lib folder if you need, just follow the presented format;
  • Add
    C:\opencv_src\Mingw_build\install\x64\mingw\lib
    to Library search path (-L);
  • Build the project. There are a lot of o ways of running it, e.g.:
    • Open the Powershell or CMD, go to the executable folder and type:
      yourprogramname.exe image.jpg
    • Or put the path of the image you want to show in the code, changing the following line:
      • image = imread(argv[1], CV_LOAD_IMAGE_COLOR);
        to
      • image = imread("C://YOURIMAGEPATH.jpg", CV_LOAD_IMAGE_COLOR);

 

  • Updates

04/11/17 – Changed the order of some steps;
22/11/17 – Added MinGW-w64 instead of the conventional MinGW;
11/01/18 – Added support to OpenCV 3.4
12/04/18 – Added a better explanation for running the test code
12/09/18 – Added version 3.4.3 links and error correction sentences
 

 

 

Have fun with your projects! 
If this post helped you, please consider buying me a coffee 🙂