gocv
gocv copied to clipboard
Not able to install on MacOS Monterey
I am trying to install this on my MacBook but I am unable to. I tried following the steps of installing OpenCV through homebrew and installing pkg-config. I tried setting up custom tags but that also ended up not working for me. I tried searching for a solution but couldn't find it. Can someone please suggest to me the steps where I did this wrong?
Description
When I try to run the version main.go file it gives me this error
$go run -tags customenv main.go
# gocv.io/x/gocv
In file included from calib3d.cpp:1:
../../../../go/pkg/mod/gocv.io/x/[email protected]/calib3d.h:5:10: fatal error: 'opencv2/opencv.hpp' file not found
Steps to Reproduce
- Run brew uninstall OpenCV
- Run brew install OpenCV
- Run brew install pkg-config
- Created custom environment
- Run version/main.go file
Your Environment
- Operating System and version: macOS Monterey 12.2.1
- OpenCV version used: 4.5.5
- How did you install OpenCV? Homebrew
- GoCV version used:
- Go version: go1.17.6 darwin/amd64
- Did you run the
env.sh
orenv.cmd
script before trying togo run
orgo build
? I rango run
For my M1, I needed to add opencv4 and update the path for the CGO_CPPFLAGS env var. So for my M1, it became CGO_CPPFLAGS="-I/opt/homebrew/Cellar/opencv/4.5.5_2/include/opencv4"
For my M1, I needed to add opencv4 and update the path for the CGO_CPPFLAGS env var. So for my M1, it became CGO_CPPFLAGS="-I/opt/homebrew/Cellar/opencv/4.5.5_2/include/opencv4"
Thank you @rdejana, you saved my day.
For someone who googled and get this answer and use VSCode for running tests, you can find the env setting just like the image shows below.
Then change the opencv version to you installed, all done.
{
"go.testEnvVars": {
"CGO_CPPFLAGS": "-I/opt/homebrew/Cellar/opencv/4.6.0_1/include/opencv4"
}
}