如何使用OpenCV 2.4.3与Code :: Blocks编译程序? [英] How to compile a program using OpenCV 2.4.3 with Code::Blocks?

查看:290
本文介绍了如何使用OpenCV 2.4.3与Code :: Blocks编译程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了代码:: Blocks with MinGW 和OpenCV 2.4.3。我想编译这个简单的程序:

  #include< opencv2 / highgui / highgui.hpp> 
#include< iostream>

using namespace cv;
using namespace std;

int main()
{
Mat im = imread(c:/path/to/lena.jpg);
if(im.empty()){
cout<< 无法打开图像! << endl;
return 1;
}
imshow(Image,im);
waitKey(0);
}

如何正确设置CodeBlocks以编译上述代码?



我已在 c:\opencv 中安装OpenCV。


<要使用OpenCV与CodeBlocks,你需要告诉CodeBlocks:


  1. 包含OpenCV头文件的目录→ c:\opencv\build\include

  2. 链接&rarr所需的OpenCV库列表; c:\opencv\build\x86\mingw\libs\libopencv _ *。dll.a






1。添加OpenCV头文件目录



打开设置编译器和调试程序... 搜索目录标签→ 编译器标签





点击添加按钮添加新条目。在弹出对话框中,输入 c:\opencv\build\include





并点击确定






2。添加链接所需的OpenCV库



打开设置 编译器和调试程序 ...→ 链接器设置标签。





点击添加添加新条目并打开弹出对话框。



点击...按钮打开文件打开对话框。转到 c:\opencv\build\x86 \mingw\lib 目录,然后按Ctrl-A选择所有文件。



>



点击打开添加文件,





点击确定以保存所有设置。 p>




现在你已经设置了include目录和链接库,你可以编译
并运行你的项目按F9键。


I've installed Code::Blocks with MinGW and OpenCV 2.4.3. I want to compile this simple program:

#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
  Mat im = imread("c:/path/to/lena.jpg");
  if (im.empty()) {
    cout << "Cannot open image!" << endl;
    return 1;
  }
  imshow("Image", im);
  waitKey(0);
}

How to properly setup CodeBlocks for compiling the code above?

I have installed OpenCV in c:\opencv.

解决方案

To use OpenCV with CodeBlocks, you need to tell CodeBlocks:

  1. The directory which contains the OpenCV header files → c:\opencv\build\include
  2. List of OpenCV libraries needed for linking → c:\opencv\build\x86\mingw\libs\libopencv_*.dll.a


1. Add the OpenCV header files directory

Open SettingsCompiler and debugger...Search directories tab → Compiler tab

Click add button for adding a new entry. In the popup dialog, type c:\opencv\build\include,

and click Ok.


2. Add the OpenCV libraries needed for linking

Open SettingsCompiler and debugger... → Linker settings tab.

Click add for adding new entries and open a popup dialog.

Click the "..." button to open the File Open Dialog. Go to c:\opencv\build\x86\mingw\lib directory and select all files by pressing Ctrl-A.

Click Open to add the files,

Click Ok to save all settings.


Now that you've set the include directory and the libraries for linking, you can compile and run your project by pressing F9 key.

这篇关于如何使用OpenCV 2.4.3与Code :: Blocks编译程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆