Skip to content

Latest commit

 

History

History
66 lines (58 loc) · 2.76 KB

v0.29.0.md

File metadata and controls

66 lines (58 loc) · 2.76 KB

Install gocv "gocv.io/x/gocv" on Windows

1. Download and extract both OpenCV sources to D:\opencv.

2. Have MSYS2 and its make, cmake, gcc and MinGW-w64 toolchain properly installed.

  • Assuming you've already installed go and git.
  • Install MSYS2.
  • Run pacman -S make cmake gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-gcc mingw-w64-x86_64-toolchain from your MSYS2 terminal.
  • Uncomment MSYS2_PATH_TYPE=inherit in msys2.ini, mingw64.ini and mingw32.ini.
  • Add D:\msys64\mingw64\bin and D:\msys64\usr\bin to your system's Path environment variable.

3. Build OpenCV.

Run the following in cmd.exe.

mkdir D:\opencv\build
cd /D D:\opencv\build
set enable_shared=ON
cmake D:\opencv\opencv-4.5.4 -G "MinGW Makefiles" -BD:\opencv\build -DENABLE_CXX11=ON -DOPENCV_EXTRA_MODULES_PATH=D:\opencv\opencv_contrib-4.5.4\modules -DBUILD_SHARED_LIBS=%enable_shared% -DWITH_IPP=OFF -DWITH_MSMF=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_opencv_java=OFF -DBUILD_opencv_python=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DBUILD_DOCS=OFF -DENABLE_PRECOMPILED_HEADERS=OFF -DBUILD_opencv_saliency=OFF -DBUILD_opencv_wechat_qrcode=OFF -DCPU_DISPATCH= -DOPENCV_GENERATE_PKGCONFIG=ON -DWITH_OPENCL_D3D11_NV=OFF -DOPENCV_ALLOCATOR_STATS_COUNTER_TYPE=int64_t -Wno-dev
mingw32-make -j%NUMBER_OF_PROCESSORS%
mingw32-make install

This should install opencv under directory D:\opencv\.

Clean-up

rmdir D:\opencv\opencv-4.5.4 /s /q
rmdir D:\opencv\opencv_contrib-4.5.4 /s /q

4. Set environment variables in order to provide gcc with global include/library paths to your opencv.

  • Add D:\opencv\build\install\x64\mingw\bin to your LIBRARY_PATH and Path environment variable.
  • Add D:\opencv\build\install\include to your CPLUS_INCLUDE_PATH environment variable.

If you want to find out your gcc's default include path:

$ echo | gcc -v -x c++ -E -
#include <...> search starts here:
 D:\opencv\build\install\include

5. Go get it.

Either way you prefer.

go get -v gocv.io/x/gocv@v0.29.0
$ git clone https://github.com/hybridgroup/gocv $GOPATH/src/gocv.io/x/gocv
$ cd $GOPATH/src/gocv.io/x/gocv
$ git checkout v0.29.0
$ go install -v

6. Test it.

chdir /D %GOPATH%\src\gocv.io\x\gocv
go install -v ./...