-2

我正在尝试将 OpenCV 与 Netbeans 7.3.1 一起使用。我已尝试遵循各种教程和博客,但无法运行任何文件。以下代码被列为检查 opencv 安装的良好示例代码:

#include <cstdlib>

using namespace std;
#include "opencv.hpp"
#include "opencv_modules.hpp"
int main ( int argc, char **argv ) { 
    cvNamedWindow( "My Window", 1 ); 
    IplImage *img = cvCreateImage( cvSize( 640, 480 ), IPL_DEPTH_8U, 1 ); 
    CvFont font; 
    double hScale = 1.0; 
    double vScale = 1.0; 
    int lineWidth = 1; 
    cvInitFont( &font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC, hScale, vScale, 0, lineWidth ); 
    cvPutText( img, "Hello World!, I can now code openCV ", cvPoint( 0, 200 ), &font, Scalar    
    (255, 255, 0 ) ); 
    cvPutText( img, "in a kickass IDE ", cvPoint( 150, 300 ), &font, cvScalar( 255, 255, 0 ) ); 
    cvShowImage( "My Window", img ); 
    cvWaitKey(); 
return 0; 
}

该代码导致以下错误:“/usr/bin/make” -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf make[1]: Entering directory/cygdrive/c/Users/Daniel/Documents/NetBeansProjects/CppApplication_4' "/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_1-Windows/cppapplication_4.exe make[2]: Entering directory/cygdrive/c/Users/Daniel/Documents/NetBeansProjects/CppApplication_4' mkdir -p build/Debug/Cygwin_1-Windows rm -f build/Debug/Cygwin_1-Windows/main.od g++ -c -g -I../。 ./../../../Program\ Files/OpenCV/build/include/opencv2 -MMD -MP -MF build/Debug/Cygwin_1-Windows/main.od -o build/Debug/Cygwin_1-Windows/main .o main.cpp 在 main.cpp:11 中包含的文件中:../../../../../Program Files/OpenCV/build/include/opencv2/opencv.hpp:46:33: opencv2 /core/core_c.h:没有这样的文件或目录../../../../../Program Files/OpenCV/build/include/opencv2/opencv.hpp:47:33: opencv2/core/ core.hpp:没有这样的文件或目录../../../../../Program Files/OpenCV/build/include/opencv2/opencv.hpp:48:39: opencv2/flann/miniflann.hpp :没有这样的文件或目录../../../../../Program Files/OpenCV/build/include/opencv2/opencv.hpp:49:39: opencv2/imgproc/imgproc_c.h:没有这样的文件或目录../../../../../Program Files/OpenCV/build/include/opencv2/opencv.hpp:50:39: opencv2/imgproc/imgproc.hpp: 没有这样的文件或目录../../../../../Program Files/OpenCV/build/include/opencv2/opencv.hpp:51:35: opencv2/photo/photo.hpp: 没有这样的文件或目录。 ./../../../../Program Files/OpenCV/build/include/opencv2/opencv.hpp:52:35: opencv2/video/video.hpp: 没有这样的文件或目录../。 ./../../../Program Files/OpenCV/build/include/opencv2/opencv.hpp:53:45: opencv2/features2d/features2d.hpp: 没有这样的文件或目录../../。 ./../../Program Files/OpenCV/build/include/opencv2/opencv.hpp:54:43: opencv2/objdetect/objdetect.hpp: 没有这样的文件或目录../../../。 ./../Program Files/OpenCV/build/include/opencv2/opencv.hpp:55:39: opencv2/calib3d/calib3d.hpp: 没有这样的文件或目录../../../../。 ./Program Files/OpenCV/build/include/opencv2/opencv.hpp:56:29: opencv2/ml/ml.hpp: 没有这样的文件或目录../../../../../Program Files /OpenCV/build/include/opencv2/opencv.hpp:57:39: opencv2/highgui/highgui_c.h: 没有这样的文件或目录../../../../../Program Files/OpenCV/ build/include/opencv2/opencv.hpp:58:39: opencv2/highgui/highgui.hpp: 没有这样的文件或目录../../../../../Program Files/OpenCV/build/include /opencv2/opencv.hpp:59:39: opencv2/contrib/contrib.hpp: 没有这样的文件或目录 main.cpp: 在函数中没有这样的文件或目录../../../../../Program Files/OpenCV/build/include/opencv2/opencv.hpp:59:39: opencv2/contrib/contrib.hpp: 没有这样的文件或目录 main.cpp:在函数中没有这样的文件或目录../../../../../Program Files/OpenCV/build/include/opencv2/opencv.hpp:59:39: opencv2/contrib/contrib.hpp: 没有这样的文件或目录 main.cpp:在函数中int main(int, char**)': main.cpp:14: error:cvNamedWindow' undeclared (首先使用这个函数) main.cpp:14: error: (每个未声明的标识符对于它出现的每个函数只报告一次。) main.cpp:15: error: IplImage' undeclared (first use this function) main.cpp:15: error:img' undeclared (首先使用这个函数) main.cpp:15: error: cvSize' undeclared (first use this function) main.cpp:15: error:IPL_DEPTH_8U' undeclared (首先使用这个函数) main.cpp:15: error: cvCreateImage' undeclared (first use this function) main.cpp:16: error:CvFont' undeclared (首先使用这个函数) main.cpp:16: error: expected ;' before "font" main.cpp:17: error:font' undeclared (首先使用这个function) main.cpp:17: error: CV_FONT_HERSHEY_SIMPLEX' undeclared (first use this function) main.cpp:17: error:CV_FONT_ITALIC' undeclared (第一次使用这个函数) main.cpp:17: error: cvInitFont' undeclared (first use this function) main.cpp:18: error:cvPoint' undeclared (第一次使用这个函数) main.cpp:18: error: cvScalar' undeclared (first use this function) main.cpp:18: error:cvPutText' undeclared (第一次使用这个函数)main.cpp:20:错误:cvShowImage' undeclared (first use this function) main.cpp:21: error:cvWaitKey' 未声明(首先使用这个函数) nbproject/Makefile-Debug.mk:86: recipe for target build/Debug/Cygwin_1-Windows/main.o' failed make[2]: *** [build/Debug/Cygwin_1-Windows/main.o] Error 1 make[2]: Leaving directory/cygdrive/c/Users/Daniel/Documents/NetBeansProjects/CppApplication_4' nbproject/Makefile-Debug.mk:59: recipe for target .build-conf' failed make[1]: *** [.build-conf] Error 2 make[1]: Leaving directory/cygdrive/c/Users/Daniel/Documents/NetBeansProjects/CppApplication_4' nbproject/Makefile-impl.mk:39:目标“.build-impl”的配方失败:* [.build-impl] 错误 2

BUILD FAILED(退出值2,总时间:2s)

任何人都可以帮助提供一套清晰的说明或至少指向一个简明的指南吗?

谢谢,丹尼尔

4

1 回答 1

0

假设您的包含路径包含C:\Program Files\OpenCV\include,并且包含文件确实位于那里,请替换

#include "opencv.hpp"

#include "opencv2/opencv.hpp"

你可能没有#include "opencv_modules.hpp",否则应该是#include "opencv2/opencv_modules.hpp"

于 2013-06-23T22:33:46.300 回答