Install OpenCV 4.5.5 for C++, Windows 10, Code::Blocks, TDM-GCC-64

Sourabh Jigjinni
5 min readNov 29, 2018

--

This is a step-by-step installation of OpenCV 4.5.5 on Windows. I was inspired to make this installation guide with the help of screenshots, to make it as easy as possible for new users to get started. Thanks to Zahid Hasan for the guide on version 3.2.0 which most of this is based on.

1. Install Code::Blocks

Download Code::Blocks here, or google codeblocks > downloads > Download the binary Release.

Click on the sourceforge.net link for the codeblocks-20.03-setup.exe option as we want to use TDM (64 bit) compiler.

2. Install TDM-GCC

Download TDM-GCC here. Make sure to select the 64 bit version.

Install it in C:\ drive. it will look like C:\TDM-GCC-64\

3. Download the source of OpenCV 4.5.5

Download OpenCV 4.5.5 and click sources to get the zip file.

Create folders:

  • C:\opencv\source\
  • C:\opencv\build\

Copy/move the opencv-4.5.5.zip file inside the C:\opencv\source\ folder, and unzip it here.

Optional Step: If you need extra-modules, we can download them by following steps mentioned here. I usually use the Aruco module for tag detection. Ignore this if you are new.

4. Install CMake

Download CMake and install.

5. Build the Binaries

  1. Open cmake, set source path to C:\opencv\source\ and binary path to C:\opencv\build.
  2. Click configure
  3. Choose CodeBlock — MinGW Makefiles (Should be set by default)

After configuring you will see options in red. We need to disable some of these to build the system:

Firstly I usually disable all python and Java bindings. Type into the search bar:

  • untick WITH_MSMF (media foundation needs special win sdk, only available for VS)
  • ENABLE_PRECOMPILED_HEADERS=OFF (untick)
  • WITH_IPP=OFF WITH_TBB=OFF (again libs available are for VS only) (untick)

MAKE SURE

  • WITH_MFMS=OFF (UNTICK)
  • WITH_IPP=OFF (UNTICK)
  • WITH_TBB=OFF (UNTICK)
  • ENABLE_PRECOMPILED_HEADERS=OFF (UNTICK)

And

  • WITH_OPENCL=ON
  • WITH_OPENCL_D3D11_NV=OFF (UNTICK)
  • WITH_DIRECTX=ON

Lastly

  • BUILD_PROTOBUF = OFF (UNTICK)
  • PROTOBUF_UPDATE_FILES = OFF (UNTICK)
  • WITH_PROTOBUF = OFF (UNTICK)
  • OPENCV_ENABLE_ALLOCATOR_STATS = OFF (UNTICK)

Optional Step follow up: If you downloaded the extra-modules, now is the time to enable them. Refer here for ALL modules. Refer here for only Aruco module.

Next click Generate.

  1. You will find a codeblocks project file (opencv.cbp) in C:\opencv\build folder. Just double click it and codeblocks should load it. If it doesn’t just find the codeblocks app and open it.
  2. Go to ‘settings‘, choose ‘compiler’ and click ‘Toolchain executable‘. In the ‘compiler’s installation directory‘ field choose the “bin” folder of MinGW C:\TDM-GCC-64\bin. set the following:
  • c compile: gcc.exe
  • c++ compiler: g++.exe
  • Linker for dynamic libs: ar.exe

3. DONT BUILD TARGET IN A HURRY, this is where I went wrong, while following Zahid Hasan’s article. Select build > select target > install

4. After this step you can build.

Tip: the percentage of the build done is shown here. This will take a while depending on your hardware.

If logs aren’t visible by default, go to View > Logs, or press F2

5. Add C:\opencv\build\install\x64\mingw\bin to the path.

  • Add path variable in windows 10 with screenshots — link

Tip: you can check path variables with echo %path:;=&echo.% in command prompt(cmd) or $Env:Path.Split(‘;’) in powershell.

6. Run a C++ test program

  1. Create a test project in Code::Blocks. Select console application.
  2. Go to settings -> compiler. Select ‘search directories’ and in the ‘compiler’ tab chose the followings:
  • C:\opencv\build\install\include
  • C:\opencv\build\install\include\opencv2

3. Select ‘Linker’ tab and add C:\opencv\build\install\x64\mingw\lib

4. Go to ‘Linker Settings’ and add all the libraries from C:\OpenCV\my_build\install\x64\mingw\lib folder

If it looks like this, all is good. Just one last step of using c++11 standard.

5. Set the compiler to c++11 standard (Settings -> Compiler)

6. Edit your main.cpp and add this:

7. Build and run

If u get an error like this restart your computer.

If your program compiles your webcam should start. If u don’t have a webcam try to open an image with openCV.

--

--