Skip to content

Walkerxrc/codeblocks-opencv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

codeblocks-opencv

Build openCV based on Codeblocks 搬运自: https://medium.com/@sourabhjigjinni/install-opencv-4-0-0-for-c-windows-7-10-code-blocks-tdm-gcc-64-dff65addf162

[toc]

Abstract

This is a step-by-step installation of OpenCV 4.1.0 on Windows. I was inspired to make this installation guide to help people avoid the stress I went through to install this on windows. I have obviously installed this myself with the help of other people’s slightly older blogs. Thanks to Zahid Hasan for the guide on version 3.2.0 which most of this is based on.

1. Install Code::Blocks

image-20200304105221358

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

Click on the sourceforge.net link for the codeblocks-17.12-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.

image-20200304105422952

Install it in C:\ drive. it will look like C:\TDM-GCC-64. The bin folder should be registered automatically in system path during the installation process

image-20200304110033173 image-20200304110105856

3. Download the source of OpenCV 4.1.0

Download OpenCV 4.1.0 and click sources to get the zip/excute file.

Create folders:

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

image-20200304110732682

4. Install CMake

Download CMake and install.

image-20200304111255767

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)

image-20200304113728230

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

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

MAKE SURE

  • WITH_MFMS=OFF
  • WITH_IPP=OFF,
  • WITH_TBB=OFF
  • ENABLE_PRECOMPILED_HEADERS=OFF

And

  • WITH_OPENCL=ON
  • WITH_OPENCL_D3D11_NV=OFF
  • WITH_DIRECTX=ON

Lastly

  • BUILD_PROTOBUF = OFF
  • PROTOBUF_UPDATE_FILES = OFF
  • WITH_PROTOBUF = OFF

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

image-20200304113851306

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

image-20200304113938739

  1. 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. It took me 1.5 hours.

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

Tip: you can check path variables with echo %path:;=&echo.% in command prompt.

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

image-20200304114030196

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

image-20200304114101936

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

    image-20200304114140489

    image-20200304114205831

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

    image-20200304114239974

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

    image-20200304114319983

    1. Edit your main.cpp and add this:
    #include <iostream>
    #include <opencv2\highgui\highgui.hpp>
    #include <opencv2\opencv.hpp>
    
    using namespace std;
    using namespace cv;
    
    int main() {
    
    	VideoCapture cap(0);
    	if (!cap.isOpened()) {
    		cout << "Error initializing video camera!" << endl;
    		return -1;
    	}
    
    	char* windowName = "Webcam Feed";
    	namedWindow(windowName, WINDOW_AUTOSIZE);
    
    	while (1) {
    
    		Mat frame;
    		bool bSuccess = cap.read(frame);
    
    		if (!bSuccess) {
    			cout << "Error reading frame from camera feed" << endl;
    			break;
    		}
    
    		imshow(windowName, frame);
    		switch (waitKey(10)) {
    		case 27:
    			return 0;
    		}
    	}
    	return 0;
    }
    1. Build and run

    If u get an error like this restart your computer.

image-20200304114434680

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

About

Build openCV based on Codeblocks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published