
2、下载eclipse-cpp-helios-SR2-win32.zip
3、安装opencv,假设安装目录为:C:/OpenCV
4、解压eclipse-cpp-helios-SR2-win32.zip,启动eclipse.exe
新建C++项目->可执行程序->Hello
World
C++
Project
5、添加头文件和库文件
右键项目选择“属性”->C/C++
Build->Settings。
Tool
Settings
标签页,GCC
C++
Compiler->Includes中添加OpenCV的头文件目录,MinGW
C++
Linker->Libraries中添加OpenCV的库文件目录以及相应的库文件名称(注意:这里的库文件不加后缀名)
6、配置完成以后,可以使用下面代码进行测试:
////////////////////////////////////////////////////////////////////////
//
//
hello-world.cpp
//
//
该程序从文件中读入一幅图像,将之反色,然后显示出来.
//
////////////////////////////////////////////////////////////////////////
#include
<stdlib.h>
#include
<stdio.h>
#include
<math.h>
#include
<cv.h>
#include
<cxcore.h>
#include
<highgui.h>
int
main(int
argc,
char
*argv[])
{
IplImage*
img
=
0
int
height,width,step,channels
uchar
*data
int
i,j,k
if(argc<2){
printf("Usage:
main
<image-file-name>/n/7")
exit(0)
}
//
load
an
image
img=cvLoadImage(argv[1])
if(!img){
printf("Could
not
load
image
file:
%s/n",argv[1])
exit(0)
}
//
get
the
image
data
height
=
img->height
width
=
img->width
step
=
img->widthStep
channels
=
img->nChannels
data
=
(uchar
*)img->imageData
printf("Processing
a
%d*%d
image
with
%d
channels/n",height,width,channels)
//
create
a
window
cvNamedWindow("mainWin",
CV_WINDOW_AUTOSIZE)
cvMoveWindow("mainWin",
100,
100)
//
invert
the
image
//
相当于
cvNot(image)
for(i=0i<heighti++)
for(j=0j<widthj++)
for(k=0k<channelsk++)
data[i*step+j*channels+k]=255-data[i*step+j*channels+k]
//
show
the
image
cvShowImage("mainWin",
img
)
//
wait
for
a
key
cvWaitKey(0)
//
release
the
image
//cvReleaseImage(&img
)
return
0
}
编译OpenCV代码,用makeinstall命令默认将OpenCV装到/usr/local/目录下。在EclipseCDT中添加包含文件目录、库目录和所用到的OpenCV库文件即可。在项目属性->C/C++Build->Settings中设置编译参数。我使用的是GCCC++Compiler。在ToolSettings->GCCC++Compiler->Directories中添加OpenCV的头文件目:/usr/local/include然后,在ToolSettings->GCCC++Linker->Libraries中添加OpenCV的库文件目录:/usr/local/lib,并加入使用到的OpenCV库,不是库文件的名字libopencv_xxx.xxx,而是去掉开头和结尾,只留opencv_xxx,例如opencv_core等。设置之后就可以编译运行OpenCV程序了。欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)