1.下载并安装Eclipse+cdt,这个很简单。
2.下载linux版的opencv:http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.6.1/opencv-2.4.6.1.tar.gz/download
3.然后安装依赖包:
sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev
4.下载cmake:sudo apt-get install cmake
5.解压下载的opencv,进入该目录创建build文件夹:
cd OpenCV-2.4.6.1
mkdir build
cd build
6.一次运行:
cmake .. (注意该命令为cmake空格后面两个点)
make
sudo make install
这一步需要较长时间,请耐心等待。
7.
现在需要配置必要的库。运行
sudo
gedit /etc/ld.so.conf.d/opencv.conf
添加这句命令到文件中,/usr/
local
/lib
,文件或许是空的,但不影响。
8.运行此命令
sudo
ldconfig
9.运行此命令:
sudo
gedit /etc/
bash
.bashrc 然后添加下面两行到文件的末尾并保存:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
10.打开Eclipse并新建工程进行测试,以下是步骤:
10.1打开Eclipse,选择File->New->C Project
然后输入工程名字和存放地址,选择Executable->Empty Project,其他的都选默认即可,点击Finish.
10.2.1选择Project–>Properties
在C/C++ Build下选择Settings. 在右侧选择Tool Settings Tab. 然后输入我们的头文件包含目录:
(a).选择GCC C++ Compiler->Includes. 在Include paths(-l) 你选择你安装的include路径,我安装在/usr/local/include/opencv.
Note:要是你不知道安装在那个路径,输入如下命令:pkg-config --cflags opencv
我的结果为:-I/usr/local/include/opencv -I/usr/local/include
(b).然后进入GCC C++ Linker,这里有两个地方要输入:
首先在Library search path (-L) 你必须输入你安装的opencv库目录,我的路径是/usr/local/lib
然后在Libraries(-l) 添加你所需要的库,通常有三个是你必须的,一下是一些常见的:
opencv_core opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_features2d
opencv_calib3d opencv_objdetect opencv_contrib opencv_legacy opencv_flann
10.3好了,现在可以写代码了,选咋New->Source File:test.c,然后Finish.我的测试代码如下:
#include
#include
#include
int main( int argc, char** argv )
{
IplImage* img;
img=cvLoadImage("lena.jpg",1);
cvNamedWindow("hello",1);
cvShowImage("hello",img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("hello");
return 0;
}
把lena.jpg考入你的工程目录下即可,测试结果如图:
还有opencv自带的一篇PDF:opencv_tutorials.pdf
就这么多了,有什么问题大家一起讨论!