头文件
在VS2010+OpenCV2.3.1
#include "StdAfx.h"
#include "opencv2/core/core.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
//#include <opencv2/legacy/legacy.hpp>
#include <vector>
#include <iostream>
#include <fstream>
#include <math.h>
using namespace cv;
using namespace std;
void getMatchLR(string imgpath);
void getMatchDT(string imgpath);
//void getSURFFeature(string imgpath);
void getORBFeature(string imgpath);
void MatchTemplate(string imgname);
void MatchTemplateORB(string imgname);
void MatchTemplateSIFT(string imgname);
void testMatch();
static string imgdir = "E:\\input_resize\\";
static string Matchsavedir = "E:\\macth_result\\";
static string TemplateDir = "E:\\template_resize\\";
//static string ORBsavedir = "ORB_result\\";
IplImage mat_src_lpl;
IplImage OutImage_lpl;
IplImage TemplateIpl;
IplImage* dst_left;
IplImage* dst_right;
IplImage *src;
IplImage *TemplateIplPtr;
Mat mat_src;
Mat OutImage;
Mat TemplateMat;
在UBUNTU12.04UTL+opencv2.4.
#include "opencv2/core/core.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/legacy/legacy.hpp>
#include <vector>
#include <iostream>
#include <fstream>
#include <math.h>
主函数
int main()
{
string imgname = "07_in.jpg";
//testMatch();
MatchTemplateSIFT(imgname);
//getMatchLR(imgname);
return 0;
}
SIFT
利用SIFT特征进行模板匹配,template1为一个物体的小图,然后在一张含有多个同样物体的大图上进行匹配。
在大图上滑窗处理,得到每一个滑窗的特征,进行匹配,计算距离均值,作为一个灰度值,最后生成一个大图。
特征子,描述符,匹配方法分别为:
new SiftFeatureDetector
new SiftDescriptorExtractor;
BruteForceMatcher<L2(float)>
详细代码
void MatchTemplateSIFT(string imgname)
{
vector<KeyPoint> LeftKey;
vector<KeyPoint> RightKey;
Mat LeftDescriptor;
Mat RightDescriptor;
vector<DMatch> Matches;
//vector<double> me