
OpenCV 4 + Windows + Mingw + VSCode
Installing OpenCV 4 on Linux is difficult, but can be done. On Windows it took me hours to get it working.
Download
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 for providing pre-compiled OpenCV + mingw Windows builds. Building this myself would have been an additional nightmare.