首页 > 代码库 > Opencv在mac系统的安装与试用

Opencv在mac系统的安装与试用

1.在mac终端内,使用brew安装opencv3,这时我的opencv被安装到/usr/local/Cellar/opencv3/3.2.0内。

2.新建xcode 项目,选择command line tool,在项目目录内新建一个group,把/usr/local/Cellar/opencv3/3.2.0/lib内的含有libopencv的dylib都添加进去。

3.在build settings 内更改Header Search Paths为/usr/local/Cellar/opencv3/3.2.0/include, Library Search Paths 更为/usr/local/Cellar/opencv3/3.2.0/lib。注意此处不能copy网上仅仅是/usr/local/include 或者/usr/local/lib,要根据你opencv安装地址而定

4.在main函数中输入,即可显示出图片,注意图片的路径要正确,自己定。

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12f1b } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; min-height: 13.0px } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #78492a } p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #ba2da2 } p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 } p.p6 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400 } span.s1 { color: #78492a } span.s2 { } span.s3 { color: #d12f1b } span.s4 { color: #000000 } span.s5 { color: #703daa } span.s6 { color: #ba2da2 } span.s7 { color: #3e1e81 } span.s8 { color: #272ad8 } span.s9 { color: #008400 }</style>

#include "opencv2/core.hpp"

#include "opencv2/imgcodecs.hpp"

#include "opencv2/highgui.hpp"

 

#include <iostream>

#include <string>

 

using namespace cv;

 

using namespace std;

 

int main(int argc, char** argv)

{

    

    String imageName("/Users/mac-jcc/Desktop/opencv-00/jcc.png");

    

    Mat image;

    

    image = imread(imageName, IMREAD_COLOR);

    

    if(image.empty())

    {

        cout<<"could not open or find the image"<<std::endl;

        return -1;

    }

      

    namedWindow( "Display window", WINDOW_AUTOSIZE ); 

    imshow( "Display window",image );                

    waitKey(0);

    

    return 0;

}

Opencv在mac系统的安装与试用