Install Gocv on MAC

1. Go to the correct path then run the following code

jimmy@jimmys-MacBook-Pro ~ % cd $GOPATH/src/gocv.io/x/gocvjimmy@jimmys-MacBook-Pro gocv % go run ./cmd/version/main.gogocv version: 0.24.0opencv lib version: 4.4.0

2. Fix the Package opencv4 was not found issue

Issue

jimmy@jimmys-MacBook-Pro x % go run ./gocv/cmd/version/main.go# pkg-config --cflags  -- opencv4Package 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 variableNo package 'opencv4' foundpkg-config: exit status 1

How to fix: find the opencv4.pc file

find / -name opencv4.pc/usr/local/Cellar/opencv/4.4.0_2/lib/pkgconfig/opencv4.pc
vi ~/.zshrc
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/Cellar/opencv/4.4.0_2/lib/pkgconfig"
source ~/.zshrc
cd $GOPATH/src/gocv.io/x/gocvjimmy@jimmys-MacBook-Pro gocv % go run ./cmd/version/main.gogocv version: 0.24.0opencv lib version: 4.4.0

See yourself from gocv

package mainimport (
"gocv.io/x/gocv"
)
func main() {
webcam, _ := gocv.VideoCaptureDevice(0)
window := gocv.NewWindow("Hello")
img := gocv.NewMat()
for {
webcam.Read(&img)
window.IMShow(img)
window.WaitKey(1)
}
}
/usr/local/go/pkg/tool/darwin_amd64/link: running clang++ failed: exit status 1ld: warning: directory not found for option '-L/usr/local/Cellar/opencv/4.4.0_2/lib'ld: library not found for -lopencv_freetypeclang: error: linker command failed with exit code 1 (use -v to see invocation)
export CGO_CPPFLAGS="-I/usr/local/Cellar/opencv/4.5.0_2/include"
export CGO_LDFLAGS="-L/usr/local/Cellar/opencv/4.5.0_2/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dpm -lopencv_face -lopencv_photo -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_dnn -lopencv_plot -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ml -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_flann -lopencv_xobjdetect -lopencv_imgcodecs -lopencv_objdetect -lopencv_xphoto -lopencv_imgproc -lopencv_core"

Reference

--

--

--

Data Scientist/MLE/SWE @takemobi

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What happens when you click on a URL

Kotlin Higher Order Functions

Web Scraping with Python using BeautifulSoup and Selenium

Take management of your change request workflow with the IBM Cloud reference implementation of…

Data flow diagram of CI pipeline run and change management automation

Understanding the Cloud Service Providers — Comparison between AWS, Microsoft Azure, and GCP

Introduction to Go — Part 1

Robot Framework: First Steps

Solidity upgradable contracts

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jimmy Shen

Jimmy Shen

Data Scientist/MLE/SWE @takemobi

More from Medium

User Creation And Authentication in Golang Part 1

How I containerize the Golang project for web development 😀

How to configure CircleCI and SonarQube for GoLang Application

Binary protection using go embed and plugins