Installing OpenCV 4 on Linux is difficult, but can be done. On Windows it took me hours to get it working.
Download
- [VS Code][1]
- [mingw-w64][2]
- [OpenCV 4.1.1 (mingw edition)][3]
- [set_env.bat][4]
Installation
- install opencv
- extract opencv[…].zip
- copy to
D:\OpenCV\
- install vscode
VSCodeUserSetup-[...].exe
- install cpp-tools in vscode
- ctrl + shift + x
- search for: “c++”
- install “c/c++” from Microsoft
- install mingw
mingw-w64-install.exe
– install toD:\mingw\
(IMPORTANT: don’t use spaces in name)- options: (version: 8.1.0, arch: x86_64, threads: posix, exception: seh, build rev: 0)
- set envoirment variables
- change any paths in
set_env.bat
if you haven’t used mine - right click
set_env.bat
- select run as admin
- change any paths in
- Finished 😉
Important notes
- compiling: add “411” or corresponding opencv version to linker
g++ ... -lopencv_core411
- don’t use spaces in folder names
Compile OpenCV code
g++ -g test.cpp -o test.exe -I"%OPENCV_DIR%include" -L"%OPENCV_DIR%x64\mingw\bin" -lopencv_stitching411 -lopencv_objdetect411 -lopencv_calib3d411 -lopencv_features2d411 -lopencv_highgui411 -lopencv_videoio411 -lopencv_imgcodecs411 -lopencv_video411 -lopencv_photo411 -lopencv_ml411 -lopencv_imgproc411 -lopencv_flann411 -lopencv_core411
Credits
Big thanks to [@huihut][5] for providing pre-compiled OpenCV + mingw Windows builds. Building this myself would have been an additional nightmare.
Sources
- https://sourceforge.net/projects/opencvlibrary/files/4.1.1/
- https://stackoverflow.com/questions/51622111/opencv-c-mingw-vscode-fatal-error-to-compile/51801863#51801863
- https://github.com/huihut/OpenCV-MinGW-Build
[1]: https://code.visualstudio.com/Download [2]: http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe/download [3]: https://github.com/huihut/OpenCV-MinGW-Build/archive/OpenCV-4.1.1-x64.zip [4]: https://gist.githubusercontent.com/Garogat/d621a087b545e73b6b7da7a998a30c17/raw/e1a8f1eac7e508ea820150e4333013ecffa6a00a/set_env.bat [5]: https://github.com/huihut