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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM