1、搜索并下载opencv的安装文件(我就不上链接了,因为链接可能会失效),目前最新版本为2.4
2、双击.exe解压文件到你喜欢的地方
3、在VS中新建一个C++项目,然后点击菜单栏中项目->属性,在属性页中打开配置属性的VC++ 目录
4、在包含目录中添加opencv/build/include、opencv/build/include/opencv和opencv/build/include/opencv2三个目录
5、在库目录中添加opencv\build\x86\vc10\lib(32-bit系统)或opencv\build\x64\vc10\lib(64-bit系统),点确定。
6、在连接器->输入的附加依赖项中添加以下库:
opencv_core241d.lib
opencv_highgui241d.lib
opencv_video241d.lib
opencv_ml241d.lib
opencv_legacy241d.lib
opencv_imgproc241d.lib
6、新建一个C++文件,保存本文最后的代码
7、复制一个.jpg格式的图片到步骤6所创建的C++文件所在目录,并命名为photo.jpg
8、在VS中按F5编译运行工程,如无错误,就会显示photo.jpg文件了
参考:http://opencv.willowgarage.com/wiki/VisualC%2B%2B
附:opencv测试代码:
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int main(int argc, char* argv[])
{
// Open the file.
IplImage *img = cvLoadImage("photo.jpg");
if (!img) {
printf("Error: Couldn't open the image file.\n");
return 1;
}
// Display the image.
cvNamedWindow("Image:", CV_WINDOW_AUTOSIZE);
cvShowImage("Image:", img);
// Wait for the user to press a key in the GUI window.
cvWaitKey(0);
// Free the resources.
cvDestroyWindow("Image:");
cvReleaseImage(&img);
return 0;
}
本文详细介绍了如何在Visual Studio环境中安装并配置OpenCV库的方法,包括下载安装文件、配置开发环境及测试代码运行等关键步骤。
585

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



