亲自安装opencv2.4.9(vs2012+64位操作系统)

本篇文章的参考文章:





这篇文章的重点是如何a、安装opencv2.4.9
b、重复利用debug和release的配置,从而省去每次新建工程都要配置的麻烦事
c、解决配置过程中遇到的问题(测试很简单的程序,却总是抛出异常)
 
1、下载opencv-2.4.9.exe
双击后会提示解压到某个地方,我选的地址是G:\,然后你就不用管啦,完成之后会生成如下文件夹

2、配置环境变量Path
如你的计算机为32位操作系统,那么将Path变量添加G:\opencv\build\x86\vc11\bin
如为64位操作系统那么将Path变量添加G:\opencv\build\x86\vc11\bin;G:\opencv\build\x64\vc11\bin
(注:vs2010=vc10,vs2012=vc11)

3、配置VS2012 OpenCV一次配置Debug和Release,反复使用的方法,这篇文章是通过新建属性表并配置后,将它保存下来,下次新建工程只需将这个属性表引用进来就好,如果你懒的每次新建工程都要引用这个属性表,那么你可以参考这篇文章
http://blog.csdn.net/huang9012/article/details/21811129来配置VS2012的根属性表Microsoft.Cpp.Win32.user。

4、测试配置是否成功
我的测试程序为
#include<iostream>  
#include <opencv2/core/core.hpp>  
#include <opencv2/highgui/highgui.hpp>   
using namespace cv;   
int main()  
{  
    // 读入一张图片(游戏原画)  
    Mat img=imread("1.jpg");  
    // 创建一个名为 "游戏原画"窗口  
    cvNamedWindow("游戏原画");  
    // 在窗口中显示游戏原画  
    imshow("游戏原画",img);  
    // 等待6000 ms后窗口自动关闭  
    waitKey(6000);  
}  
1 .jpg就直接复制在项目的源文件里,但去项目保存的路径里去找这个文件却又找不到,不晓得为什么鄙视鄙视
但程序运行后老是出错,老是抛出异常
Unhandled exception at at 0x7606C42D in opencvTest.exe: Microsoft C++ exception: cv::Exception at memory location 0x0042F670.
解决办法:
<span style="box-sizing: content-box; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 24px; color: rgb(255, 0, 0); background-color: rgb(245, 245, 245);">如果你的图片和生成的.exe文件放在同一目录下</span><span style="color: rgb(51, 51, 51); font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 24px; background-color: rgb(245, 245, 245);">, 那么就可以这么写</span><br style="box-sizing: content-box; color: rgb(51, 51, 51); font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 24px; background-color: rgb(245, 245, 245);" /><span style="color: rgb(51, 51, 51); font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 24px; background-color: rgb(245, 245, 245);"></span><pre name="code" class="cpp" style="color: rgb(51, 51, 51); line-height: 26px;"><pre name="code" class="cpp" style="color: rgb(51, 51, 51); line-height: 26px;">Mat img=imread("1.jpg");
 
  如果不是, 那么写图片的绝对路径 
  
Mat img=imread("C:\\Users\\Administrator\\Desktop\\1.jpg");

 
 

发布了25 篇原创文章 · 获赞 17 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/muguangzhichen/article/details/50302191