macOS Qt Creator 配置 OpenCV

Qt Mar 5, 2018

先用 Homebrew 安装 opencv:

brew tap homebrew/science
brew install opencv3

或者去官网下载源码手动编译也行。

Homebrew 安装的目录在 /usr/local/Cellar/opencv/<version>/,但是一般都会做一个符号链接到 /usr/local/lib/usr/local/include,所以不管是用哪种方法安装的 opencv,建议最好都使用这个路径。

然后在 Qt Creator 的项目设置里,添加 /usr/local/bin 到环境变量 PATH 里去:

-----2018-03-05-10.57.18

如果使用的 OpenCV3 的版本,并在 Qmake 配置希望使用 PKG_CONFIG 的话,还需要另外添加一个环境变量 PKG_CONFIG_PATH,值为 OpenCV3安装目录中包含有 opencv.pc 文件的目录。

可通过这条命令查找 find /usr/local -name "opencv.pc"

QMake:

...
linux {
    INCLUDEPATH += /usr/include/opencv2
    LIBS += `pkg-config --libs opencv`
}

macx {
    INCLUDEPATH += `pkg-config --cflags opencv`
    LIBS += `pkg-config --libs opencv`
}
...

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.