使用Opencv进行图像特征点检查与匹配
2014-05-22 10:23
603 查看
参考了http://www.cnblogs.com/tornadomeet/archive/2012/03/08/2384843.html
因为使用的OpenCV2.4.9,所以有些头文件不对。
SiftFeatureDetector,SiftDescriptorExtractor,SurfFeatureDetector,SurfDescriptorExtractor这四个类应该是在<opencv2/nonfree/features2d.hpp>中,BruteForceMatcher应该是在<opencv2/legacy/legacy.hpp>
头文件:
#include<iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <vector>
#include <opencv2/legacy/legacy.hpp>
using namespace cv;
using namespace std;
Sift特征检测与匹配:
int Sift(const string &file1,const string &file2)
{
Mat img1 = imread(file1,CV_LOAD_IMAGE_GRAYSCALE);
Mat img2 = imread(file2,CV_LOAD_IMAGE_GRAYSCALE);
if(!img1.data || !img2.data)
{
cout<<"opencv error"<<endl;
return -1;
}
cout <<"Open pictures successfully"<<endl;
SiftFeatureDetector detector;
vector<KeyPoint> keyPoints_1,keyPoints_2;
detector.detect(img1,keyPoints_1);
detector.detect(img2,keyPoints_2);
Mat img_keypoints_1,img_keypoints_2;
drawKeypoints(img1,keyPoints_1,img_keypoints_1,Scalar::all(-1),DrawMatchesFlags::DEFAULT);
drawKeypoints(img2,keyPoints_2,img_keypoints_2,Scalar::all(-1),DrawMatchesFlags::DEFAULT);
cvNamedWindow("sift_keypoints_1");
cvNamedWindow("sift_keypoints_2");
imshow("sift_keypoints_1",img_keypoints_1);//显示特征点
imshow("sift_keypoints_2",img_keypoints_2);
SiftDescriptorExtractor extractor;//定义描述子对象
Mat descriptors_1,descriptors_2;//存放特征向量的矩阵
extractor.compute(img1,keyPoints_1,descriptors_1);//计算特征向量
extractor.compute(img2,keyPoints_2,descriptors_2);
//用burte force进行匹配特征向量
BruteForceMatcher<L2<float>> matcher;//定义一个burte force matcher对象
vector<DMatch>matches;
matcher.match(descriptors_1,descriptors_2,matches);
//绘制匹配线段
Mat img_matches;
drawMatches(img1,keyPoints_1,img2,keyPoints_2,matches,img_matches);//将匹配出来的结果放入内存img_matches中
//显示匹配线段
cvNamedWindow("sift_Matches");
imshow("sift_Matches",img_matches);//显示的标题为Matches
waitKey(6000);
}Surf 特征检测与匹配:
int Surf(const string &file1,const string &file2)
{
Mat img1 = imread(file1,CV_LOAD_IMAGE_GRAYSCALE);
Mat img2 = imread(file2,CV_LOAD_IMAGE_GRAYSCALE);
if(!img1.data || !img2.data)
{
cout<<"opencv error"<<endl;
return -1;
}
cout <<"Open pictures successfully"<<endl;
SurfFeatureDetector detector;
vector<KeyPoint> keyPoints_1,keyPoints_2;
detector.detect(img1,keyPoints_1);
detector.detect(img2,keyPoints_2);
Mat img_keypoints_1,img_keypoints_2;
drawKeypoints(img1,keyPoints_1,img_keypoints_1,Scalar::all(-1),DrawMatchesFlags::DEFAULT);
drawKeypoints(img2,keyPoints_2,img_keypoints_2,Scalar::all(-1),DrawMatchesFlags::DEFAULT);
cvNamedWindow("surf_keypoints_1");
cvNamedWindow("surf_keypoints_2");
imshow("surf_keypoints_1",img_keypoints_1);//显示特征点
imshow("surf_keypoints_2",img_keypoints_2);
SurfDescriptorExtractor extractor;//定义描述子对象
Mat descriptors_1,descriptors_2;//存放特征向量的矩阵
extractor.compute(img1,keyPoints_1,descriptors_1);//计算特征向量
extractor.compute(img2,keyPoints_2,descriptors_2);
//用burte force进行匹配特征向量
BruteForceMatcher<L2<float>> matcher;//定义一个burte force matcher对象
vector<DMatch>matches;
matcher.match(descriptors_1,descriptors_2,matches);
//绘制匹配线段
Mat img_matches;
drawMatches(img1,keyPoints_1,img2,keyPoints_2,matches,img_matches);//将匹配出来的结果放入内存img_matches中
//显示匹配线段
cvNamedWindow("surf_Matches");
imshow("surf_Matches",img_matches);//显示的标题为Matches
waitKey(6000);
}
main:
int main()
{
string file1 = "test.png";
string file2 = "test_t.png";
Sift(file1,file2);
Surf(file1,file2);
return 0;
}
因为使用的OpenCV2.4.9,所以有些头文件不对。
SiftFeatureDetector,SiftDescriptorExtractor,SurfFeatureDetector,SurfDescriptorExtractor这四个类应该是在<opencv2/nonfree/features2d.hpp>中,BruteForceMatcher应该是在<opencv2/legacy/legacy.hpp>
头文件:
#include<iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <vector>
#include <opencv2/legacy/legacy.hpp>
using namespace cv;
using namespace std;
Sift特征检测与匹配:
int Sift(const string &file1,const string &file2)
{
Mat img1 = imread(file1,CV_LOAD_IMAGE_GRAYSCALE);
Mat img2 = imread(file2,CV_LOAD_IMAGE_GRAYSCALE);
if(!img1.data || !img2.data)
{
cout<<"opencv error"<<endl;
return -1;
}
cout <<"Open pictures successfully"<<endl;
SiftFeatureDetector detector;
vector<KeyPoint> keyPoints_1,keyPoints_2;
detector.detect(img1,keyPoints_1);
detector.detect(img2,keyPoints_2);
Mat img_keypoints_1,img_keypoints_2;
drawKeypoints(img1,keyPoints_1,img_keypoints_1,Scalar::all(-1),DrawMatchesFlags::DEFAULT);
drawKeypoints(img2,keyPoints_2,img_keypoints_2,Scalar::all(-1),DrawMatchesFlags::DEFAULT);
cvNamedWindow("sift_keypoints_1");
cvNamedWindow("sift_keypoints_2");
imshow("sift_keypoints_1",img_keypoints_1);//显示特征点
imshow("sift_keypoints_2",img_keypoints_2);
SiftDescriptorExtractor extractor;//定义描述子对象
Mat descriptors_1,descriptors_2;//存放特征向量的矩阵
extractor.compute(img1,keyPoints_1,descriptors_1);//计算特征向量
extractor.compute(img2,keyPoints_2,descriptors_2);
//用burte force进行匹配特征向量
BruteForceMatcher<L2<float>> matcher;//定义一个burte force matcher对象
vector<DMatch>matches;
matcher.match(descriptors_1,descriptors_2,matches);
//绘制匹配线段
Mat img_matches;
drawMatches(img1,keyPoints_1,img2,keyPoints_2,matches,img_matches);//将匹配出来的结果放入内存img_matches中
//显示匹配线段
cvNamedWindow("sift_Matches");
imshow("sift_Matches",img_matches);//显示的标题为Matches
waitKey(6000);
}Surf 特征检测与匹配:
int Surf(const string &file1,const string &file2)
{
Mat img1 = imread(file1,CV_LOAD_IMAGE_GRAYSCALE);
Mat img2 = imread(file2,CV_LOAD_IMAGE_GRAYSCALE);
if(!img1.data || !img2.data)
{
cout<<"opencv error"<<endl;
return -1;
}
cout <<"Open pictures successfully"<<endl;
SurfFeatureDetector detector;
vector<KeyPoint> keyPoints_1,keyPoints_2;
detector.detect(img1,keyPoints_1);
detector.detect(img2,keyPoints_2);
Mat img_keypoints_1,img_keypoints_2;
drawKeypoints(img1,keyPoints_1,img_keypoints_1,Scalar::all(-1),DrawMatchesFlags::DEFAULT);
drawKeypoints(img2,keyPoints_2,img_keypoints_2,Scalar::all(-1),DrawMatchesFlags::DEFAULT);
cvNamedWindow("surf_keypoints_1");
cvNamedWindow("surf_keypoints_2");
imshow("surf_keypoints_1",img_keypoints_1);//显示特征点
imshow("surf_keypoints_2",img_keypoints_2);
SurfDescriptorExtractor extractor;//定义描述子对象
Mat descriptors_1,descriptors_2;//存放特征向量的矩阵
extractor.compute(img1,keyPoints_1,descriptors_1);//计算特征向量
extractor.compute(img2,keyPoints_2,descriptors_2);
//用burte force进行匹配特征向量
BruteForceMatcher<L2<float>> matcher;//定义一个burte force matcher对象
vector<DMatch>matches;
matcher.match(descriptors_1,descriptors_2,matches);
//绘制匹配线段
Mat img_matches;
drawMatches(img1,keyPoints_1,img2,keyPoints_2,matches,img_matches);//将匹配出来的结果放入内存img_matches中
//显示匹配线段
cvNamedWindow("surf_Matches");
imshow("surf_Matches",img_matches);//显示的标题为Matches
waitKey(6000);
}
main:
int main()
{
string file1 = "test.png";
string file2 = "test_t.png";
Sift(file1,file2);
Surf(file1,file2);
return 0;
}
相关文章推荐
- Feature Matching by using opencv(Python)-使用opencv进行图像特征匹配
- 在android 上,使用Opencv3.0实现图像无缝拼接,Fast查找特征点,BruteForce进行匹配
- opencv3中使用FLANN进行特征点匹配
- OpenCV使用FLANN进行特征点匹配
- Opencv实现图像无缝拼接,Sift查找特征点,Flann进行匹配
- OpenCV学习笔记__使用FLANN进行特征点匹配
- Opencv实现图像无缝拼接,Sift查找特征点,Flann进行匹配
- 使用Opencv2.4.9进行SIFT特征点提取和匹配
- 使用OpenCV3进行SURF特征提取和暴力匹配代码详解
- 使用SiftGPU对两幅图像进行特征点匹配
- OpenCV之feature2d 模块. 2D特征框架(2)特征描述 使用FLANN进行特征点匹配 使用二维特征点(Features2D)和单映射(Homography)寻找已知物体 平面物体检测
- OpenCV: Features2D Features FrameWork 图像二维特征检测、描述以及匹配框架的层次解析
- OpenCV--特征点检测与图像匹配
- 使用EMGU.CV对图像进行SIFT和SURF特征提取
- 如何使用GIST+LIBLINEAR分类器提取CIFAR-10 dataset数据集中图像特征,并用测试数据进行实验
- OpenCV学习笔记(8)VS2008 MFC下使用OpenCV2.0进行简单图像处理
- OpenCV_局部图像特征的提取与匹配_源代码
- OpenCV成长之路:特征点检测与图像匹配
- opencv2中使用Mat对图像像素进行操作
- OpenCV2.4.4中调用SIFT特征检测器进行图像匹配