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

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值