现在的位置: 首页 > 综合 > 正文

win 7 + VC++ 2008 express + OpenCv 2.1.0安装

2013年09月08日 ⁄ 综合 ⁄ 共 2509字 ⁄ 字号 评论关闭

官方文档并注释:
These instructions were tested with Visual C++ 9.0 (as part of Visual Studio 2008 Professional). These instructions should work without modification with Visual Studio 2005 and 2003. Modifications may be necessary for Visual Studio Express editions. These instructions
do not apply to Visual Studio 2010 which uses different settings (see VisualC++).
 
Install OpenCV
Download the OpenCV 2.1.0 Windows installer from SourceForge - "OpenCV-2.1.0-win32-vs2008.exe".
Install it to a folder (without any spaces in it), say "C:\OpenCV2.1\". This article will refer to this path as $openCVDir
During installation, enable the option "Add OpenCV to the system PATH for all users".
由于有些函数需要TBB,所以需要将tbb所在的目录也加入到环境变量Path中如C:\TBB\bin\ia32\vc9   加入后可能需要注销当前Windows用户(或重启)后重新登陆才生效
 
Configure Visual Studio
Open VC++ Directories configuration: Tools > Options > Projects and Solutions > VC++ Directories
Choose "Show directories for: Include files"
Add "$openCVDir\include\opencv"
Choose "Show directories for: Library files"
Add "$openCVDir\lib"
  如果使用了DirectShow,  Add  "../DirectShow/Lib"(看具体情况)
Choose "Show directories for: Source files"
Add "$openCVDir\src\cv"
Add "$openCVDir\src\cvaux"
Add "$openCVDir\src\cxcore"
Add "$openCVDir\src\highgui"
Add "$openCVDir\src\ml"

Configure your Project
After you've created a project you'll need to add the OpenCV dependencies.(debug 和release 都添加)
Open Project Properties: Project > %projectName% Properties...
Open Linker Input properties: Configuration Properties > Linker > Input
Open the "..." window to edit "Additional Dependencies" and on each line put:
"cv210.lib"
"cxcore210.lib"
"highgui210.lib"
“ml210.lib”
“cvaux210.lib”

And any other lib file necessary for your project


注意,请打开了新编辑窗口(即点击了“...”按钮)“附加依赖项”,并一条一条分别加入,一条一行(一个回车),(注意行末不要加";")否则会出现类似以下错误:1>LINK : fatal error LNK1104: 无法打开文件“…….lib”
Your project should now build. If you get any errors try restarting Visual Studio and then doing a clean Rebuild.


如果使用了DirectShow or DirectX, 在vs的解决方案资源管理器中右键相应的项目,选择属性,在属性窗口的 配置属性 -> C/C++ -> 常规 中的 附加包含目录,点击其右边的小按钮,在弹出的附加包含目录中,确保条目 $(WindowsSdkDir)\include 和 $(FrameworkSDKDir)include 在任何dx目录如..\DirectShow\Include的前面。如果要在全局配置添加头文件目录,也要遵循这个原则


用下面的程序测试:

// OpenCV_Helloworld.cpp : Defines the entry point for the console application.

// Created for build/install tutorial, Microsoft Visual C++ 2008 Express and OpenCV //2.1.0

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "stdafx.h"

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

int _tmain(int argc, _TCHAR *argv[])
{
    IplImage *img = cvLoadImage("e.jpg");
    cvNamedWindow("Image:"1);
    cvShowImage("Image:", img);
    cvWaitKey();
    cvDestroyWindow("Image:");
    cvReleaseImage(&img);
    return 0;
}


//双击exe的话,e.jpg图片放在.exe(先bulid)同一文件夹内;按F5直接运行程序的话,
//e.jpg要放在opencv\opencv里

参考:OPencvChina官网

抱歉!评论已关闭.