我正在尝试在 netbeans 上使用 opencv 用 c++ 编写这个简单的图像修改器程序。我使用的是ubuntu 10.04。每次我尝试运行或编译它时,它都会返回以下错误。我在链接器和附加工具中配置了 opencv。出了什么问题?
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;
}
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/kevin/NetBeansProjects/CppApplication_4'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/cppapplication_4
make[2]: Entering directory `/home/kevin/NetBeansProjects/CppApplication_4'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/ main.o main.cpp
main.cpp:4:16: warning: cv.h: No such file or directory
main.cpp:5:21: warning: highgui.h: No such file or directory
main.cpp: In function ‘int main(int, char**)’:
main.cpp:10: error: ‘IplImage’ was not declared in this scope
main.cpp:10: error: ‘img’ was not declared in this scope
main.cpp:12: error: ‘uchar’ was not declared in this scope
main.cpp:12: error: ‘data’ was not declared in this scope
main.cpp:21: error: ‘cvLoadImage’ was not declared in this scope
main.cpp:32: error: expected primary-expression before ‘)’ token
main.cpp:32: error: expected ‘;’ before ‘img’
main.cpp:36: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
main.cpp:36: error: ‘cvNamedWindow’ was not declared in this scope
main.cpp:37: error: ‘cvMoveWindow’ was not declared in this scope
main.cpp:44: error: ‘cvShowImage’ was not declared in this scope
main.cpp:47: error: ‘cvWaitKey’ was not declared in this scope
main.cpp:50: error: ‘cvReleaseImage’ was not declared in this scope
make[2]: *** [build/Debug/GNU-Linux-x86/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory `/home/kevin/NetBeansProjects/CppApplication_4'
make[1]: Leaving directory `/home/kevin/NetBeansProjects/CppApplication_4'
BUILD FAILED (exit value 2, total time: 115ms)
编辑: 抱歉,造成了很大的困惑
最佳答案
好吧,先生,这是您的编译行:
g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/ main.o main.cpp
当您使用 <> 包含 header 时:
#include <cv.h>
#include <highgui.h>
编译器将在默认包含路径中搜索这些文件,通常是:/usr/include
因此,知道 opencv 不会将其开发文件安装在此目录中,我必须建议您找到它们。 如果 opencv 已正确安装在系统上,命令 pkg-config --cflags opencv
将告诉您它们在哪里。来吧,尝试一下。您还可以执行 pkg-config --libs opencv
来查找必须添加到编译中的库。
总而言之,如果您打开终端并 cd
到源代码所在的目录,下面的命令可能会编译您的项目IF您正确安装了 opencv已安装。
g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/ main.o main.cpp `pkg-config --cflags opencv` `pkg-config --libs opencv`
编辑:
你知道吗?我只是粘贴一些代码(opencv/camera)here (我们称之为funcam.cpp)。您可以使用它来测试 OpenCV 是否已安装并在您的系统上编译内容。您可以使用以下命令进行编译:
g++ funcam.cpp -o funcam `pkg-config --cflags opencv` `pkg-config --libs opencv`
如果它有效,您必须弄清楚如何配置 Netbeans。如果没有,您需要正确安装 OpenCV。
关于c - opencv 无法与 NetBeans 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3911094/