OpenCV|MacOSMacOS 安装 Python-OpenCV

Posted 宇宙爆肝锦标赛冠军

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenCV|MacOSMacOS 安装 Python-OpenCV相关的知识,希望对你有一定的参考价值。

系统环境

  • MacOS 11.4
  • MacBook Pro M1
  • homebrew
  • python3.9

安装命令

brew install opencv@3 

注意:截至2021年8月,使用国内源安装会出现404错误。
解决方法:不使用国内源

export HOMEBREW_BOTTLE_DOMAIN='' 

具体原因参考:修复homebrew安装软件404问题

路径配置

安装后会输出如下内容:

==> opencv@3
opencv@3 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.

If you need to have opencv@3 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/opencv@3/bin:$PATH"' >> ~/.zshrc

For compilers to find opencv@3 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/opencv@3/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/opencv@3/include"

For pkg-config to find opencv@3 you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/opencv@3/lib/pkgconfig"

当我按照要求配置路径后,python中还是找不到cv2。

解决方法


检验

python3

>>> import cv2
>>>

以上是关于OpenCV|MacOSMacOS 安装 Python-OpenCV的主要内容,如果未能解决你的问题,请参考以下文章

OpenCV调用手机摄像头与人脸检测

在 ubuntu 上使用 anaconda 安装 openCV

Ubuntu 17.04版本下,opencv进行源码编译安装

英伟达开发板安装python-opencv下的问题

Window10+Python3.5安装opencv

入门opencv