1.安裝
- 安裝Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 安裝wget
brew install wget
- 安裝cmake
brew install cmake
2.下載
搜索一下
brew search opencv
會發(fā)現(xiàn)有兩個(gè)結(jié)果
homebrew/science/opencv
(這個(gè)是OpenCV2.x)
homebrew/science/opencv3
(這個(gè)是OpenCV3)
輸入如下命令就可以下載了
brew install homebrew/science/opencv3
完成之后在目錄 /usr/local/Cellar
下可以找到
3.新建項(xiàng)目及配置
- 打開Xcode并創(chuàng)建新的項(xiàng)目
- 項(xiàng)目類型可以選擇 Command Line
- 語言選擇C++
- 設(shè)置庫檢索路徑
- 添加C++標(biāo)準(zhǔn)庫和OpenCV庫
- 運(yùn)行測試代碼
#include <opencv2/opencv.hpp>
int main(int argc, const char * argv[]) {
printf("\t當(dāng)前使用的 OpenCV 版本為 OpenCV " CV_VERSION "\n");
cv::VideoCapture capture(0);
while (1) {
cv::Mat frame;
capture>>frame;
cv::Mat edge,grayImg;
cv::cvtColor(frame, grayImg, cv::COLOR_BGR2GRAY);
cv::blur(grayImg, edge, cv::Size(3,3));
cv::Canny(edge, edge, 3, 9, 3);
cv::imshow("邊緣", edge);
cv::waitKey(30);
}
return 0;
}
正確運(yùn)行,配置完成