首先,你得设置编译环境(针对Visual C++),包括:
1.添加含“头文件”的文件夹位置,
<OPENCV_INSTALL>/cv/inlcude
<OPENCV_INSTALL>/cxcore/include
<OPENCV_INSTALL>/cvaux/include
<OPENCV_INSTALL>/otherlibs/cvcam/include
<OPENCV_INSTALL>/otherlibs/highgui
2.添加库文件所在的文件夹位置,
<OPENCV_INSTALL>/lib
3.和含有源文件的文件夹位置。
<OPENCV_INSTALL>/cv/src
<OPENCV_INSTALL>/cxcore/src
<OPENCV_INSTALL>/cvaux/src
<OPENCV_INSTALL>/otherlibs/highgui
<OPENCV_INSTALL>/otherlibs/cvcam/src/windows
*<OPENCV_INSTALL>即是OpenCV的安装位置。
然后建立一个工程,添加如下代码:
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int main(int argc, char **argv)
{
IplImage *img = cvLoadImage("Image.bmp");
cvNamedWindow("Image:", 1);
cvShowImage("Image:", img);
cvWaitKey();
cvDestroyWindow("Image:");
cvReleaseImage(&img);
return 0;
}
当然别忘了添加编译所需的.lib文件(cxcore.lib cv.lib highgui.lib cvaux.lib),不然链接器会显示无法链接函数。然后编译,运行。
1.添加含“头文件”的文件夹位置,
<OPENCV_INSTALL>/cv/inlcude
<OPENCV_INSTALL>/cxcore/include
<OPENCV_INSTALL>/cvaux/include
<OPENCV_INSTALL>/otherlibs/cvcam/include
<OPENCV_INSTALL>/otherlibs/highgui
2.添加库文件所在的文件夹位置,
<OPENCV_INSTALL>/lib
3.和含有源文件的文件夹位置。
<OPENCV_INSTALL>/cv/src
<OPENCV_INSTALL>/cxcore/src
<OPENCV_INSTALL>/cvaux/src
<OPENCV_INSTALL>/otherlibs/highgui
<OPENCV_INSTALL>/otherlibs/cvcam/src/windows
*<OPENCV_INSTALL>即是OpenCV的安装位置。
然后建立一个工程,添加如下代码:
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int main(int argc, char **argv)
{
IplImage *img = cvLoadImage("Image.bmp");
cvNamedWindow("Image:", 1);
cvShowImage("Image:", img);
cvWaitKey();
cvDestroyWindow("Image:");
cvReleaseImage(&img);
return 0;
}
当然别忘了添加编译所需的.lib文件(cxcore.lib cv.lib highgui.lib cvaux.lib),不然链接器会显示无法链接函数。然后编译,运行。
本文详细介绍了如何在Visual C++环境中配置OpenCV,并提供了一个简单的示例程序来展示如何加载和显示图片。此外还介绍了如何添加必要的库文件及路径。
102

被折叠的 条评论
为什么被折叠?



