我正在尝试将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]:输入目录/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.o.d
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:在函数int main(int, char**)':
main.cpp:14: error:
中cvNamedWindow'未声明(首先使用此函数)
main.cpp:14:错误:(每个未声明的标识符仅针对它出现的每个函数报告一次。)
main.cpp:15:错误:IplImage' undeclared (first use this function)
main.cpp:15: error:
img'未声明(首先使用此函数)
main.cpp:15:错误:cvSize' undeclared (first use this function)
main.cpp:15: error:
IPL_DEPTH_8U'未声明(首先使用此函数)
main.cpp:15:错误:cvCreateImage' undeclared (first use this function)
main.cpp:16: error:
CvFont'未声明(首先使用此函数)
main.cpp:16:错误:期望;' before "font"
main.cpp:17: error:
字体'未声明(首先使用此函数)
main.cpp:17:错误:CV_FONT_HERSHEY_SIMPLEX' undeclared (first use this function)
main.cpp:17: error:
CV_FONT_ITALIC'未声明(首次使用此功能)
main.cpp:17:错误:cvInitFont' undeclared (first use this function)
main.cpp:18: error:
cvPoint'未声明(首先使用此函数)
main.cpp:18:错误:cvScalar' undeclared (first use this function)
main.cpp:18: error:
cvPutText'未声明(首先使用此函数)
main.cpp:20:错误:cvShowImage' undeclared (first use this function)
main.cpp:21: error:
cvWaitKey'未声明(首先使用此函数)
nbproject / Makefile-Debug.mk:86:目标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:目标.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'的配方失败
make: * [.build-impl]错误2
BUILD FAILED(退出值2,总时间:2s)
任何人都可以提供一套明确的指示或者至少指向一份简明的指南吗?
谢谢, 丹尼尔
答案 0 :(得分:0)
假设您的包含路径包含C:\Program Files\OpenCV\include
,并且包含文件确实位于那里,请替换
#include "opencv.hpp"
与
#include "opencv2/opencv.hpp"
你可能没有#include "opencv_modules.hpp"
,否则它应该是#include "opencv2/opencv_modules.hpp"