您当前的位置: 首页 >  opencv

惊鸿一博

暂无认证

  • 3浏览

    0关注

    535博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

OpenCV_ImageMatching with SURF and SIFT(使用SURF和 SIFT进行图像匹配 对比)

惊鸿一博 发布时间:2017-03-25 00:38:08 ,浏览量:3

ImageMatching with SURF :

 

// ImageMatchwithSURF.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include 
#include 
#include 
#include   //cv::BruteForceMatcher使用
int main()
{
	//获取image1特征点向量
	cv::Mat image1 = cv::imread("../../aTestImage/church01.jpg", 0);
	std::vector  keypoints1;  //特征点向量
	cv::SurfFeatureDetector surf(2500.);   //SURF特征检测器
	surf.detect(image1, keypoints1);

	//获取image2特征点向量
	cv::Mat image2 = cv::imread("../../aTestImage/church03.jpg", 0);
	std::vector  keypoints2;  //特征点向量
	//cv::SurfFeatureDetector surf(2500.);
	surf.detect(image2, keypoints2);

	//获取image1的SURF描述子
	cv::SurfDescriptorExtractor surfDesc;  //构造SURF描述子提取器
	cv::Mat descriptors1;
	surfDesc.compute(image1, keypoints1, descriptors1); //提取SURF描述子
     //获取image2的SURF描述子
	//cv::SurfDescriptorExtractor surfDesc;  //构造SURF描述子提取器
	cv::Mat descriptors2;
	surfDesc.compute(image2, keypoints2, descriptors2); //提取SURF描述子

	//进行匹配
	cv::BruteForceMatcher matcher; //构造匹配器
	std::vector  matches; //存储 匹配后的 匹配描述子
	matcher.match(descriptors1, descriptors2, matches);
	//筛选距离最近的25个匹配结果
	std::nth_element(matches.begin(), matches.begin() + 24, matches.end());  //
	matches.erase(matches.begin() + 25, matches.end()); //删除其它匹配结果

	//生成匹配图像
	cv::Mat imageMatches;
	cv::drawMatches(
		image1, keypoints1,
		image2, keypoints2,
		matches, imageMatches, cv::Scalar(255, 255, 255));

	cv::namedWindow("imageMatches");
	cv::imshow("imageMatches", imageMatches);
	cv::waitKey(0);

    return 0;
}

 

 

 

 

 

ImageMatching with SIFT:

 

// ImageMatchwithSIFT.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include 
#include 
#include 
#include   //cv::BruteForceMatcher使用
int main()
{
	//获取image1特征点向量
	cv::Mat image1 = cv::imread("../../aTestImage/church01.jpg", 0);
	使用SIFT(Scale-Invarient Feature Transform)提取特征点
	std::vector  keypoints1;  //特征点向量
	cv::SiftFeatureDetector sift(0.03, 3.);    //SIFT特征检测器 (0.03, 3.)初始化值不合适时无结果
	sift.detect(image1, keypoints1);

	//获取image2特征点向量
	cv::Mat image2 = cv::imread("../../aTestImage/church03.jpg", 0);
	std::vector  keypoints2;  //特征点向量
	cv::SiftFeatureDetector sift2(0.03, 3.);
	sift2.detect(image2, keypoints2);

	//获取image1的SIFT描述子
	cv::SiftDescriptorExtractor siftDesc;  //构造SIFT描述子提取器
	cv::Mat descriptors1;
	siftDesc.compute(image1, keypoints1, descriptors1); //提取SIFT描述子
	//获取image2的SURF描述子
	cv::SiftDescriptorExtractor siftDesc2;  //构造SIFT描述子提取器
	cv::Mat descriptors2;
	siftDesc2.compute(image2, keypoints2, descriptors2); //提取SIFT描述子

      //进行匹配
	cv::BruteForceMatcher matcher; //构造匹配器
	std::vector  matches; //存储 匹配后的 匹配描述子
	matcher.match(descriptors1, descriptors2, matches);
	//筛选距离最近的25个匹配结果
	std::nth_element(matches.begin(), matches.begin() + 34, matches.end());  //
	matches.erase(matches.begin() + 35, matches.end()); //删除其它匹配结果

	//生成匹配图像
	cv::Mat imageMatches;
	cv::drawMatches(
		image1, keypoints1,
		image2, keypoints2,
		matches, imageMatches, cv::Scalar(255, 255, 255));

	cv::namedWindow("imageMatches");
	cv::imshow("imageMatches", imageMatches);
	cv::waitKey(0);

	return 0;
}

 

 

 

Remark:

关注
打赏
1663399408
查看更多评论
立即登录/注册

微信扫码登录

0.0365s