opencv中模板匹配算法的由来
OPENCV下利用SIFT库进行图像匹配的例程
// opencv_empty_proj.cpp:定义控制台应用程序的入口点。
//
#包含" stdafx.h "
# include & ltopencv 2/opencv . HPP & gt;
# include & ltopencv 2/features 2d/features 2d . HPP & gt;
# include & ltopen cv2/non free/non free . HPP & gt;
# include & ltopencv 2/legacy/legacy . HPP & gt;
# include & ltvector & gt
使用命名空间std
使用名称空间cv;
int _tmain(int argc,_TCHAR* argv[])
{
const char * imagename = " img.jpg
//从文件中读取图像
mat img = im read(imagename);
mat img 2 = im read(" img 2 . jpg ");
//如果读取图像失败,
if(img.empty())
{
fprintf(stderr,"无法加载图像%s\n ",imagename);
return-1;
}
if(img2.empty())
{
fprintf(stderr,"无法加载图像%s\n ",imagename);
return-1;
}
//显示图像
imshow(“前像”,img);
imshow("image2 before ",img 2);
//sift特征检测
SiftFeatureDetector
向量& lt重要提示& gtkp1,kp2
siftdtc.detect(img,KP 1);
mat outimg 1;
drawKeypoints(img,kp1,outimg 1);
imshow("image1 keypoints ",outimg 1);
关键点KP;
向量& lt重要提示& gt迭代程序itvc
for(itvc = KP 1 . begin();itvc!= KP 1 . end();itvc++)
{
cout & lt& lt"角度:" & lt& ltitvc-& gt;角度& lt& lt" \ t " & lt& ltitvc-& gt;class _ id & lt& lt" \ t " & lt& ltitvc-& gt;octave & lt& lt" \ t " & lt& ltitvc-& gt;pt & lt& lt" \ t " & lt& ltitvc-& gt;响应& lt& ltendl
}
siftdtc.detect(img2,kp2);
Mat outimg2
绘制关键点(img2、kp2、outi mg 2);
imshow("图像2关键点",outi mg 2);
提取器;
Mat descriptor1,descriptor2
BruteForceMatcher & ltL2<float & gt& gtmatcher
向量& ltDMatch & gt火柴;
Mat img _ matches
extractor.compute(img,kp1,descriptor 1);
extractor.compute(img2,kp2,descriptor 2);
imshow("desc ",descriptor 1);
cout & lt& ltendl & lt& ltdescriptor 1 & lt;& ltendl
matcher.match(描述符1,描述符2,matches);
drawMatches(img,kp1,img2,kp2,Matches,img _ matches);
imshow("matches ",img _ matches);
//这个函数等待键,然后按键盘上的任意键返回。
wait key();
返回0;
}