
图1 使用linux源码编译产生错误
本人使用的系统摘要:

备注:原则上应该把这些文件拷贝到C:\Program Files (x86) \OpenCV目录下,因为在x64系统中,64位软件均应装在C:\Program Files\目录下,这里将x64的OpenCV库拷贝到C:\Program Files\目录下只是为了方便。
(2)Visual Studio 2010下配置OpenCV目录
糟糕,当我们打开Visual Studio 2010依次选择“工具-选项-项目和解决方案-VC++ 目录”的时候,系统会提示如图9所示信息:
经过查找文件后,我发现在“C:\Users\jiya\AppData\Local\Microsoft\MSBuild\v4.0”目录(你可能要修改一下路径)下有项目默认配置文件。
因此,我们可以编辑“Microsoft.Cpp.Win32.user.props”文件以添加相关的VC++ 目录。其中<ExecutablePath>和</ExecutablePath>标签之间是指可执行文件目录、<IncludePath>和</IncludePath>标签之间是指包含文件目录、<LibraryPath>与</LibraryPath>标签之间是指库文件目录,本人编辑后的内容如下所示:
- <?xml version="1.0" encoding="utf-8"?>
- <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <ExecutablePath>C:\Program Files\OpenCV\vc10\bin;$(ExecutablePath)</ExecutablePath>
- <IncludePath>C:\Program Files\OpenCV\include;C:\Program Files (x86)\tbb40_20120201oss\include;$(IncludePath)</IncludePath>
- <ReferencePath>$(ReferencePath)</ReferencePath>
- <LibraryPath>C:\Program Files\OpenCV\vc10\lib;C:/Program Files (x86)/tbb40_20120201oss/lib/ia32/vc9;$(LibraryPath)</LibraryPath>
- <SourcePath>$(SourcePath)</SourcePath>
- <ExcludePath>$(ExcludePath)</ExcludePath>
- </PropertyGroup>
- </Project>
Visual Stuido 2012与Visual Studio 2010类似,只是这里的配置文件与上面略有不同,如下为原始Visual Studio 2012“Microsoft.Cpp.Win32.user.props”配置文件:
- <?xml version="1.0" encoding="utf-8"?>
- <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ImportGroup Label="PropertySheets">
- </ImportGroup>
- <PropertyGroup Label="UserMacros" />
- <PropertyGroup />
- <ItemDefinitionGroup />
- <ItemGroup />
- </Project>
- <?xml version="1.0" encoding="utf-8"?>
- <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <ExecutablePath>C:\Program Files (x86)\OpenCV\bin;C:\Program Files (x86)\tbb41_20121003oss\bin\ia32\vc11;$(ExecutablePath)</ExecutablePath>
- <IncludePath>C:\Program Files (x86)\OpenCV\include;C:\Program Files (x86)\tbb41_20121003oss\include;$(IncludePath)</IncludePath>
- <ReferencePath>$(ReferencePath)</ReferencePath>
- <LibraryPath>C:\Program Files (x86)\OpenCV\lib;C:\Program Files (x86)\tbb41_20121003oss\lib\ia32\vc11;$(LibraryPath)</LibraryPath>
- <SourcePath>$(SourcePath)</SourcePath>
- <ExcludePath>$(ExcludePath)</ExcludePath>
- </PropertyGroup>
- <ImportGroup Label="PropertySheets">
- </ImportGroup>
- <PropertyGroup Label="UserMacros" />
- <PropertyGroup />
- <ItemDefinitionGroup />
- <ItemGroup />
- </Project>
Step3. 新建项目、测试
(1) 编辑代码“新建项目”,选择“Visual C++-空项目”,输入项目名“OpenCV”,“添加新项-代码-C++ 文件”,输入文件名“OpenCV.cpp”,编辑代码,这里本人使用的测试代码如下所示:
- #include <opencv/highgui.h>
- int main( int argc, char** argv ) {
- IplImage* img = cvLoadImage( argv[1] );
- cvNamedWindow( "OpenCV", CV_WINDOW_AUTOSIZE );
- cvShowImage( "OpenCV", img );
- cvWaitKey(0);
- cvReleaseImage( &img );
- cvDestroyWindow( "OpenCV" );
- return ( 0 );
- }
法1:右击项目名称,选择“属性-配置属性-链接器-输入”,将“opencv_highgui231d.lib opencv_core231d.lib opencv_ml231d.lib opencv_imgproc231d.lib”(这里注意Visual Studio 2010下依赖项之间是以分号间隔的,因此应为“opencv_highgui231d.lib;opencv_core231d.lib;opencv_ml231d.lib;opencv_imgproc231d.lib;”,如图10所示)拷贝到“附加依赖项”栏中,确定即可。
- #pragma comment( lib, "opencv_highgui231d.lib" )
- #pragma comment( lib, "opencv_core231d.lib" )
- #pragma comment( lib, "opencv_ml231d.lib" )
- #pragma comment( lib, "opencv_imgproc231d.lib" )
(3)编译即可,上述程序在main函数中使用了参数,如果想调试的话,可以右击项目名称,选择“属性-配置属性-调试”,在命令参数项中输入参数(如“D:\\Lena.jpg”,注意这里是双反斜线,起转义作用,如图11所示)即可。
图12 Visual Studio 2010下测试例子正常运行
备注:在配置OpenCV的时候你可能需要intel TBB,但是这不是必需的。如果在编译程序的时候提示“找不到tbb_debug.dll”等问题,请下载intel TBB并像上面一样配置环境变量及VC++目录(注意要注销一下电脑或者重启“explorer.exe”进程)。
2013年01月19日更新:
添加附加依赖项有两种方法,其中第二种方法我们可以用一种比较简便的方法先写入一个“.txt”文件(根据需要对批处理文件进行修改,如果需要将release版本的库文件,则将“*243d.lib”更改为“*243.lib”,注意“243”为OpenCV的版本号),然后将再对其进行修改即可。批处理脚本为:
- dir *243d.lib /ON /B > libd.txt

- #pragma comment( lib, "opencv_calib3d243d.lib" )
- #pragma comment( lib, "opencv_contrib243d.lib" )
- #pragma comment( lib, "opencv_core243d.lib" )
- #pragma comment( lib, "opencv_features2d243d.lib" )
- #pragma comment( lib, "opencv_flann243d.lib" )
- #pragma comment( lib, "opencv_gpu243d.lib" )
- #pragma comment( lib, "opencv_highgui243d.lib" )
- #pragma comment( lib, "opencv_imgproc243d.lib" )
- #pragma comment( lib, "opencv_legacy243d.lib" )
- #pragma comment( lib, "opencv_ml243d.lib" )
- #pragma comment( lib, "opencv_nonfree243d.lib" )
- #pragma comment( lib, "opencv_objdetect243d.lib" )
- #pragma comment( lib, "opencv_photo243d.lib" )
- #pragma comment( lib, "opencv_stitching243d.lib" )
- #pragma comment( lib, "opencv_ts243d.lib" )
- #pragma comment( lib, "opencv_video243d.lib" )
- #pragma comment( lib, "opencv_videostab243d.lib" )
- #pragma comment( lib, "opencv_world243d.lib" )
附录:
OpenCV视觉库: http://sourceforge.net/projects/opencvlibrary/
TBB Home: http://threadingbuildingblocks.org/
Cmake: http://www.cmake.org
安装opencv 2.3出现错误“opencv error PRJ0019: 工具从“正在执行生成后事件...”: http://blog.youkuaiyun.com/yongshengsilingsa/article/details/6743680
附件下载:
http://115.com/file/an0ceovg# OpenCV-2.3.1-win-superpack.exe
http://115.com/file/bem4144r# OpenCV-2.4.0.exe
http://115.com/file/an050xhb# tbb40_20120201oss_win.zip
编译后文件(无需再编译,可直接使用):

1049

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



