Gocv安装(Windows)
什么是GoCV
gocv 是 OpenCV 4.x 计算机视觉库的包装器。 它为最新版本的 OpenCV 提供了 Go 语言接口
官网链接:https://gocv.io/
安装
1.安装Go(PASS)
2.安装GoCV
go get -u -d gocv.io/x/gocv # 执行完这条命令后,%GOPATH%\pkg\mod下会出现一个文件夹"[http://gocv.io](https://link.zhihu.com/?target=http%3A//gocv.io)"
|
3.安装MinGW-W64
注意安装版本:8.1.0
MinGW-W64版本
添加环境变量到系统环境变量
4.安装Cmake
安装链接
5 安装opencv(谨记,要手动添加环境变量,不要忘了!)
chdir %GOPATH%\src\gocv.io\x\gocv win_build_opencv.cmd
|
主要是win_build_opencv.cmd文件:
可以把文件opencv-4.6.0.zip和opencv_contrib-4.6.0.zip先放到C:\opencv
echo off
if not exist "C:\opencv" mkdir "C:\opencv" if not exist "C:\opencv\build" mkdir "C:\opencv\build"
echo Downloading OpenCV sources echo. echo For monitoring the download progress please check the C:\opencv directory. echo.
REM This is why there is no progress bar: REM https://github.com/PowerShell/PowerShell/issues/2138
REM echo Downloading: opencv-4.6.0.zip [91MB] REM powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri https://github.com/opencv/opencv/archive/4.6.0.zip -OutFile c:\opencv\opencv-4.6.0.zip" echo Extracting... powershell -command "$ProgressPreference = 'SilentlyContinue'; Expand-Archive -Path c:\opencv\opencv-4.6.0.zip -DestinationPath c:\opencv" REM del c:\opencv\opencv-4.6.0.zip /q echo.
REM echo Downloading: opencv_contrib-4.6.0.zip [58MB] REM powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri https://github.com/opencv/opencv_contrib/archive/4.6.0.zip -OutFile c:\opencv\opencv_contrib-4.6.0.zip" echo Extracting... powershell -command "$ProgressPreference = 'SilentlyContinue'; Expand-Archive -Path c:\opencv\opencv_contrib-4.6.0.zip -DestinationPath c:\opencv" REM del c:\opencv\opencv_contrib-4.6.0.zip /q echo.
echo Done with downloading and extracting sources. echo.
echo on
cd /D C:\opencv\build set PATH=%PATH%;C:\Program Files (x86)\CMake\bin;F:\env\mingw64 if [%1]==[static] ( echo Build static opencv set enable_shared=OFF ) else ( set enable_shared=ON ) cmake C:\opencv\opencv-4.6.0 -G "MinGW Makefiles" -BC:\opencv\build -DENABLE_CXX11=ON -DOPENCV_EXTRA_MODULES_PATH=C:\opencv\opencv_contrib-4.6.0\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=ON -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 rmdir c:\opencv\opencv-4.6.0 /s /q rmdir c:\opencv\opencv_contrib-4.6.0 /s /q chdir D:\GoLand2021.2\sdk\gopath\pkg\mod\gocv.io
|
验证
cd /d %GOPATH%\pkg\mod\gocv.io\x\gocv@v0.32.0 go run cmd\version\main.go
|
其他问题
出现exit status 0xc0000135
解决方案:重启