I’m going to show you how to install GOCV on your Mac, so that you can easily write programs like face detection and edging to go with my other tutorials on image processing.
To start, we can install gocv. It’s best to do it the old-fashioned way (without go modules). To do so, you need to set the GO111MODULES environment variable to off.
GO111MODULE=off go get -u -d gocv.io/x/gocv
GoCV has a lot of examples to show that it works well. For confirmation, we will compile one of the provided samples. To do so, we’ll use the commands below in the command line interface.
cd $GOPATH/src/gocv.io/x/gocv/cmd/hello go run main.go
The command failed because OpenCV is not installed
# 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
The easiest way to install OpenCV on a Mac is by using homebrew package manager. You can follow their install instructions at the following URL:
Installing OpenCV through homebrew package manager is really easy with the command below
brew install opencv
After the installation has finished we need to find the file opencv4.pc to add it to pkg-config path
find /opt/homebrew -name opencv4.pc
Run this command in your terminal to ensure that pkg-config can find OpenCV before compiling the example
PKG_CONFIG_PATH=/opt/homebrew/lib/pkgconfig/ go run main.go
Voila, we have installed GoCV and it now has access to the camera on your computer!