win7平台下vs2013配置opencv3.0

  • 下载opencv3.0 for Windows 本人下载的是verison 3.0
  • 配置环境变量

系统环境变量里面新建变量,名为 OPENCV,值为自己解压OpenCV的路径下的bulid路径,如 E:\opencv_install\OpenCV\build

无论是32bit还是64bit的PC,都在 path变量后面添加 ;%OPENCV%\x86\vc12\bin

  • 重启计算机,保证环境变量生效
  • 编写OpenCV的VS工程容量属性表

在OpenCV的根目录,如E:\opencv_install\opencv,下新建属性表文件opencv300.props,其文件内容如下:
<?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\lib;;$(OPENCV)\x86\vc12\staticlib;$(LibraryPath)</LibraryPath>
    <LibraryPath Condition="'$(Platform)'=='X64'">$(OPENCV)\x64\vc12\staticlib;$(OPENCV)\x64\vc12\lib;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <Link Condition="'$(Configuration)'=='Debug'">
<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_video300d.lib;opencv_videoio300d.lib;opencv_videostab300d.lib;
%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
    <Link Condition="'$(Configuration)'=='Release'">
<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>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>
注意,网上下载的很多属性表文件opencv300.props,其文件内容不全,导致编译的时候出现这样那样的错误,一般错误集中在lib库的连接上面,所以,若是出现lib库连接错误,检查要么是你的工程lib文件名称是否正确,要么是这个属性表文件opencv300.props的内容是否全面。网上的这个属性表文件opencv300.props的内容遗漏最常出现在 LibraryPath Condition的位置。这份属性表为opencv3.0的VS2013 工程属性表,兼容64位和32位平台,兼容Debug和Release配置。详细解释看后文,后面在VS工程中配置Opencv只需要导入这份属性表就可以了。

  • 导入工程
属性管理器 --> 工程名处 右键 --> 添加现有属性表
  • 测试
#include <opencv2\opencv.hpp>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
int main()
{
        Mat img = imread("**.jpg");
        if (img.empty())
        {
                cout << "error";
                return -1;
        }
        imshow("**", img);
        waitKey();

        return 0;
}

配置结束


你可能感兴趣的:(win7,opencv,VS2013)