• OpenCV头文件包含问题


         opencv从2.2版本以后<opencv root>include下有两个文件夹 opencv 和opencv2。从官方的意思来看,它逐渐喜欢用opencv2里面的那种包含头文件的方式。

    注意:<opencv root>是opencv2.2安装路径。每个人的路径都可能有所不同!!

    Opencv.hpp本身是一个头文件,它包含了opencv全部的头文件。有图有真相:

    #ifndef __OPENCV_ALL_HPP__  
      
    #define __OPENCV_ALL_HPP__  
      
    #include "opencv2/core/core_c.h"  
      
    #include "opencv2/core/core.hpp"  
      
    #include "opencv2/flann/flann.hpp"  
      
    #include "opencv2/imgproc/imgproc_c.h"  
      
    #include "opencv2/imgproc/imgproc.hpp"  
      
    #include "opencv2/video/tracking.hpp"  
      
    #include "opencv2/video/background_segm.hpp"  
      
    #include "opencv2/features2d/features2d.hpp"  
      
    #include "opencv2/objdetect/objdetect.hpp"  
      
    #include "opencv2/calib3d/calib3d.hpp"  
      
    #include "opencv2/ml/ml.hpp"  
      
    #include "opencv2/highgui/highgui_c.h"  
      
    #include "opencv2/highgui/highgui.hpp"  
      
    #include "opencv2/contrib/contrib.hpp"  
      
    #endif  

        每次下载opencv的新版本时,都需要重新写头文件,更改链接库配置,很麻烦有木有?下面这个头文件是我在别人的代码中淘出来的,很不错,与大家分享~(具体作者忘记了,不好意思啊)

      作者很巧妙地利用Opencv的版本信息定义了一个宏,无论你的Opencv是243还是246都能够完美支持,以后再不用担心更新版本带来的问题了,另:对于比较老的Opencv版本可能有个别lib的名称不对,修改一下就可以了

    #pragma once
    
    #include "targetver.h"
    
    #include <stdio.h>
    #include <tchar.h>
    #include <iostream>
    #include <fstream>
    
    #include <opencv2/opencv.hpp>
    
    #define CV_VERSION_ID       CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) CVAUX_STR(CV_SUBMINOR_VERSION)
    
    #ifdef _DEBUG
    #define cvLIB(name) "opencv_" name CV_VERSION_ID "d"
    #else
    #define cvLIB(name) "opencv_" name CV_VERSION_ID
    #endif
    
    #pragma comment( lib, cvLIB("core") )
    #pragma comment( lib, cvLIB("imgproc") )
    #pragma comment( lib, cvLIB("highgui") )
    #pragma comment( lib, cvLIB("flann") )
    #pragma comment( lib, cvLIB("features2d") )
    #pragma comment( lib, cvLIB("calib3d") )
    #pragma comment( lib, cvLIB("gpu") )
    #pragma comment( lib, cvLIB("legacy") )
    #pragma comment( lib, cvLIB("ml") )
    #pragma comment( lib, cvLIB("objdetect") )
    #pragma comment( lib, cvLIB("ts") )
    #pragma comment( lib, cvLIB("video") )
    #pragma comment( lib, cvLIB("contrib") )
    #pragma comment( lib, cvLIB("nonfree") )

    version.hpp库自带的:

    #ifndef __OPENCV_VERSION_HPP__
    #define __OPENCV_VERSION_HPP__
    
    #define CV_VERSION_MAJOR    3
    #define CV_VERSION_MINOR    1
    #define CV_VERSION_REVISION 0
    #define CV_VERSION_STATUS   ""
    
    #define CVAUX_STR_EXP(__A)  #__A
    #define CVAUX_STR(__A)      CVAUX_STR_EXP(__A)
    
    #define CVAUX_STRW_EXP(__A)  L#__A
    #define CVAUX_STRW(__A)      CVAUX_STRW_EXP(__A)
    
    #define CV_VERSION          CVAUX_STR(CV_VERSION_MAJOR) "." CVAUX_STR(CV_VERSION_MINOR) "." CVAUX_STR(CV_VERSION_REVISION) CV_VERSION_STATUS
    
    /* old  style version constants*/
    #define CV_MAJOR_VERSION    CV_VERSION_MAJOR
    #define CV_MINOR_VERSION    CV_VERSION_MINOR
    #define CV_SUBMINOR_VERSION CV_VERSION_REVISION
    
    #endif
  • 相关阅读:
    asp.net textbox控件readonly为true时,后台取值的问题
    未能加载文件或程序集“ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73”或它的某一个依赖项
    DataSet与DataReader的比较
    EntityFramwork所有 SSDL 项目都必须以同一提供程序为目标。ProviderManifestToken“2008”不同于以前遇到的“2005”
    路由器wan口连接不上的问题
    Git学习(四)----版本号跳转
    jquery记分牌的插件
    ORACLE 第4节 多表查询
    基于消息机制的异步架构之回调函数注冊
    干货!手把手教你怎样高速了解一个行业--游戏产业概况
  • 原文地址:https://www.cnblogs.com/ranjiewen/p/6063994.html
Copyright © 2020-2023  润新知