Freak 和 brisk描述符与匹配

#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/legacy/legacy.hpp>
#include <iostream>
#include <vector>

using namespace cv;
using namespace std;

int main17070703(void)
{


	VideoCapture cap(0);
	Mat image;

	// Freak 
	//SurfFeatureDetector detector_Freak(2000);
	SurfFeatureDetector detector_Freak;
	vector<KeyPoint> keypoints_Freak;
	vector<DMatch> matches_Freak;
	vector<DMatch> matches1to2;
	Mat descriptors_Freak;
	Mat OutImage_Freak;
	FREAK freak;


	//ORB
	ORB orb;
	Mat OutImage_ORB;
	vector<KeyPoint> keypoints_ORB;

	//brisk
	BRISK brisk;
	Mat OutImage_BRISK;
	vector<KeyPoint> Keypoints_BRISK;


	if (!cap.isOpened())
	{
		cout << " cannot open the camera!\n";
		getchar();
	}
	else
	{
		while (waitKey(3) != 27)
		{
			cap >> image;

			// Freak  
			double t = (double)getTickCount();
			detector_Freak.detect(image, keypoints_Freak);
			//t = ((double)getTickCount() - t) / getTickFrequency();
			//cout << "FREAK detection time [s]: " << t / 1.0 << endl;

			// extract  
			t = (double)getTickCount();
			freak.compute(image, keypoints_Freak, descriptors_Freak);
			t = ((double)getTickCount() - t) / getTickFrequency();
			cout << "FREAK extraction time [s]: " << t << endl;

			// Draw keypoints.
			//CV_EXPORTS_W void drawKeypoints(const Mat& image, const vector<KeyPoint>& keypoints, CV_OUT Mat& outImage,
			//	const Scalar& color = Scalar::all(-1), int flags = DrawMatchesFlags::DEFAULT);
			drawKeypoints(image, keypoints_Freak, OutImage_Freak, Scalar::all(-1));
			imshow("OutImage_Freak", OutImage_Freak);

			//ORB
			orb.operator()(image, Mat(), keypoints_ORB);
			drawKeypoints(image, keypoints_ORB, OutImage_ORB, Scalar::all(-1));
			imshow("OutImage_ORB", OutImage_ORB);


			//BRISK
			brisk.operator()(image, Mat(), Keypoints_BRISK);
			drawKeypoints(image, Keypoints_BRISK, OutImage_BRISK, Scalar::all(-1));
			imshow("OutImage_BRISK", OutImage_BRISK);


			waitKey(1);
		}
	}







	return 0;
}

int main0(void)
{
	string filename1 = "hua.jpg";
	string filename2 = "hua.jpg";
	// FREAK  
	Mat imgA_Freak = imread(filename1);
	Mat imgB_Freak = imread(filename2);
	resize(imgA_Freak, imgA_Freak, Size(640, 480));
	resize(imgB_Freak, imgB_Freak, Size(640, 480));

	//VideoCapture cap(0);
	//if (!cap.isOpened())
	//{
	//	cout << " cannot open the camera!\n";
	//	getchar();
	//}
	//else
	//{
	//	while (waitKey(3) != 27)
	//	{
	//		cap >> imgB_Freak;

	//	

	//	}

	//}



	vector<KeyPoint> keypointsA_Freak, keypointsB_Freak;
	Mat descriptorsA_Freak, descriptorsB_Freak;
	vector<DMatch> matches_Freak;

	// DETECTION  
	// Any openCV detector such as  
	SurfFeatureDetector detector_Freak(200);

	// DESCRIPTOR  
	// Our proposed FREAK descriptor  
	// (roation invariance, scale invariance, pattern radius corresponding to SMALLEST_KP_SIZE,  
	// number of octaves, optional vector containing the selected pairs)  
	// FREAK extractor(true, true, 22, 4, std::vector<int>());  
	FREAK freak;
	FREAK freak1;

	// MATCHER  
	// The standard Hamming distance can be used such as  
	// BruteForceMatcher<Hamming> matcher;  
	// or the proposed cascade of hamming distance using SSSE3  
	BruteForceMatcher<HammingLUT> matcher_Freak;

	// detect  
	double t = (double)getTickCount();
	detector_Freak.detect(imgA_Freak, keypointsA_Freak);
	detector_Freak.detect(imgB_Freak, keypointsB_Freak);
	//t = ((double)getTickCount() - t) / getTickFrequency();
	//cout << "FREAK detection time [s]: " << t / 1.0 << endl;

	// extract  
	t = (double)getTickCount();
	freak.compute(imgA_Freak, keypointsA_Freak, descriptorsA_Freak);
	freak.compute(imgB_Freak, keypointsB_Freak, descriptorsB_Freak);
	t = ((double)getTickCount() - t) / getTickFrequency();
	cout << "FREAK extraction time [s]: " << t << endl;

	Mat image;
	vector<DMatch> matches1to2;
	drawMatches(imgA_Freak, keypointsA_Freak, imgB_Freak, keypointsB_Freak, matches1to2, image);

	imshow("image", image);


	waitKey(0);
	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值