码迷,mamicode.com
首页 > 系统相关 > 详细

在mac上使用sublime text3搭建opencv3开发环境

时间:2019-06-11 00:50:49      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:new   info   bin   return   lag   col   alt   终端   width   

安装sublime text3

 

打开mac终端,安装brew

 

安装opencv3,终端输入下面的coomand:

brew install opencv@3

注意:@3表示安装的版本,如果不加@3,那么会默认安装最新的版本;建议安装版本3。

 

在sublime text3中添加build system

Tools->Build System->New Build System...

复制下面的code到新建的.sublime-build文件

{
 "cmd": ["g++", "-Wall", "-Wextra", "${file}", "-o", "${file_path}/${file_base_name}",
 "-I/usr/local/Cellar/opencv@3/3.4.5_2/include/opencv",
 "-I/usr/local/Cellar/opencv@3/3.4.5_2/include",
 "/usr/local/Cellar/opencv@3/3.4.5_2/lib/libopencv_calib3d.dylib",
 "/usr/local/Cellar/opencv@3/3.4.5_2/lib/libopencv_core.dylib",
 "/usr/local/Cellar/opencv@3/3.4.5_2/lib/libopencv_features2d.dylib",
 "/usr/local/Cellar/opencv@3/3.4.5_2/lib/libopencv_flann.dylib",
 "/usr/local/Cellar/opencv@3/3.4.5_2/lib/libopencv_highgui.dylib",
 "/usr/local/Cellar/opencv@3/3.4.5_2/lib/libopencv_imgcodecs.dylib",
 "/usr/local/Cellar/opencv@3/3.4.5_2/lib/libopencv_imgproc.dylib",
 "/usr/local/Cellar/opencv@3/3.4.5_2/lib/libopencv_ml.dylib",
 "/usr/local/Cellar/opencv@3/3.4.5_2/lib/libopencv_objdetect.dylib",
 "/usr/local/Cellar/opencv@3/3.4.5_2/lib/libopencv_photo.dylib",
 "/usr/local/Cellar/opencv@3/3.4.5_2/lib/libopencv_stitching.dylib",
 "/usr/local/Cellar/opencv@3/3.4.5_2/lib/libopencv_video.dylib",
 "/usr/local/Cellar/opencv@3/3.4.5_2/lib/libopencv_videostab.dylib"],
 "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
 "working_dir": "${file_path}",
 "selector": "source.c, source.c++",
 
"variants":
 [{
"name": "Run",
"cmd": ["bash", "-c", "g++ ‘${file}‘ -o ‘${file_path}/${file_base_name}‘ `/usr/bin/pkg-config --cflags --libs   /usr/Local/Cellar/opencv@3/3.4.5_2/lib/pkgconfig/opencv.pc` && ‘${file_path}/${file_base_name}‘ "]
}]
}

保存,注意扩展名是.sublime-build,我这里取名是opencv.sublime-build,勾选新建的build system,作为build opencv code的指令。

技术图片

 

hello opencv测试

#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main()
{
    //从文件中读入图像
    Mat img = imread("1.jpeg");
    //如果读入图像失败
    if(img.empty())
    {
        fprintf(stderr, "Can not load image!\n");
        return -1;
    }
    //显示图像
    imshow("original picture", img);
    //此函数等待按键,按键盘任意键就返回
    waitKey();
    return 0;
}

 

在sublime text中使用快捷键command+B,build测试用例,输出结果如下:

技术图片

 

在mac上使用sublime text3搭建opencv3开发环境

标签:new   info   bin   return   lag   col   alt   终端   width   

原文地址:https://www.cnblogs.com/qianxiaolingyun/p/11001254.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!