由于最初这个方法是用qt界面的形式呈现了,没有平常见到的main函数执行图像检索的那样,我稍微做了下整理,提供出一个c++接口interface()可供调用。注释还比较少,后面有时间补上。
#ifndef IMAGERETRIVAL
#define IMAGERETRIVAL
//#include <cxcore.h>
#include <opencv2\features2d\features2d.hpp>
#include <opencv2\calib3d\calib3d.hpp>
#include <opencv2\contrib\contrib.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include <highgui.h>
#include <iostream>
#include <map>
#include <io.h>
using namespace std ;
using namespace cv;
#define HessianThreshold 400
#define MAX_Image_Num 1000
#define MIN_Image_Similar_Threshold 0.001
struct matDescToImgfile{
int i_begin_index ;
int i_end_index ;
string s_imge_filename ;
};
const string trainFileType = "jpg"; // "*" represent any file type.
//////////////////////////////////////////////////////////////////////////
//从目录中读取文件名列表
int readDirFile(const string dirName, const string fileType , vector<string> &allFilename)
{
int fileNum = 0 ;
_finddata_t onefile ;
long lFile ;
string dirName_FileType = dirName + "\\*."+fileType;
lFile = _findfirst(dirName_FileType.c_str() , &onefile) ;
if (lFile == -1l ) //on such file, return -1l (long type)
{
cout << "can`t find the file"<<endl;
return fileNum ;
}
else
{
//cout <<"the files of the folder:"<<endl ;
do
{
//cout<<onefile.name <<endl ;
allFilename.push_back(onefile.name) ;
fileNum ++ ;