Resently 我在我的机器上安装了 Opencv。它在python中运行良好(我刚刚通过一些例如程序检查了它)。但由于缺乏python教程,我决定转向c。我刚刚从http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/运行一个 Hello world 程序
我的程序是
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.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 %dx%d image with %d channels\n",height,width,channels);
// create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
// invert the image
for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)
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;
}
首先在编译时出现以下错误
hello-world.c:4:16: fatal error: cv.h: No such file or directory
compilation terminated.
我通过像这样编译来纠正这个错误
gcc -I/usr/lib/perl/5.12.4/CORE -o hello-world hello-world.c
但现在错误是
In file included from hello-world.c:4:0:
/usr/lib/perl/5.12.4/CORE/cv.h:14:5: error: expected specifier-qualifier-list before ‘_XPV_HEAD’
hello-world.c:5:21: fatal error: highgui.h: No such file or directory
compilation terminated.
Qns:是不是我的系统中没有安装这个头文件?当我使用这个命令时 find /usr -name "highgui.h" 我什么也找不到 如果这个头文件不在我的系统中,我安装这个?
请帮我 。我是opencv的新手