先说:最近准备做基于openCV的移动端人脸对比和识别,所以记录一下在过程中遇到的问题和解决办法,还有一些感想,文章随时更新,有问题希望大家可以多沟通交流
一写markdown上的不兼容,看着不习惯可以去 原文链接
1 选择&安装配置
1.1 首先Go的OpenVC两个版本的库
1.2 安装OpenCV(OpenCV3+)
依赖很多,安装时间很长,请准备好瓜子和板凳,直待GoCV安装完成
brew install hybridgroup/tools/opencv
运行以下命令获取GoCV库
go get -u -d gocv.io/x/gocv
切换到gocv文件夹下
cd $GOPATH/src/gocv.io/x/gocv
运行go run XX.go 选其中一个demo文件运行即可
1.2.1 But!! 你可能会遇到一个报错
go run: cannot run *_test.go files (video_test.go)
或
pkg-config –cflags – opencv4
Package opencv4 was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv4.pc’
to the PKG_CONFIG_PATH environment variable
No package ‘opencv4’ found
pkg-config: exit status 1
你可以通过brew install pkgconfig解决
1.2.2 你还可能遇到Library not loaded
dyld: Library not loaded:glog啊或者gflags啊之类的
总之缺什么库啊引用缺失啊 ,你就导入什么就好了brew install glog
1.2.3 运行成功
运行
cd $GOPATH/src/gocv.io/x/gocv
go run ./cmd/version/main.go
成功->输出
gocv version: 0.18.0
opencv lib version: 4.0.0
2 运行Demo
2.1 面部检测Demo 直接用goCV的Demo就好了,搞起来
1 | import ( |
2.1.1 But!!!! 你可能会遇到报错
Error reading cascade file: data/haarcascade_frontalface_default.xml 路径不对,问题代码行数if !classifier.Load("data/haarcascade_frontalface_default.xml") { 替换load路径为你的opencv的路径$GOPATH/src/gocv.io/x/gocv/data/haarcascade_frontalface_default.xml
3.打包go文件为静态.a包
安装gomobilego get golang.org/x/mobile/cmd/gomobile 需要翻墙
然后安装gomobile init 绑定go get -d golang.org/x/mobile/example/bind/...
最后生成gomobile的生成.a的测试包helpDemo,以iOS为例子
cd $GOPATH/src/golang.org/x/mobile/example/bind
gomobile bind -target=ios golang.org/x/mobile/example/bind/hello 因为gomobile在生成.framework时,调用了CommandLineTools,所以你需要在MacOS上安装CommandLineTools,或者Xcode
But!!!!!即使你安装了CommandLineTools或者Xcode也还是会有可能会报出gomobile: -target=ios requires XCode的错误,我理解
是因为gomobile实现的xcrun找不到你的CommandLineTools,路径错误,解决:
sudo xcode-select -r
xcode-select –help
Options:
-h, –help print this help message and exit
-p, –print-path print the path of the active developer directory
-s
, –switch set the path for the active developer directory –install open a dialog for installation of the command line developer tools
-v, –version print the xcode-select version
-r, –reset reset to the default command line tools path