OpenCV is a rich computer vision open-source library initially maintained by Intel Inc. and now governed by itseez. Development of OpenCV is generally based on C and C++ before it is implicitly said that C API is almost deprecated. By the way python and Java wrappers are also available to make use of rich functionalities and efficient coding style in respective languages. Further, OpenCV supports cross platforms ranging from PCs to Mobile devices while supporting various GPU acceleration optimizations such as CUDA and OpenCL as well as TBB, etc.
The main objective of this blog is to present the way in which OpenCV 3.0.0 is built on Windows environment. Though there are so many articles, blogs and forums covering this basic topic, I saw a lack of integration of building OpenCV with MinGW for platforms (Eclipse, Netbeans, etc.) other than Visual Studio. If you also have faced the same issue then the below steps are for you.
- Download or clone OpenCV and unzip to a desired destination (say ‘opencv-source’).
- Download OpenCV Extra Modules (as say ‘opencv_contrib’)
- Download cmake binaries and unzip into a desired location (say ‘cmake-binary’).
- Download and Install MinGW as a fresher (say at ‘mingw-dir’)
- Set PATH of MinGW (otherwise you would have an error saying ‘libgmp-10.dll is missing’)
- Run ‘cmake-gui’ in <cmake-binary>/bin
- Enter <opencv-source> path in the ‘Where is the source code:’ text box.
- Enter the newly created build directory’s path (say ‘opencv-build’) in ‘Where to build the binaries:’ text box.
- Check both ‘Grouped’ and ‘Advanced’ radio buttons in order to navigate options available in cmake-gui easily.
- For the moment disable IPP by unchecking the WITH_IPP under the WITH category (otherwise ‘cannot find -lRunTmChk’ error is expected when building OpenCV)
- Click ‘Configure’. In the popping window, select MinGW option under ‘Specify the generator for this project’ and click ‘Finish’.
- Wait until the configuration is done and then click ‘Generate’.Now you have properly configured OpenCV and check whether you have cvconfig.h inside the ‘opencv-build’ folder.
- Before building the project it is advised to uncomment ‘add_extra_compiler_option(-Werror=non-virtual-dtor)’ option in ‘<opencv-source>\cmake\OpenCVCompilerOptions.cmake’ file in order to avoid errors related to ‘[-Werror=non-virtual-dtor]’ while mingw building process.
- Go to <mingw-dir>/msys/1.0 and run ‘msys’ bash file.
- Navigate to <opencv-build> path and run ‘mingw32-make’ command.
- Run ‘mingw32-make install’ after build is successful.After successful building and installing of OpenCV go to <opencv-build> folder and copy generated files to respective destinations as follows.
- Copy two folders in ‘<opencv-build>\install\include’ to ‘<mingw-dir>\include’
- Copy files in ‘<opencv-build>\install\x86\mingw\bin’ to ‘C:\Windows\SysWOW64’ if your system is 64-bit, otherwise ‘C:\Windows\System32’
- Copy files in ‘<opencv-build>\install\x86\mingw\lib’ to ‘<mingw-dir>\lib’
OpenCV Extra Modules
Additionally if you need extra opencv modules such as Text, Face, etc. modules categorized under separate repository follow the below steps.
- Unzip ‘opencv_contrib’ modules zip file at a desired path (say ‘opencv_contrib_path’).
- Again open ‘cmake-gui’ and select ‘OPENCV_EXTRA_MODULES_PATH’ under ‘OPENCV’ category and insert ‘<opencv_contrib_path>\modules’
- For the moment deselect ‘opencv_bioinspired’ module under the ‘BUILD’ category as it crashes unexpectedly.
- It seems some API mismatch in the system generates ‘<opencv_contrib_path>\opencv_contrib-master\modules\ximgproc\src\spar
se_match_interpolators.cpp:171:52: error: ‘const class cv::_InputArray’ has no m
ember named ‘isVector” error. Therefore try to ‘Configure’ and ‘Generate’ after commenting out the lines as follows. CV_Assert( !from_points.empty() && //from_points.isVector() &&
!to_points .empty() && //to_points .isVector() &&
These are the ways and resolutions I have made on the way to the successful OpenCV run on my Windows environment. If this helps you, I am quite happy with that or if you think I have done something silly, well, please point it out.