gocv icon indicating copy to clipboard operation
gocv copied to clipboard

Not able to install on MacOS Monterey

Open ksajan opened this issue 2 years ago • 2 comments

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

  1. Run brew uninstall OpenCV
  2. Run brew install OpenCV
  3. Run brew install pkg-config
  4. Created custom environment
  5. 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 or env.cmd script before trying to go run or go build? I ran go run

ksajan avatar Feb 28 '22 21:02 ksajan

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"

rdejana avatar May 04 '22 13:05 rdejana

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. Screen Shot 2022-11-20 at 1 51 11 AM

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"
    }
}

Calvin-Huang avatar Nov 19 '22 17:11 Calvin-Huang