OpenCV3-Mac环境配置
2017-12-19 本文已影响428人
Yochi
-
安装Homebrew
安装文档地址
快速安装直接执行以下命令安装:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
-
安装CMake(安装好Homebrew之后,可以执行以下命令安)
CMake是什么:是一个跨平台编译工具- 下载安装
- 执行命令安装:
brew install cmake
-
安装OpenCV
- 1.进入下载OpenCV解压之后的文件夹
- 2.执行命令(以此执行以下命令安装)
- 命令一:mkdir build
- 命令二:cd build
- 命令三:cmake -G "Unix Makefiles" ..(别忘了两点)
- 命令四:make
- 命令五:sudo make install
- 执行完命令:OpenCV安装完成
-
查看是否安装成功
/usr/local/lib目录下是否有了OpenCV动态库 -
新建项目测试测试
- 新建项目(Mac OS->Command Line Tools注意:选择c++语言)
- 在项目build setting->search path进行配置
- Always search User paths : true
- Framework search path: /usr/local/lib
- Header Search Paths :/usr/local/include
- Library Search Paths : /usr/local/lib
- 在项目build setting->search path进行配置
在项目中新建一个文件夹,选"Add files to ...", 按 command+shift+g 输入路径 /usr/local/lib,把所有的dylib库导入项目 - 测试运行(直接Copy代码运行修改图片路径)
#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
int main( int argc, char** argv ){
string imageName("/Users/yangshaohong/Desktop/2.jpg"); // by default
if( argc > 1) {
imageName = argv[1];
}
Mat image;
image = imread(imageName.c_str(), IMREAD_COLOR); // Read the file
if( image.empty() ){
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}