码迷,mamicode.com
首页 > 编程语言 > 详细

OpenCV图像匹配算法之freak

时间:2015-01-09 10:45:22      阅读:949      评论:0      收藏:0      [点我收藏+]

标签:opencv图像匹配算法   opencv freak   

utils.cpp与utils.h

//freak.cpp
#include "stdafx.h"
#include <cv.hpp>
#include <highgui.h>
#include "utils.h"
#include <iostream>
using namespace std;

void freak(char* path1, char* path2, INFO& info, bool show)
{
	double t1,t2;
	t1=cvGetTickCount();

	initModule_nonfree();

	Mat img1, img2;
	img1=imread(path1,0);
	img2=imread(path2,0);
	if(img1.data==NULL)
	{
		cout<<"The image can not been loaded: "<<path1<<endl;
		system("pause");
		exit(-1);
	}
	if(img2.data==NULL)
	{
		cout<<"The image can not been loaded: "<<path2<<endl;
		system("pause");
		exit(-1);
	}

	vector<KeyPoint> kpts1_freak, kpts2_freak;
	Mat desc1_freak, desc2_freak;
	Ptr<cv::DescriptorMatcher> matcher_l1 = DescriptorMatcher::create("BruteForce-Hamming");		//二进制汉明距离匹配
	vector<vector<DMatch> > dmatches_freak;
	vector<Point2f> matches_freak, inliers_freak;
	
	
	SurfFeatureDetector dfreak(200,4);
	
	dfreak.detect(img1,kpts1_freak);
	dfreak.detect(img2,kpts2_freak);
	info.n1 = kpts1_freak.size();
	info.n2 = kpts2_freak.size();
	
	FREAK freak;
    freak.compute(img1,kpts1_freak,desc1_freak);
    freak.compute(img2,kpts2_freak,desc2_freak);
    matcher_l1->knnMatch(desc1_freak,desc2_freak,dmatches_freak,2);
    matches2points_nndr(kpts1_freak,kpts2_freak,dmatches_freak,matches_freak,DRATIO);
	info.m=matches_freak.size()/2;
    compute_inliers_ransac(matches_freak,inliers_freak,MIN_H_ERROR,false);
	info.rm=inliers_freak.size()/2;

	t2=cvGetTickCount();
	info.t=(t2-t1)/1000000.0/cvGetTickFrequency();

	Mat img1_rgb_freak = imread(path1,1);
	Mat img2_rgb_freak = imread(path2,1);
	Mat img_com_freak = Mat(Size(img1.cols*2,img1.rows),CV_8UC3);

	if(show == true)
	{
		draw_inliers(img1_rgb_freak,img2_rgb_freak,img_com_freak,inliers_freak,2);
		imshow("freak",img_com_freak);
		waitKey(0);
	}

	return;
}
使用

INFO freak_info;
freak(path1,path2,freak_info,true);
showInfo(freak_info);





OpenCV图像匹配算法之freak

标签:opencv图像匹配算法   opencv freak   

原文地址:http://blog.csdn.net/cjc211322/article/details/42551779

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!