安装 OpenCV
方法一 :Homebrew
1.安装homebrew
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
2.依赖环境安装
sudo xcode-select --install
3.pkg-config安装 用于精简编译(不确定在 xcode 环境下是否需要这个,vscode是需要的)
brew install pkg-config
4.安装opencv
brew install opencv
5.homebrew默认安装opencv_contrib,不需要考虑重新编译opencv+opencv_contrib,M1原生的homebrew的安装目录只能为/opt/homebrew
。homebrew安装的包都在/opt/homebrew/Cellar
下,opencv也不例外,具体为/opt/homebrew/Cellar/opencv/4.6.1,
安装完之后设置环境变量
export PATH="/opt/homebrew/Cellar/opencv/4.6.0_1/bin:$PATH"
export PATH="-L/opt/homebrew/Cellar/opencv/4.6.0_1/lib"
export PATH="-I/opt/homebrew/Cellar/opencv/4.6.0_1/include"
export PATH="/opt/homebrew/Cellar/opencv/4.6.0_1/lib/pkgconfig"