Atom利用gcc-make-run编译opencv工程

0、起什么标题呢?(就叫写在前面的话吧)

Atom插件的安装参照这篇文章,opencv的配置参考这篇文章(不使用CodeBlocks的话,解压后只需要添加相应的环境变量即可)。
之前就是想设置Atom能够编译opencv工程,Atom的gcc-make-run插件是利用MinGW的gcc/g++编译C/C++代码,要添加其对opencv的支持,实际上只需要在编译时进行相关库文件的链接即可。对codeBlocks配置opencv后,我写了一个简单的图片显示代码进行测试,编译时发现Build log下有编译链接库的命令,然后就是根据这个改了一下gcc-make-run的设置,能够正确编译opencv代码并运行。

Atom利用gcc-make-run编译opencv工程_第1张图片

1、设置

打开Atom,按下快捷键Ctrl+Shift+P,输入install package,点击第一个进入设置管理。

Atom利用gcc-make-run编译opencv工程_第2张图片
找到安装的gcc-make-run插件,点击设置对插件编译选项进行设置

Atom利用gcc-make-run编译opencv工程_第3张图片

参数 作用
-Wall 表示允许gcc提供可用的警告信息
-g 表示在编译时产生调试信息
-Idir 此处为包含opencv头文件所在目录
-Ldir 指定opencv链接库的路径

在Complier Flags里面添加的编译选项是opencv头文件的链接路径,Link Libraries添加的为链接库的路径。实际设置时,要根据__自己opencv所在路径__进行相应__修改__,例如在我的电脑上,opencv路径为E:\OpenCv_Code\CodeBlocks1601\opencv3,那么我的配置如下:

1.1.Compiler Flags添加如下:

-Wall -fexceptions -g -IE:\OpenCv_Code\CodeBlocks1601\opencv3\build\include -IE:\OpenCv_Code\CodeBlocks1601\opencv3\build\include\opencv -IE:\OpenCv_Code\CodeBlocks1601\opencv3\build\include\opencv2

1.2.Link Libraries添加如下:

-LE:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_calib3d310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_core310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_features2d310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_flann310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_highgui310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_imgcodecs310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_imgproc310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_ml310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_objdetect310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_photo310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_shape310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_stitching310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_superres310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_ts310.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_video310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_videoio310.dll.a E:\OpenCv_Code\CodeBlocks1601\opencv3\build\x86\mingw\lib\libopencv_videostab310.dll.a

Atom利用gcc-make-run编译opencv工程_第4张图片

2、代码测试

随意新建一个目录,在目录里新建一个cpp文档并拷贝一个test.jpg图片到该目录,使用Atom打开,输入如下代码,按F6编译执行:

#include 
#include 
#include 
#include 

using namespace std;
using namespace cv;

int main()
{
     
    cout << "Hello world!" << endl;
    Mat img = imread("test.jpg");
    imshow("test", img);
    cvtColor(img, img, CV_RGB2GRAY);
    imshow("gray", img);
    waitKey(0);
    return 0;
}

你可能感兴趣的:(opencv,atom编辑器,环境配置,opencv,atom,mingw,c++)