码迷,mamicode.com
首页 > 其他好文 > 详细

VS2013下配置OpenCV 3.0.0

时间:2015-10-13 10:42:23      阅读:754      评论:0      收藏:0      [点我收藏+]

标签:

最近做图像需要用到Matlab和OpenCV,一些东西真的是要深入的研究进去才会有所发现,但Matlab和C++都不是我擅长的语言,所以要很加油很加油才行啊!!

步入正题。

   1.  环境:Win7 64位 + Visual Studio 2013 Community + OpenCV 3.0.0

   2. 安装VS 2013 Community版本。 —— 到VS官网https://www.visualstudio.com/zh-cn/downloads/download-visual-studio-vs.aspx选择对应版本下载,记住要下载ISO不要下载web版本哦。

   3. 到OPenCV官网http://opencv.org/下载Windows版本的OpenCV 3.0.0版,然后解压到相应文件夹,如我的是“C:\Park_Software\opencv”。

   4. 配置电脑的环境变量。在“计算机”下右键,然后“属性”-》“高级系统设置”-》(注意:更改的是系统变量)“环境变量”-》“新建”-》“变量名:OPENCV; 变量值:C:\Park_Software\opencv\build”; -》找到“PATH”-》“编辑”-》加入“;%OPENCV%\x86\vc12\bin”.

   5. 找到解压后的OpenCV文件夹,然后进入根目录,新建文件opencv300.props,写入如下代码:(这些代码是方便配置VS中的信息,每次新建Project时,只需将该文件加载进去即可,不必再繁琐的设置一些属性表)

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup>
    <IncludePath>$(OPENCV)\include;$(IncludePath)</IncludePath>
    <LibraryPath Condition="‘$(Platform)‘==‘Win32‘">$(OPENCV)\x86\vc12\staticlib;$(OPENCV)\x86\vc12\lib;$(LibraryPath)</LibraryPath>
    <LibraryPath Condition="‘$(Platform)‘==‘X64‘">$(OPENCV)\x64\vc12\staticlib;$(OPENCV)\x64\vc12\lib;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <Link Condition="‘$(Configuration)‘==‘Debug‘">
      <AdditionalDependencies>opencv_ts300.lib;opencv_world300.lib;opencv_calib3d300.lib;opencv_core300.lib;opencv_features2d300.lib;opencv_flann300.lib;opencv_highgui300.lib;opencv_imgcodecs300.lib;opencv_imgproc300.lib;opencv_ml300.lib;opencv_objdetect300.lib;opencv_photo300.lib;opencv_shape300.lib;opencv_stitching300.lib;opencv_superres300.lib;opencv_ts300.lib;opencv_video300.lib;opencv_videoio300.lib;opencv_videostab300.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
    <Link Condition="‘$(Configuration)‘==‘Release‘">
      <AdditionalDependencies>opencv_ts300d.lib;opencv_world300d.lib;opencv_calib3d300d.lib;opencv_core300d.lib;opencv_features2d300d.lib;opencv_flann300d.lib;opencv_highgui300d.lib;opencv_imgcodecs300d.lib;opencv_imgproc300d.lib;opencv_ml300d.lib;opencv_objdetect300d.lib;opencv_photo300d.lib;opencv_shape300d.lib;opencv_stitching300d.lib;opencv_superres300d.lib;opencv_ts300d.lib;opencv_video300d.lib;opencv_videoio300d.lib;opencv_videostab300d.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

   6. 下面开始对VS中的项目进行配置。

   7. 新建一个空的Visual C++控制台程序,然后在“属性管理器”窗口下(如没有属性管理器窗口,则应该到“视图”-》“其他窗口”-》“属性管理器”)右键刚刚建立的项目,然后“添加现有属性表”,找到刚刚写好的“opencv300.props”加入即可。

   8. 下面开始写读取图像的一个小程序。在源文件中新建一个.cpp文件,写入以下代码:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{    


    Mat image;
    image = imread("G:\\1.jpg", IMREAD_COLOR); // Read the file(your own image route)

    if (!image.data) // Check for invalid input
    {
        cout << "Could not open or find the image" << std::endl;
        return -1;
    }

    namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
    imshow("Display window", image); // Show our image inside it.

    waitKey(0); // Wait for a keystroke in the window
    return 0;
}

   9. 本地Windows调试器,然后编译运行即可。

 

VS2013下配置OpenCV 3.0.0

标签:

原文地址:http://www.cnblogs.com/little-YTMM/p/4873659.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!