This page has information on how to install and use GoCV on Microsoft Windows 10, 64-bit.
Install the GoCV package:
go get -u -d gocv.io/x/gocv
In order to use GoCV on Windows you must build and install OpenCV 3.4.3. First download and install MinGW-W64 and CMake, as follows.
Download and run the MinGW-W64 compiler installer from https://sourceforge.net/projects/mingw-w64/?source=typ_redirect.
The latest version of the MinGW-W64 toolchain is
7.3.0, but any version from
7.X on should work.
Choose the options for “posix” threads, and for “seh” exceptions handling, then install to the default location
C:\Program Files\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev2\mingw64\bin path to your System Path.
Download and install CMake https://cmake.org/download/ to the default location. CMake installer will add CMake to your system path.
The following commands should do everything to download and install OpenCV 3.4.3 on Windows:
chdir %GOPATH%\src\gocv.io\x\gocv win_build_opencv.cmd
It will probably take at least 1 hour to download and build.
C:\opencv\build\install\x64\mingw\bin to your System Path.
Change the current directory to the location of the GoCV repo:
Now you should be able to build or run any of the command examples:
go run cmd\version\main.go
The version program should output the following:
gocv version: 0.17.0 opencv lib version: 3.4.3
That’s it, now you are ready to use GoCV.
If you are running a version of Go older than v1.10 and not modifying GoCV source, precompile the GoCV package to significantly decrease your build times:
go install gocv.io/x/gocv
By default, OpenCV is expected to be in
C:\opencv\build\install\include. This behavior can be disabled by supplying
-tags customenv when building/running your application. When building with this tag you will need to supply the CGO environment variables yourself.
Due to the way OpenCV produces DLLs, including the version in the name, using this method is required if you’re using a different version of OpenCV.
set CGO_CXXFLAGS="--std=c++11" set CGO_CPPFLAGS=-IC:\opencv\build\install\include set CGO_LDFLAGS=-LC:\opencv\build\install\x64\mingw\lib -lopencv_core343 -lopencv_face343 -lopencv_videoio343 -lopencv_imgproc343 -lopencv_highgui343 -lopencv_imgcodecs343 -lopencv_objdetect343 -lopencv_features2d343 -lopencv_video343 -lopencv_dnn343 -lopencv_xfeatures2d343 -lopencv_plot343 -lopencv_tracking343 -lopencv_img_hash343
Please note that you will need to run these 3 lines of code one time in your current session in order to build or run the code, in order to setup the needed ENV variables. Once you have done so, you can execute code that uses GoCV with your custom environment like this:
go run -tags customenv cmd\version\main.go