【发布时间】:2013-12-14 14:20:26
【问题描述】:
我已经按照此处所述安装了 OpenCV:Installing openCV 2.4 for C/C++ for Visual Studio。
我尝试链接 openCV 库,但我被困在 this tutorial 中的“本地方法”。
我有两个地方存放 openCV 文件: [用户名]/opencv (official)/ 我提取openCV源码的地方(进一步称为源码目录) [用户名]/opencv-build/ 我使用 cmake 构建 openCV 然后用 Visual Studio 编译它(进一步称为构建目录)
我尝试遵循的教程说链接指向构建目录的 $(OPENCV_DIR)\include。但是,我的构建目录中的“include”文件夹仅包含一些 cmake 文件,而源目录中的“include”包含 openCV 头文件(在文件夹 opencv 和 opencv 中)。我知道我应该改用源目录,但我尝试了两者都没有工作。
接下来,教程说链接 $(OPENCV_DIR)\libs。我有一个文件夹“lib”,所以我猜这只是一个拼写错误。我的文件夹“lib”包含两个文件夹:“Debug”和“Release”。我应该将 [username]/opencv-build/lib/Debug 添加到 Debug 属性页,并将 [username]/opencv-build/lib/Release 添加到 Release 属性页吗?
我在两个属性页的链接器输入中添加了 242 个版本库。
无论我做什么,Visual Studio 都会突出显示所有的 include 语句,因此也会突出显示其他所有内容。
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
任何想法我做错了什么?
在 go4sri 回答后编辑:
更改为 opencv\include\opencv 解决了包含问题(“stdafx.h”除外),但是我现在尝试了以下“hello world”:
#include <cv.h>
#include <highgui.h>
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!", cvPoint( 200, 400 ), &font,
cvScalar( 255, 255, 0 ) );
cvShowImage( "My Window", img );
cvWaitKey();
return 0;
}
虽然包含不再突出显示,但其他所有内容仍然是。错误是“标识符 XXX 未定义”。
编辑
我已将之前版本的 openCV 中的一些文件复制到<source_directory>\include\opencv2。现在 Visual Studio 不会突出显示任何内容,但是当我尝试构建它时,出现“未解析的外部符号”错误:_cvCreateImage、_cvInitFont、_cvNamedWindow、_cvPutText、_cvShowImage 和 _cvWaitKey。
【问题讨论】:
-
This thread has a good solution > 如果你想进一步了解 Open CV 中的图像处理,那么OpenCv Tutorial
标签: visual-studio-2010 visual-studio opencv