使用Opencv进行图像特征点检查与匹配
来源:互联网 发布:同花顺最新软件下载 编辑:程序博客网 时间:2024/05/06 10:53
参考了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);//显示的标题为MatcheswaitKey(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);//显示的标题为MatcheswaitKey(6000);}
main:
int main(){string file1 = "test.png";string file2 = "test_t.png";Sift(file1,file2);Surf(file1,file2);return 0;}
0 0
- 使用Opencv进行图像特征点检查与匹配
- 【OpenCV】SIFT特征检测器进行图像匹配
- opencv源码解析之(3):特征点检查前言1
- opencv源码解析之(3):特征点检查前言1
- OpenCV--特征点检测与图像匹配
- OpenCV:特征点检测与图像匹配
- OpenCV: 特征点检测与图像匹配
- OpenCV 特征点检测与图像匹配
- OpenCV:特征点检测与图像匹配
- OpenCV -- 特征点检测与图像匹配
- 使用SiftGPU对两幅图像进行特征点匹配
- OpenCV学习笔记__使用FLANN进行特征点匹配
- 图像局部特征点检测算子综述
- 利用OpenCV进行图像匹配
- 图像特征提取与匹配
- 图像特征与匹配方法
- opencv特征检测与匹配
- ASIFT+OpenCV图像特征匹配实战
- 280行代码:Javascript 写的2048游戏
- 仿搜索自动联想功能
- 共享栈的实现(C++版)
- IOS_OC_基础语法
- CCEGLViewProtocol(窗口协议 各个平台会继承这个类重写一个子类来具体实现窗口创建)
- 使用Opencv进行图像特征点检查与匹配
- snprintf、stringstream、strstream的对比分析
- phonegap获取本地内网(路由器分配的)IP地址(IPV4)
- Tornado入门教程
- git中文文件名、目录名乱码应该怎么解决?(已解决)
- CF#247(Div. 2)部分题解
- 浏览器缓存机制浅析(三)
- bootstrap
- HttpServlet.init 的两种版本