红联Linux门户
Linux帮助

在Ubuntu上使用Eclipse创建OpenCV项目

发布时间:2014-12-19 10:38:53来源:linux网站作者:here1009

我的操作系统是Ubuntu 11.04

Eclipse 信息如下:

Eclipse IDE for C/C++ Linux Developers
Version: Helios Service Release 2
Build id: 20110218-0911


具体步骤如下:

1.首先在http://sourceforge.net/projects/opencvlibrary/下载opencv-unix安装包OpenCV-2.3.0.tar.bz2


2.安装cmake

终端运行:sudo apt-get install cmake


3.安装cmake-qt-gui,一个cmake的图形界面

终端运行: sudo apt-get install cmake-qt-gui


4.编译安装opencv

(1)cmake-qt-gui安装好之后,在终端运行cmake-gui,打开cmake的图形界面。

首先,将下载的OpenCV-2.3.0.tar.bz2解压,比如解压到文件夹OpenCV_2_3_src。

然后,新建一个文件夹比如叫作OpenCV_2_3_build,作为cmke build 到的目录。

点击cmake-gui窗口的Browse Source 选择OpenCV_2_3_src, Browse Build 选择OpenCV_2_3_build。

发现窗口变红,按提示做就是了,点Configure,然后Generate。

(2)打开终端,cd到OpenCV_2_3_build目录下,运行

make

要等比较长的时间。

完成之后

sudo make install

完成后openCV被安装到usr/local/下。

至此openCV 安装完毕。


5.在Eclipse中创建openCV项目

1)打开Eclipse,File-->New-->C++ project。就新建一个Hello World工程吧,取名叫firstOpencv。

2)将firstOpencv.cpp 中的内容改为如下,举个例子而已:

#include "cv.h"  
#include <cxcore.h>  
#include <highgui.h>  
int main(int argc, char* argv[]) 

IplImage *img = cvLoadImage("image.jpg"); 
cvNamedWindow("Image:",1); 
cvShowImage("Image:",img); 
cvWaitKey(); 
cvDestroyWindow("Image:"); 
cvReleaseImage(&img); 
return 0; 
}

3.配置包含文件的路径

Project-->Properties-->C/C++Build-->Settings-->GCC C++ Compiler-->Includes

添加/usr/local/include/opencv。

GCC C++ Linker-->Libraries 中Library search path中添加  /usr/local/lib;Libraries  中添加opencv_cv、opencv_cxcore、opencv_highgui。

点编译运行。


如果出现提示像我一样。就按提示来吧。

OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /media/myprogram/OpenCV_2_3_src/modules/highgui/src/window.cpp, line 293
terminate called after throwing an instance of 'cv::Exception'
what():  /media/myprogram/OpenCV_2_3_src/modules/highgui/src/window.cpp:293: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage

安装libgtk2.0-dev和pkg-config

sudo apt-get install libgtk2.0-dev

sudo apt-get install pkg-config

装好之后第4步再来一遍,至少我的经过这样就好了。

初学OpenCV,多多指教。