最近我在我的機器上安裝了Opencv。它在Python中工作的很好(我只是通過一些程序來檢查它)。但由於缺乏python教程,我決定搬到c。我剛剛從http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/如何在C中安裝opencv的頭文件在我的Ubuntu 11.10
運行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.
問題: 這個頭文件沒有安裝在我的系統中嗎?當我使用這個命令find/usr -name「highgui.h」我找不到任何東西 如果這個頭文件不在我的sysytem hoew中,我安裝了這個?
請幫幫我。我在OpenCV的新