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

  1. install opencv
    • extract opencv[…].zip
    • copy to D:\OpenCV\
  2. install vscode
    • VSCodeUserSetup-[...].exe
  3. install cpp-tools in vscode
    • ctrl + shift + x
    • search for: “c++”
    • install “c/c++” from Microsoft
  4. install mingw
    • mingw-w64-install.exe – install to D:\mingw\ (IMPORTANT: don’t use spaces in name)
    • options: (version: 8.1.0, arch: x86_64, threads: posix, exception: seh, build rev: 0)
  5. 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
  6. 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

[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