<h1 style="margin: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 32px; color: rgb(204, 153, 51); font-weight: normal;">1.下载和安装OpenCV SDK</span> </h1> <div> <span style="font-family: "Microsoft YaHei"; font-size: 32px; color: rgb(204, 153, 51);"><br/></span> </div> <div> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </div> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">VS2010不用说,肯定都安装了吧。来说说当前最新的OpenCV版本2.4.8(2014年2月24日),2.4.9 (2014年4月)的下载和安装。与其说是安装,不如叫解压更加合适,因为我们下载的exe安装文件就是一个自解压程序而已。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140224101937734?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"></p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">在官网:<a target="_blank" href="http://undefined" style="text-decoration-line: none; color: rgb(12, 137, 207);">http://opencv.org/</a>上找到OpenCV windows版下载下来。</span><img src="http://img.blog.csdn.net/20140224102048343?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 602px; max-height: 100%; height: auto; font-family: "Microsoft YaHei"; font-size: 14px;"/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"></p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">下载完后得到文件OpenCV 2.4.X,双击后会提示解压到某个地方,推荐放到D:\Program Files\下,比如D:\Program Files,(因为OpenCV项目文件打包的时候,根目录就是opencv,所以我们不需要额外的新建一个名为opencv的文件夹,然后再解压,那是多此一举的事情)然后点击Extract按钮。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <img src="http://img.blog.csdn.net/20140224102109375?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 602px; max-height: 100%; height: auto;"/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">等一段时间,OpenCV2.4.8近3个多G的文件就解压到了D:\Program Files下。</span><br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140224102140687?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <h2 style="margin: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px; font-weight: normal;"> 其中,build里面是使用OpenCV相关的文件,我们如果只是使用</span><span style="font-family: "Microsoft YaHei"; font-size: 14px; font-weight: normal;">OpenCV的话呢,就只用管build里面的内容</span><span style="font-family: "Microsoft YaHei"; font-size: 14px; font-weight: normal;">。下面的sources文件夹你嫌烦,你嫌占硬盘空间,完全可以删掉。但是需要注意的是,官方示例集,也就是samples文件夹里面的示例程序,在</span><span style="font-family: "Microsoft YaHei"; font-size: 14px; font-weight: normal;">sources文件夹里面躺着呢,所以,如果真是要删的话,还是想清楚哦。</span> </h2> <h2 style="margin: 0px; padding: 0px;"> <a target="_blank" style="color: rgb(12, 137, 207);" href="http://undefined"></a><span style="font-family: "Microsoft YaHei"; font-size: 14px; font-weight: normal;">sources里面是源代码。可以直接查看。如何生成sln解决方案浅墨在这篇博文中有详细讲到:</span> </h2> <h2 style="margin: 0px; padding: 0px;"> <a target="_blank" style="color: rgb(12, 137, 207);" href="http://undefined"></a><span style="font-family: "Microsoft YaHei"; font-size: 14px;"> <a target="_blank" href="http://undefined" style="text-decoration-line: none; color: rgb(12, 137, 207); font-size: 20px; line-height: 30px;"><span style="color: rgb(204, 0, 0);">【OpenCV入门教程之七】 玩转OpenCV源代码:生成OpenCV工程解决方案与OpenCV源码编译</span></a></span> </h2> <div> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </div> <div> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </div> <h1 style="margin: 0px; padding: 0px;"> <a target="_blank" style="color: rgb(12, 137, 207);" href="http://undefined"></a><span style="font-family: "Microsoft YaHei"; font-size: 32px; color: rgb(153, 51, 153); font-weight: normal;">2.配置环境变量</span> </h1> <div> <span style="font-family: "Microsoft YaHei"; font-size: 32px; color: rgb(153, 51, 153);"><br/></span> </div> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> </span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> </span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">这步的配置方法如下:</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">【计算机】->【(右键)属性】->【高级系统设置】->【高级(标签)】->【环境变量】->“双击”系统变量中的PATH->在变量值里面添加相应的路径。如图:</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><1></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140611202529296?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><2></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140611202801093?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><3></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140611202633406?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><4></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140611202644031?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><5></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140611202702546?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">对于32位系统,就添加:</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">”;…… opencv\build\x86\vc10\bin”(和之前的就有有的环境变量用英文的分号“;”进行分隔)</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> </span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">而对于64位系统,可以两个都添加上:</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">”;…… opencv\build\x86\vc10\bin”</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">和”…… opencv\build\x64\vc10\bin”,</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">这样,到时候才可以在编译器Win32和X64中来回切换都吃得开,游刃有余~</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">例如,浅墨的就是</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">D:\Program Files\opencv\build\x64\vc10\bin;D:\Program Files\opencv\build\x86\vc10\bin</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> PS:有童鞋亲测说64位系统也只需添加”…… opencv\build\x86\vc10\bin”即可,大家不妨一试。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">注:变量值实际为bin文件夹的路径;D表示OpenCV安装于D盘;X64表示运行系统环境位64位系统,若安装于32位系统,应为X86;vc10表示编译环境为Microsoft Visual Studio 2010;变量添加完成后最好注销系统,才会生效。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> </span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> </span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <h1 style="margin: 0px; padding: 0px;"> <a target="_blank" style="color: rgb(12, 137, 207);" href="http://undefined"></a><span style="font-family: "Microsoft YaHei"; font-size: 32px; color: rgb(51, 51, 255); font-weight: normal;">3.工程包含(include)目录的配置</span> </h1> <div> <span style="font-family: "Microsoft YaHei"; font-size: 32px; color: rgb(51, 51, 255);"><br/></span> </div> <div> <span style="font-family: "Microsoft YaHei"; font-size: 32px; color: rgb(51, 51, 255);"><br/></span> </div> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">之前看过的好多博文都说“每次新建工程都要重新配置”,其实不用这样麻烦的。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">首先是在Visual Studio里面新建一个控制台应用程序,最好是勾好空项目那个勾。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">(考虑到看这篇博文的童鞋很少接触vs,那么浅墨在这里将过程详细截图出来——浅墨2014年6月11日注)<br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei";"><span style="font-size: 14px;"><1>打开visual studio,新建win32控制台项目,取个名字,比如叫test1,然后选好路径,点确定.</span></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140611203901984?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><2>点一次“下一步”。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140611203537718?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><3>勾上空项目那个勾。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140611204002984?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><4>接着在解决方案资源管理器的【源文件】处右击->添加->新建项,准备在工程中新建一个cpp源文件。<br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140611204027000?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140611204125484?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><5>选定C++源文件,取个名字,比如叫“main”,然后点【添加】,那么,一个新的cpp文件就添加到了工程中。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><6></span><span style="font-family: "Microsoft YaHei"; font-size: 14px;">看过浅墨之前DirectX配置的相关博文的朋友们应该都知道,有一招叫属性管理器。在属性管理器中进行一次配置,就相当于进行了通用的配置过程,以后新建的工程就不用再额外的进行重新配置了。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">在菜单栏里面点<视图>--<属性管理器>,那么就会在visual studio中多出一个属性管理器工作区来。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140224102944687?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><7>在新出现的“属性管理器”工作区中,点击项目->Debug|Win32->Microsoft.Cpp.Win32.userDirectories(右键属性,或者双击)即可打开属性页面。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> <img src="http://img.blog.csdn.net/20140224103001375?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"></p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><8>打开属性页面后,就是一番配置了。首先是在</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">【通用属性】 ->【VC++目录】 ->【包含目录】中</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140224103237765?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">添加上</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">D:\Program Files\opencv\build\include</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">D:\Program Files\opencv\build\include\opencv</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">D:\Program Files\opencv\build\include\opencv2 这三个目录。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140224103257015?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">当然,这是之前把OpenCV解压到D:\Program Files\下的情况。实际的路径还要看你自己把OpenCV解压到了哪个目录下,根据你的实际情况来调节。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <h1 style="margin: 0px; padding: 0px;"> <a target="_blank" style="color: rgb(12, 137, 207);" href="http://undefined"></a><span style="font-family: "Microsoft YaHei"; font-size: 32px; color: rgb(0, 153, 0); font-weight: normal;">4.工程库(lib)目录的配置</span> </h1> <div> <span style="font-family: "Microsoft YaHei"; font-size: 32px; color: rgb(0, 153, 0);"><br/></span> </div> <div> <span style="font-family: "Microsoft YaHei"; font-size: 32px; color: rgb(0, 153, 0);"><br/></span> </div> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">其实这步和上一步差不多,属性管理器”工作区中,点击项目->Debug|Win32->Microsoft.Cpp.Win32.userDirectories(反键属性,或者双击)打开属性页面。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">接着上步,就是在【通用属性】 ->【VC++目录】 ->【库目录】中,</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140224103438109?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">添加上D:\Program Files\opencv\build\x86\vc10\lib这个路径。(最好不要复制粘贴浅墨给出的路径,而是自己去预览里面指定出来,这样会准确得多)</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p>
<blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"> <blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"> <blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><span style="color: rgb(51, 102, 255);">(感谢<a target="_blank" class="username" href="http://undefined" style="text-decoration-line: none; color: rgb(12, 137, 207); line-height: 26px; background-color: rgb(228, 228, 228);">小如风</a>童鞋,之前给出的路径D:\Program Files\opencv\build\x86\vc10\lib里少个空格,直接复制浅墨给出的上面路径的童鞋就会出现“<span style="line-height: 20px;">无法打开错误 1 error LNK1104: 无法打开文件“opencv_calib3d248.lib”类似的错误</span>”,现已更正)</span></span> </p> </blockquote> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"> <blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"> <blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><span style="color: rgb(51, 102, 255);"><span style="white-space: pre;"> </span>——————浅墨于2014年4月3日</span></span> </p> </blockquote> </blockquote> </blockquote>
<p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">这里选择x86还是x64是一个常常令人困惑的问题。当然,对于32位操作系统,铁定就是选x86了。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">如果是64位操作系统,很多童鞋会想当然自作聪明地选择x64,其实不然。正确的理解是这样的:</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px; color: rgb(204, 0, 0);"></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei";"><strong><span style="font-size: 14px; color: rgb(204, 0, 0);">不管你是32位还是64位操作系统,只用管你用win32编译器还是X64编译器。</span></strong></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei";"><strong><span style="font-size: 14px; color: rgb(204, 0, 0);">其实配置选择什么跟64位还是32位系统没有直接的关系,而是在于你在编译你的程序的时候是使用那个编译器。</span></strong></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei";"><strong><span style="font-size: 14px; color: rgb(204, 0, 0);"><img src="http://img.blog.csdn.net/20140224103833203?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span></strong></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"></p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei";"><strong><span style="font-size: 14px; color: rgb(204, 0, 0);">编译器选的是win32,就用x86</span></strong></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <strong><span style="font-size: 14px; color: rgb(204, 0, 0);"><span style="font-family: "Microsoft YaHei";">编译器选的是X64,就用X64。不过一般情况下,都是用的win32的X86编译器。所以,</span>无论32还是64位操作系统,配置文件最好都选择x86版的</span></strong> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">另外,这里的vc10表示vs2010,如果是其他版本的visual studio,稍微要微调一下。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><span style="line-height: 20px;">感谢<a target="_blank" class="username" href="http://undefined" style="text-decoration-line: none; color: rgb(51, 102, 153); line-height: 26px; background-color: rgb(228, 228, 228);">JJBomb</a><span style="color: rgb(136, 136, 136); line-height: 26px; background-color: rgb(228, 228, 228);"> </span><span style="line-height: 26px;">童鞋,这里我们补充完整:</span>vc8 = Visual Studio 2005,vc9 = Visual Studio 2008,vc10 = Visual Studio 2010,vc11 = Visual Studio 2012,vc12 = Visual Studio 2013。</span><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> </span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"></p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <h1 style="margin: 0px; padding: 0px;"> <a target="_blank" style="color: rgb(12, 137, 207);" href="http://undefined"></a><span style="font-family: "Microsoft YaHei"; font-size: 32px; color: rgb(204, 102, 0); font-weight: normal;">5.链接库的配置</span> </h1> <div> <span style="font-family: "Microsoft YaHei"; font-size: 32px; color: rgb(204, 102, 0);"><br/></span> </div> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> </span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">依然是“属性管理器”工作区中,点击项目->Debug|Win32->Microsoft.Cpp.Win32.userDirectories(反键属性,或者双击)即可打开属性页面。【通用属性】 ->【链接器】->【输入】->【附加的依赖项】</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140224104521937?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei";"><span style="font-size: 18px;">对于</span><span style="font-size: 24px; color: rgb(204, 0, 0);">【</span><span style="font-size: 24px; color: rgb(204, 0, 0);">OpenCV2.4.8】</span><span style="font-size: 18px;">,添加如下248版本的lib<span style="font-size: 14px;">(这样的lib顺序是:</span><span style="font-size: 14px;">19个</span><span style="font-size: 14px;">带d的debug版的lib写在前面,19个不带d的release版的lib写在后面)</span>:</span></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-size: 14px;"></span> </p><span style="font-family: "Microsoft YaHei"; font-size: 14px;">opencv_ml248d.lib<br/>opencv_calib3d248d.lib<br/>opencv_contrib248d.lib<br/>opencv_core248d.lib<br/>opencv_features2d248d.lib<br/>opencv_flann248d.lib<br/>opencv_gpu248d.lib<br/>opencv_highgui248d.lib<br/>opencv_imgproc248d.lib<br/>opencv_legacy248d.lib<br/>opencv_objdetect248d.lib<br/>opencv_ts248d.lib<br/>opencv_video248d.lib<br/>opencv_nonfree248d.lib<br/>opencv_ocl248d.lib<br/>opencv_photo248d.lib<br/>opencv_stitching248d.lib<br/>opencv_superres248d.lib<br/>opencv_videostab248d.lib<br/><br/>opencv_objdetect248.lib<br/>opencv_ts248.lib<br/>opencv_video248.lib<br/>opencv_nonfree248.lib<br/>opencv_ocl248.lib<br/>opencv_photo248.lib<br/>opencv_stitching248.lib<br/>opencv_superres248.lib<br/>opencv_videostab248.lib<br/>opencv_calib3d248.lib<br/>opencv_contrib248.lib<br/>opencv_core248.lib<br/>opencv_features2d248.lib<br/>opencv_flann248.lib<br/>opencv_gpu248.lib<br/>opencv_highgui248.lib<br/>opencv_imgproc248.lib<br/>opencv_legacy248.lib<br/></span> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">opencv_ml248.lib</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-size: 14px;"></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei";"><span style="font-size: 18px;">对于</span><span style="font-size: 24px; color: rgb(204, 0, 0);">【OpenCV2.4.9】</span><span style="font-size: 18px;">,添加如下249版本的lib</span><span style="font-size: 14px;">(这样的lib顺序是:</span><span style="font-size: 14px;">19个</span><span style="font-size: 14px;">带d的debug版的lib写在前面,19个不带d的release版的lib写在后面)</span></span><span style="font-family: "Microsoft YaHei";"><span style="font-size: 18px;">:</span></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><span style="white-space: pre;"></span></span> </p> <div> <div style="text-align: -webkit-auto;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">opencv_ml249d.lib<br/>opencv_calib3d249d.lib<br/>opencv_contrib249d.lib<br/>opencv_core249d.lib<br/>opencv_features2d249d.lib<br/>opencv_flann249d.lib<br/>opencv_gpu249d.lib<br/>opencv_highgui249d.lib<br/>opencv_imgproc249d.lib<br/>opencv_legacy249d.lib<br/>opencv_objdetect249d.lib<br/>opencv_ts249d.lib<br/>opencv_video249d.lib<br/>opencv_nonfree249d.lib<br/>opencv_ocl249d.lib<br/>opencv_photo249d.lib<br/>opencv_stitching249d.lib<br/>opencv_superres249d.lib<br/>opencv_videostab249d.lib</span> </div> <div style="text-align: -webkit-auto;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/>opencv_objdetect249.lib<br/>opencv_ts249.lib<br/>opencv_video249.lib<br/>opencv_nonfree249.lib<br/>opencv_ocl249.lib<br/>opencv_photo249.lib<br/>opencv_stitching249.lib<br/>opencv_superres249.lib<br/>opencv_videostab249.lib<br/>opencv_calib3d249.lib<br/>opencv_contrib249.lib<br/>opencv_core249.lib<br/>opencv_features2d249.lib<br/>opencv_flann249.lib<br/>opencv_gpu249.lib<br/>opencv_highgui249.lib<br/>opencv_imgproc249.lib<br/>opencv_legacy249.lib</span> </div> <div style="text-align: -webkit-auto;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">opencv_ml249.lib</span> </div> </div> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-size: 14px;"></span> </p><span style="font-size: 14px;"><br/></span> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> <img src="http://img.blog.csdn.net/20140224104542250?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">需要注意的是,所粘贴内容即为之前我们解压的OpencV目录D:\opencv\build\x86\vc10\lib下所有lib库文件的名字;其中的248代表我们的OpenCV版本为2.4.8,若是其他版本的配置则在这里要进行相应的更改,比如说2.4.6版的OpenCV,那么这里的opencv_calib3d248d.lib就要改成opencv_calib3d246d.lib了.</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">Debug文件库名有d结尾,Release没有,如 opencv_ts248d.lib(debug版本的lib)和opencv_ts248.lib(release版本的lib)</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">不过我一般是在这里把带d和不带d的统统写在这里,因为这里是以后创建所有工程时都会继承的公共属性。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei";"><span style="font-size: 18px;">对于</span><span style="font-size: 24px; color: rgb(204, 0, 0);">【OpenCV 3.0】</span><span style="font-size: 18px;">,</span><span style="font-size: 14px;">添加3.0版本的lib,新版的lib非常简单。想用debug版本的库,添加</span></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-size: 14px; font-family: 方正兰亭刊黑_GBK; text-align: -webkit-auto;">opencv_ts300d.lib</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-size: 14px; font-family: 方正兰亭刊黑_GBK; line-height: 20px;">opencv_world300d.lib 这两个库即可。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-size: 14px; font-family: 方正兰亭刊黑_GBK; line-height: 20px;">而想用release版本的库,添加<br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: 方正兰亭刊黑_GBK; font-size: 14px; text-align: -webkit-auto;">opencv_ts300.lib</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: 方正兰亭刊黑_GBK; font-size: 14px; line-height: 20px;">opencv_world300.lib</span><span style="font-family: 方正兰亭刊黑_GBK; font-size: 14px; text-align: -webkit-auto;">即可。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"></p> <div> <span style="font-family: 方正兰亭刊黑_GBK; font-size: 14px;"><br/></span> </div> <div> <span style="font-size: 14px;">其实,对已经发行和</span><span style="font-family: "Microsoft YaHei";"><span style="font-size: 14px;">未来即将发布的新版OpenCV,只需看opencv\build\x86\vc10\lib下的库是哪几个,添加成依赖项就可以了。</span></span> </div> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"></p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; color: rgb(204, 0, 0); font-size: 24px;">另外注意</span><span style="color: rgb(204, 0, 0); font-size: 14px; font-family: "Microsoft YaHei";">:</span><span style="font-family: "Microsoft YaHei";"><span style="color: rgb(153, 51, 153); font-size: 18px;">按照如上的这种方式来配置,也许会出现debug下可以运行但是release下不能运行的情况(因为字符串读取问题引起的诸如图片载入不了,报指针越界,内存错误等等),这算是OpenCV自2.4.1以来的一个bug。</span></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei";"><span style="font-size: 24px; color: rgb(204, 0, 0);">解决方案:</span><span style="color: rgb(153, 51, 153); font-size: 18px;">想在release模式下运行出程序结果,在工程的release模式下,将不带d的lib(全部是19个)添加到【项目】->【属性】(注意这样打开的是当前工程的属性页,我们只需在这里将release版(即不带d)的相关lib添加进去)->【配置属性】->【链接器】->【输入】->【附加的依赖项】下即可。</span></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei";"><span style="font-size: 14px;"><span style="color: rgb(204, 0, 0);"><span style="white-space: pre;"> </span>——————浅墨 2014年3月17日注&2014年6月11日更新</span></span></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei";"><span style="font-size: 14px;"><span style="line-height: 26px;">类似错误如图:</span><br/></span></span> </p>
<blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"> <blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"> <blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"> <blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei";"><span style="font-size: 14px;"><span style="color: rgb(204, 0, 0);"><img src="http://img.blog.csdn.net/20140318222335359?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" width="444" height="200" style="border: none; max-width: 100%; max-height: 100%;"/></span></span></span> </p> </blockquote> </blockquote> </blockquote> </blockquote>
<p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> </span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> </span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <br/> </p> <h1 style="margin: 0px; padding: 0px;"> <a target="_blank" style="color: rgb(12, 137, 207);" href="http://undefined"></a><span style="font-family: "Microsoft YaHei"; font-size: 24px; color: rgb(0, 153, 0); font-weight: normal;">6.在Windows文件夹下加入OpenCV动态链接库</span> </h1> <div> <span style="font-family: "Microsoft YaHei"; font-size: 24px; color: rgb(0, 153, 0);"><br/></span> </div> <div> <span style="font-family: "Microsoft YaHei"; font-size: 24px;"><br/></span> </div> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-size: 18px;"><span style="font-family: "Microsoft YaHei";">PS:</span><span style="font-family: "Microsoft YaHei"; line-height: 26px;">经过 </span><a target="_blank" href="http://undefined" style="text-decoration-line: none; color: rgb(12, 137, 207); font-family: "Microsoft YaHei"; line-height: 26px;">hellofuturecyj</a><span style="font-family: "Microsoft YaHei"; line-height: 26px;"> 同学提醒,如果配置环境变量那步配置准确,且配置之后经过重启,就没有进行这步配置的必要了。即做完上面第五步的配置,重启一次,就可以直接跳到第七步,进行测试,看出不出图。</span></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; line-height: 26px;"><span style="font-size: 18px;">当然,如果需不重启而马上来看配置的结果,就可以试试这里的方式。</span></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="color: rgb(204, 0, 0); font-family: "Microsoft YaHei"; font-size: 14px;"><span style="white-space: pre;"> </span>——————浅墨 2014年6月16日注</span><br/> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px; line-height: 26px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">这一步是各种介绍OpenCV的配置的相关博文中都没写出来的。根据这些博文配置出来的环境,在运行基于OpenCV的程序的时候,往往会得到这样类似的结果:</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> <img src="http://img.blog.csdn.net/20140224105111687?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"></p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-size: 14px;"><span style="font-family: "Microsoft YaHei";">这种问题最简单粗暴的方法,是把相关的dll都拷贝到Windows操作系统的目录下。如果你的Windows安装在C盘,那么路径就是</span><span style="font-size: 16px; line-height: 27.1875px;"><span style="font-family: "Microsoft YaHei";">c:\Windows\System32</span></span><span style="font-family: "Microsoft YaHei";">。按照之前我的OpenCV的存放环境,这些dll存放在</span></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">D:\Program Files\opencv\build\x86\vc10\bin目录下。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><img src="http://img.blog.csdn.net/20140224105135953?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcG9lbV9xaWFubW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" style="border: none; max-width: 100%; max-height: 100%;"/><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"></p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-size: 14px;"><span style="font-family: "Microsoft YaHei";">到这个目录下,【Alt+A】全选,【Alt+C】拷贝,然后转到</span><span style="font-size: 16px; line-height: 27.1875px;"><span style="font-family: "Microsoft YaHei";">c:\Windows\System32</span></span><span style="font-family: "Microsoft YaHei";">下面,【Alt+V】复制,简单粗暴地就完成了。</span></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei";"><span style="font-size: 14px;">PS:对于Windows 8,则要放在要在SysWOW64文件夹中。</span></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> </span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> </span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">恩,环境配置大功告成,我们来测试一下成果吧~</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"><br/></span> </p> <h2 style="margin: 0px; padding: 0px;"> <a target="_blank" style="color: rgb(12, 137, 207);" href="http://undefined"></a><span style="font-family: "Microsoft YaHei"; font-size: 32px; color: rgb(102, 51, 102); font-weight: normal;">7.最终的测试</span> </h2> <div> <span style="font-family: "Microsoft YaHei"; font-size: 32px; color: rgb(102, 51, 102);"><br/></span> </div> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"> </span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">就用载入并显示一张图片到窗口的程序,用于我们的配置测试吧。</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;">新建一个空项目的控制台应用程序,新建一个cpp文件,然后粘贴如下代码:</span> </p> <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px;"> <span style="font-family: "Microsoft YaHei"; font-size: 14px;"></span> </p> <div class="dp-highlighter bg_cpp" style="font-family: Consolas, "Courier New", Courier, mono, serif; font-size: 12px; background-color: rgb(231, 229, 220); width: 885.057px; overflow: hidden; padding-top: 1px; position: relative; border-color: rgb(204, 204, 204); margin: 18px 0px !important;"> <div class="bar" style="padding-left: 45px;"> <div class="tools" style="padding: 3px 8px 10px 10px; font-stretch: normal; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left: 3px solid rgb(108, 226, 108); border-right: 1px solid rgb(231, 229, 220);"> <strong>[cpp]</strong> <a href="http://undefined" class="ViewSource" title="view plain" target="_blank" style="text-decoration-line: none; background-image: url("images/default/ico_plain.gif"); background-position: left top; background-size: initial; background-repeat: no-repeat; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; color: rgb(12, 137, 207); display: inline-block; width: 16px; height: 16px; text-indent: -2000px;">view plain</a><span> <a href="http://undefined" class="CopyToClipboard" title="copy" target="_blank" style="text-decoration-line: none; background-image: url("images/default/ico_copy.gif"); background-position: left top; background-size: initial; background-repeat: no-repeat; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; color: rgb(12, 137, 207); display: inline-block; width: 16px; height: 16px; text-indent: -2000px;">copy</a> <div style="position: absolute; left: 796px; top: 20813px; width: 18px; height: 18px; z-index: 99;"></div></span><span></span> </div> </div> <ol class="dp-cpp" style="padding: 0px; border-top: none; border-right: 1px solid rgb(231, 229, 220); border-bottom: none; border-left: none; border-image: initial; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;"> <li class="alt" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include<iostream></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span> </li> <li class="" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; background-color: rgb(248, 248, 248); line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include <opencv2/core/core.hpp></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span> </li> <li class="alt" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include <opencv2/highgui/highgui.hpp></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span> </li> <li class="" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; background-color: rgb(248, 248, 248); line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span> </li> <li class="alt" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span> </li> <li class="" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; background-color: rgb(248, 248, 248); line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 102, 153); background-color: inherit; font-weight: bold;">using</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 102, 153); background-color: inherit; font-weight: bold;">namespace</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> cv; </span></span> </li> <li class="alt" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span> </li> <li class="" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; background-color: rgb(248, 248, 248); line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span> </li> <li class="alt" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> main() </span></span> </li> <li class="" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; background-color: rgb(248, 248, 248); line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{ </span> </li> <li class="alt" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">// 读入一张图片(游戏原画)</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span> </li> <li class="" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; background-color: rgb(248, 248, 248); line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> Mat img=imread(<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"pic.jpg"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">); </span></span> </li> <li class="alt" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">// 创建一个名为 "游戏原画"窗口</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span> </li> <li class="" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; background-color: rgb(248, 248, 248); line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> namedWindow(<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"游戏原画"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">); </span></span> </li> <li class="alt" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">// 在窗口中显示游戏原画</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span> </li> <li class="" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; background-color: rgb(248, 248, 248); line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> imshow(<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"游戏原画"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">,img); </span></span> </li> <li class="alt" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">// 等待6000 ms后窗口自动关闭</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span> </li> <li class="" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; background-color: rgb(248, 248, 248); line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> waitKey(6000); </span> </li> <li class="alt" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgb(108, 226, 108); border-image: initial; list-style-type: decimal-leading-zero; list-style-image: initial; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; list-style-position: outside !important;"> <span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span> </li> </ol> </div><br/>
<br/>
原文文章出自博悦平台 www.hongshulin001.com) 转载请注明出处