zoukankan      html  css  js  c++  java
  • VC2010 OPENCV 配置攻略;生成opencv向导

    VC中新建项目

    opencv安装目录 D:\opencv\opencv\

    include

    D:\opencv\opencv\build\include\opencv;D:\opencv\opencv\build\include\opencv2;D:\opencv\opencv\build\include;$(IncludePath)

    库目录

    D:\opencv\opencv\build\x86\vc10\bin;C:\Program Files\Microsoft Visual Studio 10.0\VC\lib;C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib;$(LibraryPath)

    链接 - 输入

    opencv_core240d.lib;opencv_features2d240d.lib;opencv_flann240d.lib;opencv_gpu240d.lib;opencv_highgui240d.lib;opencv_imgproc240d.lib;opencv_legacy240d.lib;opencv_ml240d.lib;opencv_objdetect240d.lib;opencv_ts240d.lib;opencv_video240d.lib;kernel32.lib;%(AdditionalDependencies)

    项目可以正常编译

    一劳永逸的项目产生办法

    新建常规-自定义向导 产生一个模板文件

    cvDemo

    路径为 C:\Users\username \Documents\Visual Studio 2010\Projects\cvDemo

    C:\Users\username \Documents\Visual Studio 2010\Projects\cvDemo\cvDemo\default.vcxproj

    打开编辑如下

    View Code
      1 <?xml version="1.0" encoding="utf-8"?>
      2 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      3 
      4   <ItemGroup Label="ProjectConfigurations">
      5     <ProjectConfiguration Include="Debug|Win32">
      6       <Configuration>Debug</Configuration>
      7       <Platform>Win32</Platform>
      8     </ProjectConfiguration>
      9     <ProjectConfiguration Include="Release|Win32">
     10       <Configuration>Release</Configuration>
     11       <Platform>Win32</Platform>
     12     </ProjectConfiguration>
     13   </ItemGroup>
     14 
     15   <PropertyGroup Label="Globals">
     16   </PropertyGroup>
     17 
     18   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
     19 
     20    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     21       <ConfigurationType>Application</ConfigurationType>
     22     <UseDebugLibraries>true</UseDebugLibraries>
     23     <CharacterSet>Unicode</CharacterSet>
     24   </PropertyGroup>
     25   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     26       <ConfigurationType>Application</ConfigurationType>
     27     <UseDebugLibraries>true</UseDebugLibraries>
     28     <CharacterSet>Unicode</CharacterSet>
     29   </PropertyGroup>
     30 
     31   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
     32 
     33   <ImportGroup Label="ExtensionSettings">
     34   </ImportGroup>
     35 
     36   <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     37     <Import Project="$(LocalAppData)\Microsoft\VisualStudio\10.0\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(LocalAppData)\Microsoft\VisualStudio\10.0\Microsoft.Cpp.$(Platform).user.props')" />
     38   </ImportGroup>
     39   <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     40     <Import Project="$(LocalAppData)\Microsoft\VisualStudio\10.0\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(LocalAppData)\Microsoft\VisualStudio\10.0\Microsoft.Cpp.$(Platform).user.props')" />
     41   </ImportGroup>
     42 
     43   <PropertyGroup Label="UserMacros" />
     44   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     45     <LinkIncremental>true</LinkIncremental>
     46     <SourcePath>$(SourcePath)</SourcePath>
     47     <IncludePath>D:\opencv\opencv\build\include\opencv;D:\opencv\opencv\build\include\opencv2;D:\opencv\opencv\build\include;$(IncludePath)</IncludePath>
     48     <LibraryPath>D:\opencv\opencv\build\x86\vc10\bin;C:\Program Files\Microsoft Visual Studio 10.0\VC\lib;C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib;$(LibraryPath)</LibraryPath>
     49     <ReferencePath>$(ReferencePath)</ReferencePath>
     50   </PropertyGroup>
     51   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     52     <LinkIncremental>false</LinkIncremental>
     53   </PropertyGroup>
     54 
     55  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     56     <ClCompile>
     57       <PrecompiledHeader>Use</PrecompiledHeader>
     58       <WarningLevel>Level3</WarningLevel>
     59       <Optimization>Disabled</Optimization>
     60       <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     61     </ClCompile>
     62     <Link>
     63       <SubSystem>Console</SubSystem>
     64       <GenerateDebugInformation>true</GenerateDebugInformation>
     65       <AdditionalDependencies>opencv_core240d.lib;opencv_features2d240d.lib;opencv_flann240d.lib;opencv_gpu240d.lib;opencv_highgui240d.lib;opencv_imgproc240d.lib;opencv_legacy240d.lib;opencv_ml240d.lib;opencv_objdetect240d.lib;opencv_ts240d.lib;opencv_video240d.lib;kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
     66       <AdditionalLibraryDirectories>D:\opencv\opencv\build\x86\vc10\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
     67     </Link>
     68   </ItemDefinitionGroup>
     69   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     70     <ClCompile>
     71       <WarningLevel>Level3</WarningLevel>
     72       <PrecompiledHeader>Use</PrecompiledHeader>
     73       <Optimization>MaxSpeed</Optimization>
     74       <FunctionLevelLinking>true</FunctionLevelLinking>
     75       <IntrinsicFunctions>true</IntrinsicFunctions>
     76       <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     77     </ClCompile>
     78      <Link>
     79       <SubSystem>Console</SubSystem>
     80       <GenerateDebugInformation>true</GenerateDebugInformation>
     81       <AdditionalDependencies>opencv_core240d.lib;opencv_features2d240d.lib;opencv_flann240d.lib;opencv_gpu240d.lib;opencv_highgui240d.lib;opencv_imgproc240d.lib;opencv_legacy240d.lib;opencv_ml240d.lib;opencv_objdetect240d.lib;opencv_ts240d.lib;opencv_video240d.lib;kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
     82       <AdditionalLibraryDirectories>D:\opencv\opencv\build\x86\vc10\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
     83     </Link>
     84   </ItemDefinitionGroup>
     85   <ItemGroup>
     86     <None Include="ReadMe.txt" />
     87   </ItemGroup>
     88   <ItemGroup>
     89     <ClInclude Include="stdafx.h" />
     90     <ClInclude Include="targetver.h" />
     91   </ItemGroup>
     92   <ItemGroup>
     93     <ClCompile Include="cvhello.cpp" />
     94     <ClCompile Include="stdafx.cpp">
     95       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
     96       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
     97     </ClCompile>
     98   </ItemGroup>
     99 
    100   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    101 
    102   <ImportGroup Label="ExtensionTargets">
    103   </ImportGroup>
    104 </Project>

    同目录下default.vcxproj.filters 文件根据网上的某些不知道有没有用

    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ItemGroup>
        <Filter Include="源文件">
          <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
          <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
        </Filter>
        <Filter Include="头文件">
          <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
          <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
        </Filter>
        <Filter Include="资源文件">
          <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
          <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
        </Filter>
      </ItemGroup>
    </Project>

    然后在项目新建时候已经选择向导,选择cvDmo模板就可以了。

    cvhellp.cpp

    #include "stdafx.h"
     
    #include <opencv2/opencv.hpp>
     
    using namespace std;
    using namespace cv;
     
    int main(int argc, char* argv[])
    {
     const char* imagename = "http://www.cnblogs.com/../lena.jpg";
     
     //从文件中读入图像
     Mat img = imread( imagename );
     
     //如果读入图像失败
     if(img.empty())
     {
      fprintf(stderr, "Can not load image %s\n", imagename);
      return -1;
     }
     
     //显示图像
     imshow("image", img);
     
     //此函数等待按键,按键盘任意键就返回
     waitKey();
     
     return 0;
    }

    转帖请注明出处 (cndavy)

  • 相关阅读:
    167. 两数之和 II
    14. 最长公共前缀
    28. 实现strStr()
    118. 杨辉三角
    54. 螺旋矩阵
    498. 对角线遍历
    66. 加一
    747. 至少是其他数字两倍的最大数
    34. 在排序数组中查找元素的第一个和最后一个位置
    164. 寻找峰值
  • 原文地址:https://www.cnblogs.com/cndavy/p/2540035.html
Copyright © 2011-2022 走看看