准备工作

  1. ​QT官网​​下载安装Qt5.7.
  2. ​Homebrew​​ 官网,安装homebrew.
  3. ​iTerm​​ 官网下载安装iTerm2.
  4. 启动iTerm

$ brew update
$ brew info opencv
$ brew tap homebrew/science
$ brew install opencv --with-qt5 --with-ffmpeg --with-opengl --with-opencl

Qt 测试项目helloCV

Mac10.11 + Qt5.7 + OpenCV2.4.13_opencv

Mac10.11 + Qt5.7 + OpenCV2.4.13_opencv_02

Mac10.11 + Qt5.7 + OpenCV2.4.13_mac_03

Mac10.11 + Qt5.7 + OpenCV2.4.13_brew_04

Mac10.11 + Qt5.7 + OpenCV2.4.13_#include_05

Mac10.11 + Qt5.7 + OpenCV2.4.13_brew_06

Mac10.11 + Qt5.7 + OpenCV2.4.13_brew_07

helloCV.pro 末尾添加以下代码:

INCLUDEPATH += /usr/local/include
INCLUDEPATH += /usr/local/include/opencv
INCLUDEPATH += /usr/local/include/opencv2

LIBS += -L/usr/local/lib \
-lopencv_core \
-lopencv_highgui \
-lopencv_imgproc \

main.cpp 代码如下:

//#include "mainwindow.h"
//#include <QApplication>
//int main(int argc, char *argv[])
//{
// QApplication a(argc, argv);
// MainWindow w;
// w.show();
// return a.exec();
//}

#include <iostream>
#include <string>
#include <vector>
using namespace std;

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;

int main(int argc, char *argv[])
{
Mat src = imread("/Users/tianzhaixing/Pictures/jurassic_world.jpg");
if(src.empty())
{
cerr << "Please check the path of input image!" << endl;
return -1;
}
const string winname = "src";
namedWindow(winname, WINDOW_AUTOSIZE);
imshow(winname, src);
waitKey(0);
destroyWindow(winname);
return 0;
}

问题

dyld: Symbol not found: __cg_jpeg_resync_to_restart
Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /usr/local/lib/libjpeg.8.dylib
in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
程序异常结束。

Mac10.11 + Qt5.7 + OpenCV2.4.13_qt5_08

参考

[1] ​​install-opencv-3-on-yosemite-osx-10-10-x​​​
[2] ​​​configuring-qt-for-opencv-on-osx​